Add input form for HASS discovery topic
This commit is contained in:
11
Network.cpp
11
Network.cpp
@@ -345,6 +345,10 @@ void Network::publishPresenceDetection(char *csv)
|
||||
|
||||
void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState)
|
||||
{
|
||||
String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery);
|
||||
|
||||
if(discoveryTopic != "")
|
||||
{
|
||||
String configJSON = "{\"dev\":{\"ids\":[\"nuki_";
|
||||
configJSON.concat(uidString);
|
||||
configJSON.concat("\"],\"mf\":\"Nuki\",\"mdl\":\"");
|
||||
@@ -373,7 +377,8 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
|
||||
configJSON.concat(unlockedState);
|
||||
configJSON.concat("\",\"opt\":\"false\"}");
|
||||
|
||||
String path = "homeassistant/lock/";
|
||||
String path = discoveryTopic;
|
||||
path.concat("/lock/");
|
||||
path.concat(uidString);
|
||||
path.concat("/smartlock/config");
|
||||
|
||||
@@ -398,11 +403,13 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
|
||||
configJSON.concat(mqtt_topic_battery_critical);
|
||||
configJSON.concat("\"}");
|
||||
|
||||
path = "homeassistant/binary_sensor/";
|
||||
path = discoveryTopic;
|
||||
path.concat("/binary_sensor/");
|
||||
path.concat(uidString);
|
||||
path.concat("/battery_low/config");
|
||||
|
||||
_device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void Network::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *))
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define preference_mqtt_ca "mqttca"
|
||||
#define preference_mqtt_crt "mqttcrt"
|
||||
#define preference_mqtt_key "mqttkey"
|
||||
#define preference_mqtt_hass_discovery "hassdiscovery"
|
||||
#define preference_hostname "hostname"
|
||||
#define preference_network_timeout "nettmout"
|
||||
#define preference_query_interval_lockstate "lockStInterval"
|
||||
|
||||
@@ -225,6 +225,11 @@ bool WebCfgServer::processArgs(String& message)
|
||||
_preferences->putString(preference_mqtt_key, value);
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "HASSDISCOVERY")
|
||||
{
|
||||
_preferences->putString(preference_mqtt_hass_discovery, value);
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "HOSTNAME")
|
||||
{
|
||||
_preferences->putString(preference_hostname, value);
|
||||
@@ -493,6 +498,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
|
||||
printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE);
|
||||
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE);
|
||||
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE);
|
||||
printInputField(response, "HASSDISCOVERY", "Home Assistant discovery topic (empty to disable)", _preferences->getString(preference_mqtt_hass_discovery).c_str(), 30);
|
||||
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
|
||||
response.concat("</table>");
|
||||
response.concat("* If no encryption is configured for the MQTT broker, leave empty.<br>");
|
||||
|
||||
Reference in New Issue
Block a user