[DISC] Fix Mqtt Device Trigger announcement message (#2091)
This commit is contained in:
1 parent
f86d89db85
commit
f30960566c
2 files changed
+12
-2
No files matched your search
@@ -130,7 +130,7 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*
|
|||||||
strcat(state_topic, gateway_name);
|
strcat(state_topic, gateway_name);
|
||||||
|
|
||||||
strcat(state_topic, topic);
|
strcat(state_topic, topic);
|
||||||
sensor["topic"] = state_topic;
|
sensor["info_topic"] = state_topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set The Devices */
|
/* Set The Devices */
|
||||||
@@ -187,7 +187,7 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*
|
|||||||
sensor["device"] = device; //device representing the board
|
sensor["device"] = device; //device representing the board
|
||||||
|
|
||||||
/* Publish on the topic */
|
/* Publish on the topic */
|
||||||
String topic_to_publish = String(discovery_prefix) + "/device_automation/" + String(unique_id) + "/config";
|
String topic_to_publish = String(discovery_prefix) + "/device_automation/" + String(Gateway_Short_Name) + "/" + String(unique_id) + "/config";
|
||||||
Log.trace(F("Announce Device Trigger %s" CR), topic_to_publish.c_str());
|
Log.trace(F("Announce Device Trigger %s" CR), topic_to_publish.c_str());
|
||||||
sensor["topic"] = topic_to_publish;
|
sensor["topic"] = topic_to_publish;
|
||||||
sensor["retain"] = true;
|
sensor["retain"] = true;
|
||||||
|
|||||||
@@ -585,7 +585,17 @@ bool pub(JsonObject& data) {
|
|||||||
data.remove("origin");
|
data.remove("origin");
|
||||||
} else if (data.containsKey("topic") && data["topic"].is<const char*>()) {
|
} else if (data.containsKey("topic") && data["topic"].is<const char*>()) {
|
||||||
topic = data["topic"].as<const char*>();
|
topic = data["topic"].as<const char*>();
|
||||||
|
if (data.containsKey("info_topic") && data["info_topic"].is<const char*>()) {
|
||||||
|
// Sometimes it is necessary to provide information about the publishing topic, not just use it.
|
||||||
|
// This is the case, for example, for the RF2MQTT device trigger announcement message where the
|
||||||
|
// temporary variable info_topic provides information about the topic that will be used to publish the message,
|
||||||
|
// and it can be different of current message topic (This is a clever pun, I hope it's clear).
|
||||||
|
data["topic"].set(data["info_topic"]);
|
||||||
|
data.remove("info_topic");
|
||||||
|
} else {
|
||||||
data.remove("topic");
|
data.remove("topic");
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.error(F("No topic or origin in JSON, not published" CR));
|
Log.error(F("No topic or origin in JSON, not published" CR));
|
||||||
gatewayState = GatewayState::ERROR;
|
gatewayState = GatewayState::ERROR;
|
||||||
|
|||||||
Reference in new issue
Block a user