Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always suffix with device number in discovery topic #1962

Conversation

emontnemery
Copy link
Contributor

@emontnemery emontnemery commented Feb 18, 2018

Prevent duplicate devices discovered if device is reconfigured.

Another option would be to do something like this to clear the retained topic:

// Clear "other" topics first in case the device has been reconfigured
    if (1 == i)
    {
      snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "switch" : "light", mqtt_topic, (1 == devices_present) ? sidx : "");
      MqttPublish(stopic, true);
      snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "light" : "switch", mqtt_topic, (1 == devices_present) ? sidx : "");
      MqttPublish(stopic, true);
    }
    snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "switch" : "light", mqtt_topic, (1 == devices_present) ? "" : sidx);
    MqttPublish(stopic, true);
    snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "light" : "switch", mqtt_topic, (1 == devices_present) ? "" : sidx);

@emontnemery
Copy link
Contributor Author

@arendst is the patch OK, or does it need to be improved in some way?

@arendst arendst added the enhancement Type - Enhancement that will be worked on label Mar 8, 2018
arendst added a commit that referenced this pull request Mar 8, 2018
5.12.0d
* Add always suffix with device number in Mqtt discovery topic (#1962)

* Add single decimal precision to Nova Fitness SDS0x1 sensor values
(#2093)
@arendst arendst closed this Mar 8, 2018
curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 6, 2018
5.12.0d
* Add always suffix with device number in Mqtt discovery topic (arendst#1962)

* Add single decimal precision to Nova Fitness SDS0x1 sensor values
(arendst#2093)
@emontnemery emontnemery deleted the duplicate_discovery_topic2 branch December 2, 2018 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type - Enhancement that will be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants