Initial HASS autodiscovery support

This commit is contained in:
rodriguezst
2022-06-19 09:51:07 +00:00
committed by GitHub
parent 6e3371df3d
commit 9f68e67ce8
8 changed files with 83 additions and 0 deletions

View File

@@ -343,6 +343,36 @@ void Network::publishPresenceDetection(char *csv)
_presenceCsv = csv;
}
void Network::publishHASSConfig(const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState)
{
String configJSON = "{\"~\": \"";
configJSON.concat(baseTopic);
configJSON.concat("\", \"name\": \"");
configJSON.concat(name);
configJSON.concat("\", \"unique_id\": \"");
configJSON.concat(uidString);
configJSON.concat("\", \"cmd_t\": \"~/lock/action\", \"pl_lock\": \"");
configJSON.concat(lockAction);
configJSON.concat("\", \"pl_unlk\": \"");
configJSON.concat(unlockAction);
configJSON.concat("\", \"pl_open\": \"");
configJSON.concat(openAction);
configJSON.concat("\", \"stat_t\": \"~/lock/state\", \"stat_locked\": \"");
configJSON.concat(lockedState);
configJSON.concat("\", \"stat_unlocked\": \"");
configJSON.concat(unlockedState);
configJSON.concat("\", \"opt\": \"false\"}");
String path = "homeassistant/lock/";
path.concat(uidString);
path.concat("/config");
Serial.println("HASS Config:");
Serial.println(configJSON);
_device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true);
}
void Network::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *))
{
_lockActionReceivedCallback = lockActionReceivedCallback;