[BT Discovery] Deactivate/Activate sliders dynamicaly depending on auto adaptive state (#1502)
To avoid having unnecessaries commands in the interface
This commit is contained in:
1 parent
df228a4aa4
commit
9c73896999
2 files changed
+38
-19
No files matched your search
+10
-1
@@ -137,7 +137,7 @@ void stateBTMeasures(bool start) {
|
|||||||
void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) {
|
void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) {
|
||||||
// Attempts to connect to eligible devices or not
|
// Attempts to connect to eligible devices or not
|
||||||
Config_update(BTdata, "bleconnect", BTConfig.bleConnect);
|
Config_update(BTdata, "bleconnect", BTConfig.bleConnect);
|
||||||
// Identify AdaptiveScan deactivation to pass to continuous mode
|
// Identify AdaptiveScan deactivation to pass to continuous mode or activation to come back to default settings
|
||||||
if (startup == false) {
|
if (startup == false) {
|
||||||
if (BTdata.containsKey("adaptivescan") && BTdata["adaptivescan"] == false && BTConfig.adaptiveScan == true) {
|
if (BTdata.containsKey("adaptivescan") && BTdata["adaptivescan"] == false && BTConfig.adaptiveScan == true) {
|
||||||
BTdata["interval"] = MinTimeBtwScan;
|
BTdata["interval"] = MinTimeBtwScan;
|
||||||
@@ -145,9 +145,18 @@ void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) {
|
|||||||
} else if (BTdata.containsKey("adaptivescan") && BTdata["adaptivescan"] == true && BTConfig.adaptiveScan == false) {
|
} else if (BTdata.containsKey("adaptivescan") && BTdata["adaptivescan"] == true && BTConfig.adaptiveScan == false) {
|
||||||
BTdata["interval"] = TimeBtwRead;
|
BTdata["interval"] = TimeBtwRead;
|
||||||
BTdata["intervalacts"] = TimeBtwActive;
|
BTdata["intervalacts"] = TimeBtwActive;
|
||||||
|
# ifdef ZmqttDiscovery
|
||||||
|
// Remove discovered entities
|
||||||
|
eraseTopic("number", (char*)getUniqueId("interval", "").c_str());
|
||||||
|
eraseTopic("number", (char*)getUniqueId("intervalacts", "").c_str());
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Config_update(BTdata, "adaptivescan", BTConfig.adaptiveScan);
|
Config_update(BTdata, "adaptivescan", BTConfig.adaptiveScan);
|
||||||
|
# ifdef ZmqttDiscovery
|
||||||
|
// Create discovery entities
|
||||||
|
btScanParametersDiscovery();
|
||||||
|
# endif
|
||||||
// Time before before active scan
|
// Time before before active scan
|
||||||
// Scan interval set
|
// Scan interval set
|
||||||
if (BTdata.containsKey("interval") && BTdata["interval"] != 0)
|
if (BTdata.containsKey("interval") && BTdata["interval"] != 0)
|
||||||
|
|||||||
+28
-18
@@ -385,6 +385,31 @@ void eraseTopic(const char* sensor_type, const char* unique_id) {
|
|||||||
pubMQTT((char*)topic.c_str(), "", true);
|
pubMQTT((char*)topic.c_str(), "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ifdef ZgatewayBT
|
||||||
|
void btScanParametersDiscovery() {
|
||||||
|
if (BTConfig.adaptiveScan == false) {
|
||||||
|
createDiscovery("number", //set Type
|
||||||
|
subjectBTtoMQTT, "BT: Interval between scans", (char*)getUniqueId("interval", "").c_str(), //set state_topic,name,uniqueId
|
||||||
|
will_Topic, "", "{{ value_json.interval/1000 }}", //set availability_topic,device_class,value_template,
|
||||||
|
"{\"interval\":{{value*1000}},\"save\":true}", "", "s", //set,payload_on,payload_off,unit_of_meas,
|
||||||
|
0, //set off_delay
|
||||||
|
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic
|
||||||
|
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain,
|
||||||
|
stateClassNone //State Class
|
||||||
|
);
|
||||||
|
createDiscovery("number", //set Type
|
||||||
|
subjectBTtoMQTT, "BT: Interval between active scans", (char*)getUniqueId("intervalacts", "").c_str(), //set state_topic,name,uniqueId
|
||||||
|
will_Topic, "", "{{ value_json.intervalacts/1000 }}", //set availability_topic,device_class,value_template,
|
||||||
|
"{\"intervalacts\":{{value*1000}},\"save\":true}", "", "s", //set,payload_on,payload_off,unit_of_meas,
|
||||||
|
0, //set off_delay
|
||||||
|
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic
|
||||||
|
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain,
|
||||||
|
stateClassNone //State Class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
void pubMqttDiscovery() {
|
void pubMqttDiscovery() {
|
||||||
Log.trace(F("omgStatusDiscovery" CR));
|
Log.trace(F("omgStatusDiscovery" CR));
|
||||||
createDiscovery("binary_sensor", //set Type
|
createDiscovery("binary_sensor", //set Type
|
||||||
@@ -988,24 +1013,7 @@ void pubMqttDiscovery() {
|
|||||||
|
|
||||||
# ifdef ZgatewayBT
|
# ifdef ZgatewayBT
|
||||||
# ifdef ESP32
|
# ifdef ESP32
|
||||||
createDiscovery("number", //set Type
|
|
||||||
subjectBTtoMQTT, "BT: Interval between scans", (char*)getUniqueId("interval", "").c_str(), //set state_topic,name,uniqueId
|
|
||||||
will_Topic, "", "{{ value_json.interval/1000 }}", //set availability_topic,device_class,value_template,
|
|
||||||
"{\"interval\":{{value*1000}},\"save\":true}", "", "s", //set,payload_on,payload_off,unit_of_meas,
|
|
||||||
0, //set off_delay
|
|
||||||
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic
|
|
||||||
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain,
|
|
||||||
stateClassNone //State Class
|
|
||||||
);
|
|
||||||
createDiscovery("number", //set Type
|
|
||||||
subjectBTtoMQTT, "BT: Interval between active scans", (char*)getUniqueId("intervalacts", "").c_str(), //set state_topic,name,uniqueId
|
|
||||||
will_Topic, "", "{{ value_json.intervalacts/1000 }}", //set availability_topic,device_class,value_template,
|
|
||||||
"{\"intervalacts\":{{value*1000}},\"save\":true}", "", "s", //set,payload_on,payload_off,unit_of_meas,
|
|
||||||
0, //set off_delay
|
|
||||||
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic
|
|
||||||
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain,
|
|
||||||
stateClassNone //State Class
|
|
||||||
);
|
|
||||||
createDiscovery("number", //set Type
|
createDiscovery("number", //set Type
|
||||||
subjectBTtoMQTT, "BT: Connnect interval", (char*)getUniqueId("intervalcnct", "").c_str(), //set state_topic,name,uniqueId
|
subjectBTtoMQTT, "BT: Connnect interval", (char*)getUniqueId("intervalcnct", "").c_str(), //set state_topic,name,uniqueId
|
||||||
will_Topic, "", "{{ value_json.intervalcnct/60000 }}", //set availability_topic,device_class,value_template,
|
will_Topic, "", "{{ value_json.intervalcnct/60000 }}", //set availability_topic,device_class,value_template,
|
||||||
@@ -1072,6 +1080,8 @@ void pubMqttDiscovery() {
|
|||||||
eraseTopic(obsoleteEntities[i][0], (char*)getUniqueId(obsoleteEntities[i][1], "").c_str());
|
eraseTopic(obsoleteEntities[i][0], (char*)getUniqueId(obsoleteEntities[i][1], "").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btScanParametersDiscovery();
|
||||||
|
|
||||||
createDiscovery("switch", //set Type
|
createDiscovery("switch", //set Type
|
||||||
subjectBTtoMQTT, "BT: Publish HASS presence", (char*)getUniqueId("hasspresence", "").c_str(), //set state_topic,name,uniqueId
|
subjectBTtoMQTT, "BT: Publish HASS presence", (char*)getUniqueId("hasspresence", "").c_str(), //set state_topic,name,uniqueId
|
||||||
will_Topic, "", "{{ value_json.hasspresence }}", //set availability_topic,device_class,value_template,
|
will_Topic, "", "{{ value_json.hasspresence }}", //set availability_topic,device_class,value_template,
|
||||||
|
|||||||
Reference in new issue
Block a user