mirror of
https://github.com/1technophile/OpenMQTTGateway.git
synced 2026-02-20 00:32:04 +01:00
[DISC] Fix Mqtt Device Trigger announcement message (#2091)
This commit is contained in:
committed by
GitHub
parent
f86d89db85
commit
f30960566c
@@ -130,7 +130,7 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*
|
||||
strcat(state_topic, gateway_name);
|
||||
|
||||
strcat(state_topic, topic);
|
||||
sensor["topic"] = state_topic;
|
||||
sensor["info_topic"] = state_topic;
|
||||
}
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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());
|
||||
sensor["topic"] = topic_to_publish;
|
||||
sensor["retain"] = true;
|
||||
|
||||
@@ -585,7 +585,17 @@ bool pub(JsonObject& data) {
|
||||
data.remove("origin");
|
||||
} else if (data.containsKey("topic") && data["topic"].is<const char*>()) {
|
||||
topic = data["topic"].as<const char*>();
|
||||
data.remove("topic");
|
||||
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");
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.error(F("No topic or origin in JSON, not published" CR));
|
||||
gatewayState = GatewayState::ERROR;
|
||||
|
||||
Reference in New Issue
Block a user