Skip to content

Commit

Permalink
First Pass (#1442)
Browse files Browse the repository at this point in the history
  • Loading branch information
NorthernMan54 authored Feb 9, 2023
1 parent ec1731b commit efd2473
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions main/ZmqttDiscovery.ino
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ void createDiscovery(const char* sensor_type,
sensor["stat_t"] = state_topic;
}

if (availability_topic[0]) {
char avty_topic[mqtt_topic_max_size];
// If not an entity belonging to the gateway we put wild card for the location and gateway name
// allowing to have the entity detected by several gateways and a consistent discovery topic among the gateways
if (gateway_entity) {
strcpy(avty_topic, mqtt_topic);
strcat(avty_topic, gateway_name);
} else {
strcpy(avty_topic, "+/+");
}
strcat(avty_topic, availability_topic);
sensor["avty_t"] = avty_topic;
}

if (device_class[0]) {
// We check if the class belongs to HAAS classes list
int num_classes = sizeof(availableHASSClasses) / sizeof(availableHASSClasses[0]);
Expand Down Expand Up @@ -978,7 +992,7 @@ void pubMqttDiscovery() {
);
createDiscovery("switch", //set Type
subjectBTtoMQTT, "BT: Publish only sensors", (char*)getUniqueId("only_sensors", "").c_str(), //set state_topic,name,uniqueId
"", "", "{{ value_json.onlysensors }}", //set availability_topic,device_class,value_template,
will_Topic, "", "{{ value_json.onlysensors }}", //set availability_topic,device_class,value_template,
"{\"onlysensors\":true,\"save\":true}", "{\"onlysensors\":false,\"save\":true}", "", //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
Expand All @@ -988,7 +1002,7 @@ void pubMqttDiscovery() {
);
createDiscovery("switch", //set Type
subjectBTtoMQTT, "BT: Adaptive scan", (char*)getUniqueId("adaptive_scan", "").c_str(), //set state_topic,name,uniqueId
"", "", "{{ value_json.adaptivescan }}", //set availability_topic,device_class,value_template,
will_Topic, "", "{{ value_json.adaptivescan }}", //set availability_topic,device_class,value_template,
"{\"adaptivescan\":true,\"save\":true}", "{\"adaptivescan\":false,\"save\":true}", "", //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
Expand All @@ -998,7 +1012,7 @@ void pubMqttDiscovery() {
);
createDiscovery("switch", //set Type
subjectBTtoMQTT, "BT: Publish HASS presence", (char*)getUniqueId("hasspresence", "").c_str(), //set state_topic,name,uniqueId
"", "", "{{ value_json.hasspresence }}", //set availability_topic,device_class,value_template,
will_Topic, "", "{{ value_json.hasspresence }}", //set availability_topic,device_class,value_template,
"{\"hasspresence\":true,\"save\":true}", "{\"hasspresence\":false,\"save\":true}", "", //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
Expand All @@ -1008,7 +1022,7 @@ void pubMqttDiscovery() {
);
createDiscovery("switch", //set Type
subjectBTtoMQTT, "BT: Publish Advertisement data", (char*)getUniqueId("pubadvdata", "").c_str(), //set state_topic,name,uniqueId
"", "", "{{ value_json.pubadvdata }}", //set availability_topic,device_class,value_template,
will_Topic, "", "{{ value_json.pubadvdata }}", //set availability_topic,device_class,value_template,
"{\"pubadvdata\":true,\"save\":true}", "{\"pubadvdata\":false,\"save\":true}", "", //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
Expand All @@ -1018,7 +1032,7 @@ void pubMqttDiscovery() {
);
createDiscovery("switch", //set Type
subjectBTtoMQTT, "BT: Connect to devices", (char*)getUniqueId("bleconnect", "").c_str(), //set state_topic,name,uniqueId
"", "", "{{ value_json.bleconnect }}", //set availability_topic,device_class,value_template,
will_Topic, "", "{{ value_json.bleconnect }}", //set availability_topic,device_class,value_template,
"{\"bleconnect\":true,\"save\":true}", "{\"bleconnect\":false,\"save\":true}", "", //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
Expand Down

0 comments on commit efd2473

Please sign in to comment.