Skip to content

Commit

Permalink
Merge branch 'master' into update-check
Browse files Browse the repository at this point in the history
  • Loading branch information
iranl authored Feb 8, 2024
2 parents 2c71fed + a9d80b3 commit d0d34ae
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions MqttTopics.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define mqtt_topic_info_firmware_version "/info/firmwareVersion"
#define mqtt_topic_info_nuki_hub_version "/info/nukiHubVersion"
#define mqtt_topic_info_nuki_hub_latest "/info/nukiHubLatest"
#define mqtt_topic_info_nuki_hub_ip "/info/nukiHubIp"

#define mqtt_topic_keypad "/keypad"
#define mqtt_topic_keypad_command_action "/keypad/command/action"
Expand Down
36 changes: 36 additions & 0 deletions Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ bool Network::reconnect()
}

publishString(_maintenancePathPrefix, mqtt_topic_mqtt_connection_state, "online");
publishString(_maintenancePathPrefix, mqtt_topic_info_nuki_hub_ip, _device->localIP().c_str());

_mqttConnectionState = 2;
for(const auto& callback : _reconnectedCallbacks)
Expand Down Expand Up @@ -752,6 +753,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";
Expand Down Expand Up @@ -953,6 +966,23 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
{ { "enabled_by_default", "true" },
{"ic", "mdi:counter"}});

// NUKI Hub IP Address
publishHassTopic("sensor",
"nuki_hub_ip",
uidString,
"_nuki_hub_ip",
"NUKI Hub IP",
name,
baseTopic,
_lockPath + mqtt_topic_info_nuki_hub_ip,
deviceType,
"",
"",
"diagnostic",
"",
{ { "enabled_by_default", "true" },
{"ic", "mdi:ip"}});

// LED enabled
publishHassTopic("switch",
"led_enabled",
Expand Down Expand Up @@ -1427,6 +1457,12 @@ void Network::removeHASSConfig(char* uidString)
path.concat(uidString);
path.concat("/sound_level/config");
_device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, "");

path = discoveryTopic;
path.concat("/sensor/");
path.concat(uidString);
path.concat("/nuki_hub_ip/config");
_device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, "");

path = discoveryTopic;
path.concat("/number/");
Expand Down
3 changes: 2 additions & 1 deletion PreferencesKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -64,7 +65,7 @@ class DebugPreferences
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,
Expand Down
6 changes: 6 additions & 0 deletions WebCfgServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -771,6 +776,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);
Expand Down
5 changes: 5 additions & 0 deletions networkDevices/EthLan8720Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ int8_t EthLan8720Device::signalStrength()
return -1;
}

String EthLan8720Device::localIP()
{
return ETH.localIP().toString();
}

void EthLan8720Device::mqttSetClientId(const char *clientId)
{
if(_useEncryption)
Expand Down
2 changes: 2 additions & 0 deletions networkDevices/EthLan8720Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class EthLan8720Device : public NetworkDevice
virtual bool isConnected();

int8_t signalStrength() override;

String localIP() override;

void mqttSetClientId(const char *clientId) override;

Expand Down
2 changes: 2 additions & 0 deletions networkDevices/NetworkDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class NetworkDevice

virtual bool isConnected() = 0;
virtual int8_t signalStrength() = 0;

virtual String localIP() = 0;

virtual void mqttSetClientId(const char* clientId) = 0;
virtual void mqttSetCleanSession(bool cleanSession) = 0;
Expand Down
5 changes: 5 additions & 0 deletions networkDevices/W5500Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions networkDevices/W5500Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class W5500Device : public NetworkDevice
virtual bool isConnected();

int8_t signalStrength() override;

String localIP() override;

void mqttSetClientId(const char *clientId) override;

Expand Down
5 changes: 5 additions & 0 deletions networkDevices/WifiDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions networkDevices/WifiDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class WifiDevice : public NetworkDevice
virtual bool isConnected();

int8_t signalStrength() override;

String localIP() override;

void mqttSetClientId(const char *clientId) override;

Expand Down

0 comments on commit d0d34ae

Please sign in to comment.