Skip to content

Commit

Permalink
[HA Discovery] Filter on type rather than model_id (#1535)
Browse files Browse the repository at this point in the history
For maintainability
Add Ibeacon in the filtering as they are not identified with RMAC type
  • Loading branch information
1technophile authored Mar 15, 2023
1 parent dbba1bd commit 390302a
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,7 @@ void launchBTDiscovery(bool overrideDiscovery) {
BLEdevice* p = *it;
Log.trace(F("Device mac %s" CR), p->macAdr);
// Do not launch discovery for the devices already discovered (unless we have overrideDiscovery) or that are not unique by their MAC Address (iBeacon, GAEN and Microsoft CDP)
if ((overrideDiscovery || !isDiscovered(p)) &&
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::IBEACON &&
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::MS_CDP &&
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::APPLE_CONT &&
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::GAEN) {
if (overrideDiscovery || !isDiscovered(p)) {
String macWOdots = String(p->macAdr);
macWOdots.replace(":", "");
if (!BTConfig.extDecoderEnable && // Do not decode if an external decoder is configured
Expand Down Expand Up @@ -1047,10 +1043,7 @@ void process_bledata(JsonObject& BLEdata) {
const char* mac = BLEdata["id"].as<const char*>();
int model_id = BTConfig.extDecoderEnable ? -1 : decoder.decodeBLEJson(BLEdata);
int mac_type = BLEdata["mac_type"].as<int>();
if (model_id >= 0 && model_id != TheengsDecoder::BLE_ID_NUM::IBEACON &&
model_id != TheengsDecoder::BLE_ID_NUM::MS_CDP &&
model_id != TheengsDecoder::BLE_ID_NUM::APPLE_CONT &&
model_id != TheengsDecoder::BLE_ID_NUM::GAEN) { // Broadcaster devices
if (model_id >= 0 && model_id != TheengsDecoder::BLE_ID_NUM::IBEACON && (BLEdata["type"].as<string>()).compare("RMAC") != 0) { // Broadcaster devices, excluding random macs
Log.trace(F("Decoder found device: %s" CR), BLEdata["model_id"].as<const char*>());
if (model_id == TheengsDecoder::BLE_ID_NUM::HHCCJCY01HHCC || model_id == TheengsDecoder::BLE_ID_NUM::BM2) {
createOrUpdateDevice(mac, device_flags_connect, model_id, mac_type); // Device that broadcast and can be connected
Expand Down Expand Up @@ -1105,7 +1098,7 @@ void process_bledata(JsonObject& BLEdata) {
}
}
if (!BTConfig.extDecoderEnable && model_id < 0) {
Log.trace(F("No device found " CR));
Log.trace(F("No eligible device found " CR));
}
}

Expand Down

0 comments on commit 390302a

Please sign in to comment.