Add Home Assistant configuration URL
This commit is contained in:
12
Network.cpp
12
Network.cpp
@@ -719,6 +719,18 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
|
||||
json["dev"]["mf"] = "Nuki";
|
||||
json["dev"]["mdl"] = deviceType;
|
||||
json["dev"]["name"] = name;
|
||||
|
||||
String cuUrl = _preferences->getString(preference_mqtt_hass_cu_url);
|
||||
|
||||
if (cuUrl != "")
|
||||
{
|
||||
json["dev"]["cu"] = cuUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
json["dev"]["cu"] = "http://" + _device->localIP();
|
||||
}
|
||||
|
||||
json["~"] = baseTopic;
|
||||
json["name"] = nullptr;
|
||||
json["unique_id"] = String(uidString) + "_lock";
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#define preference_mqtt_crt "mqttcrt"
|
||||
#define preference_mqtt_key "mqttkey"
|
||||
#define preference_mqtt_hass_discovery "hassdiscovery"
|
||||
#define preference_mqtt_hass_cu_url "hassConfigUrl"
|
||||
#define preference_ip_dhcp_enabled "dhcpena"
|
||||
#define preference_ip_address "ipaddr"
|
||||
#define preference_ip_subnet "ipsub"
|
||||
@@ -64,7 +65,7 @@ private:
|
||||
preference_mqtt_user, preference_mqtt_password, preference_mqtt_log_enabled, preference_lock_enabled,
|
||||
preference_mqtt_lock_path, preference_opener_enabled, preference_mqtt_opener_path,
|
||||
preference_lock_max_keypad_code_count, preference_opener_max_keypad_code_count, preference_mqtt_ca,
|
||||
preference_mqtt_crt, preference_mqtt_key, preference_mqtt_hass_discovery,
|
||||
preference_mqtt_crt, preference_mqtt_key, preference_mqtt_hass_discovery, preference_mqtt_hass_cu_url,
|
||||
preference_ip_dhcp_enabled, preference_ip_address, preference_ip_subnet, preference_ip_gateway, preference_ip_dns_server,
|
||||
preference_network_hardware, preference_network_wifi_fallback_disabled, preference_rssi_publish_interval,
|
||||
preference_hostname, preference_network_timeout, preference_restart_on_disconnect,
|
||||
|
||||
@@ -352,6 +352,11 @@ bool WebCfgServer::processArgs(String& message)
|
||||
configChanged = true;
|
||||
}
|
||||
}
|
||||
else if(key == "HASSCUURL")
|
||||
{
|
||||
_preferences->putString(preference_mqtt_hass_cu_url, value);
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "HOSTNAME")
|
||||
{
|
||||
_preferences->putString(preference_hostname, value);
|
||||
@@ -764,6 +769,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
|
||||
response.concat("<h3>Advanced MQTT and Network Configuration</h3>");
|
||||
response.concat("<table>");
|
||||
printInputField(response, "HASSDISCOVERY", "Home Assistant discovery topic (empty to disable; usually homeassistant)", _preferences->getString(preference_mqtt_hass_discovery).c_str(), 30);
|
||||
printInputField(response, "HASSCUURL", "Home Assistant device configuration URL (empty to use http://LOCALIP; fill when using a reverse proxy for example)", _preferences->getString(preference_mqtt_hass_cu_url).c_str(), 261);
|
||||
printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE, _network->encryptionSupported(), true);
|
||||
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE, _network->encryptionSupported(), true);
|
||||
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE, _network->encryptionSupported(), true);
|
||||
|
||||
@@ -159,6 +159,11 @@ int8_t EthLan8720Device::signalStrength()
|
||||
return -1;
|
||||
}
|
||||
|
||||
String EthLan8720Device::localIP()
|
||||
{
|
||||
return Ethernet.localIP().toString();
|
||||
}
|
||||
|
||||
void EthLan8720Device::mqttSetClientId(const char *clientId)
|
||||
{
|
||||
if(_useEncryption)
|
||||
|
||||
@@ -229,6 +229,11 @@ int8_t W5500Device::signalStrength()
|
||||
return 127;
|
||||
}
|
||||
|
||||
String W5500Device::localIP()
|
||||
{
|
||||
return Ethernet.localIP().toString();
|
||||
}
|
||||
|
||||
void W5500Device::mqttSetClientId(const char *clientId)
|
||||
{
|
||||
_mqttClient.setClientId(clientId);
|
||||
|
||||
@@ -180,6 +180,11 @@ int8_t WifiDevice::signalStrength()
|
||||
return WiFi.RSSI();
|
||||
}
|
||||
|
||||
String WifiDevice::localIP()
|
||||
{
|
||||
return WiFi.localIP().toString();
|
||||
}
|
||||
|
||||
void WifiDevice::clearRtcInitVar(WiFiManager *)
|
||||
{
|
||||
memset(WiFiDevice_reconfdetect, 0, sizeof WiFiDevice_reconfdetect);
|
||||
|
||||
Reference in New Issue
Block a user