remove duplicate code in main\ZgatewayBT.ino (#557)
* merge duplicate code into function setWorBMac * rename setWorBMac to updateWorB * add helper getDeviceByMac * change updateWorB to use helper getDeviceByMac * change isWhite to use helper getDeviceByMac * change isBlack to use helper getDeviceByMac * change isDiscovered to use helper getDeviceByMac * eliminate duplicate devices walk for isWhite, isBlack and isDiscovered check * fix a data corruption race between MQTTtoBT and discovery-functions the ***Discovery functions every time create a new device unless this device is set to white-list before. as a result of this, the devices list contains the same mac multiple times with different flags * eliminate duplicate devices walk for oneWhite check because now we have a utility function 'createOrUpdateDevice' we can globally cache this as a single flag * secure createOrUpdateDevice agains data races on multicore esp32 * fix the concept of the createOrUpdateDevice c / c++ does not allow NULL as function parameter like modern languages * use nkolban Semaphore helper class (already included and used from eos1d3/ESP32_BLE librarie) this makes the semaphore handling more cleaner and readable * merge duplicate code during createDiscovery into new helper createDiscoveryFromList * replace excessive use of ZmqttDiscovery precompiler directive in ble advertised callbacks with dummy functions for a better readability we can remove this because isDiscovered does not do a devices walk anymore * fix build errors found by travis-ci
This commit is contained in:
1 parent
0681d09b41
commit
033a583f0a
4 files changed
+190
-301
No files matched your search
@@ -49,6 +49,23 @@ String getUniqueId(String name, String sufix)
|
||||
return String(uniqueId);
|
||||
}
|
||||
|
||||
#ifdef ZgatewayBT
|
||||
void createDiscoveryFromList(char *mac, char *sensorList[][8], int sensorCount)
|
||||
{
|
||||
for (int i = 0; i < sensorCount; i++)
|
||||
{
|
||||
Log.trace(F("CreateDiscoverySensor %s" CR),sensorList[i][1]);
|
||||
String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac);
|
||||
String unique_id = String(mac) + "-" + sensorList[i][1];
|
||||
createDiscovery(sensorList[i][0],
|
||||
(char *)discovery_topic.c_str(), sensorList[i][1], (char *)unique_id.c_str(),
|
||||
will_Topic, sensorList[i][3], sensorList[i][4],
|
||||
sensorList[i][5], sensorList[i][6], sensorList[i][7],
|
||||
0, "", "", false, "");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void createDiscovery(char *sensor_type,
|
||||
char *st_topic, char *s_name, char *unique_id,
|
||||
char *availability_topic, char *device_class, char *value_template,
|
||||
|
||||
Reference in new issue
Block a user