Remove retained MQTT messages when changing HASS config

This commit is contained in:
rodriguezst
2022-06-21 22:19:19 +00:00
committed by GitHub
parent 5d254d463b
commit 1b0402cfe7
9 changed files with 82 additions and 0 deletions

View File

@@ -412,6 +412,28 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
}
}
void Network::removeHASSConfig(char* uidString)
{
String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery);
if(discoveryTopic != "")
{
String path = discoveryTopic;
path.concat("/lock/");
path.concat(uidString);
path.concat("/smartlock/config");
_device->mqttClient()->publish(path.c_str(), NULL, 0U, true);
path = discoveryTopic;
path.concat("/binary_sensor/");
path.concat(uidString);
path.concat("/battery_low/config");
_device->mqttClient()->publish(path.c_str(), NULL, 0U, true);
}
}
void Network::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *))
{
_lockActionReceivedCallback = lockActionReceivedCallback;