Fixes/Enhancements for pio/preferences, new info page, add reboot button, remove old files (#451)
* Preferences * Info page * Info page * Remove old files + Info page
This commit is contained in:
@@ -215,7 +215,7 @@ NetworkDevice *NukiNetwork::device()
|
||||
#ifdef NUKI_HUB_UPDATER
|
||||
void NukiNetwork::initialize()
|
||||
{
|
||||
_hostname = _preferences->getString(preference_hostname);
|
||||
_hostname = _preferences->getString(preference_hostname, "");
|
||||
|
||||
if(_hostname == "")
|
||||
{
|
||||
@@ -240,9 +240,9 @@ void NukiNetwork::initialize()
|
||||
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect, false);
|
||||
_checkUpdates = _preferences->getBool(preference_check_updates, false);
|
||||
_reconnectNetworkOnMqttDisconnect = _preferences->getBool(preference_recon_netw_on_mqtt_discon, false);
|
||||
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000;
|
||||
|
||||
_hostname = _preferences->getString(preference_hostname);
|
||||
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval, 0) * 1000;
|
||||
_hostname = _preferences->getString(preference_hostname, "");
|
||||
_discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery, "");
|
||||
|
||||
if(_hostname == "")
|
||||
{
|
||||
@@ -251,8 +251,8 @@ void NukiNetwork::initialize()
|
||||
}
|
||||
if(_rssiPublishInterval == 0)
|
||||
{
|
||||
_rssiPublishInterval = 60;
|
||||
_preferences->putInt(preference_rssi_publish_interval, _rssiPublishInterval);
|
||||
_rssiPublishInterval = 60000;
|
||||
_preferences->putInt(preference_rssi_publish_interval, 60);
|
||||
}
|
||||
strcpy(_hostnameArr, _hostname.c_str());
|
||||
_device->initialize();
|
||||
@@ -263,7 +263,7 @@ void NukiNetwork::initialize()
|
||||
String brokerAddr = _preferences->getString(preference_mqtt_broker);
|
||||
strcpy(_mqttBrokerAddr, brokerAddr.c_str());
|
||||
|
||||
int port = _preferences->getInt(preference_mqtt_broker_port);
|
||||
int port = _preferences->getInt(preference_mqtt_broker_port, 0);
|
||||
if(port == 0)
|
||||
{
|
||||
port = 1883;
|
||||
@@ -299,14 +299,14 @@ void NukiNetwork::initialize()
|
||||
_device->mqttSetCleanSession(MQTT_CLEAN_SESSIONS);
|
||||
_device->mqttSetKeepAlive(MQTT_KEEP_ALIVE);
|
||||
|
||||
_networkTimeout = _preferences->getInt(preference_network_timeout);
|
||||
_networkTimeout = _preferences->getInt(preference_network_timeout, 0);
|
||||
if(_networkTimeout == 0)
|
||||
{
|
||||
_networkTimeout = -1;
|
||||
_preferences->putInt(preference_network_timeout, _networkTimeout);
|
||||
}
|
||||
|
||||
_publishDebugInfo = _preferences->getBool(preference_publish_debug_info);
|
||||
_publishDebugInfo = _preferences->getBool(preference_publish_debug_info, false);
|
||||
|
||||
char gpioPath[250];
|
||||
bool rebGpio = rebuildGpio();
|
||||
@@ -433,7 +433,7 @@ bool NukiNetwork::update()
|
||||
|
||||
_lastConnectedTs = ts;
|
||||
|
||||
#if PRESENCE_DETECTION_ENABLED
|
||||
#if PRESENCE_DETECTION_ENABLED
|
||||
if(_presenceDetection != nullptr && (_lastPresenceTs == 0 || (ts - _lastPresenceTs) > 3000))
|
||||
{
|
||||
char* presenceCsv = _presenceDetection->generateCsv();
|
||||
@@ -446,7 +446,7 @@ bool NukiNetwork::update()
|
||||
|
||||
_lastPresenceTs = ts;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(_device->signalStrength() != 127 && _rssiPublishInterval > 0 && ts - _lastRssiTs > _rssiPublishInterval)
|
||||
{
|
||||
@@ -515,7 +515,7 @@ bool NukiNetwork::update()
|
||||
if(strcmp(_latestVersion, _preferences->getString(preference_latest_version).c_str()) != 0) _preferences->putString(preference_latest_version, _latestVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
https.end();
|
||||
}
|
||||
delete client;
|
||||
@@ -592,7 +592,7 @@ void NukiNetwork::onMqttDisconnect(const espMqttClientTypes::DisconnectReason &r
|
||||
bool NukiNetwork::reconnect()
|
||||
{
|
||||
_mqttConnectionState = 0;
|
||||
int port = _preferences->getInt(preference_mqtt_broker_port);
|
||||
int port = _preferences->getInt(preference_mqtt_broker_port, 1883);
|
||||
|
||||
while (!_device->mqttConnected() && (esp_timer_get_time() / 1000) > _nextReconnect)
|
||||
{
|
||||
@@ -907,7 +907,7 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
json["dev"]["sw"] = softwareVersion;
|
||||
json["dev"]["hw"] = hardwareVersion;
|
||||
|
||||
String cuUrl = _preferences->getString(preference_mqtt_hass_cu_url);
|
||||
String cuUrl = _preferences->getString(preference_mqtt_hass_cu_url, "");
|
||||
|
||||
if (cuUrl != "")
|
||||
{
|
||||
@@ -942,7 +942,7 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
|
||||
serializeJson(json, _buffer, _bufferSize);
|
||||
|
||||
String path = _preferences->getString(preference_mqtt_hass_discovery);
|
||||
String path = _preferences->getString(preference_mqtt_hass_discovery, "homeassistant");
|
||||
path.concat("/lock/");
|
||||
path.concat(uidString);
|
||||
path.concat("/smartlock/config");
|
||||
@@ -3453,9 +3453,7 @@ void NukiNetwork::publishHassTopic(const String& mqttDeviceType,
|
||||
std::vector<std::pair<char*, char*>> additionalEntries
|
||||
)
|
||||
{
|
||||
String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery);
|
||||
|
||||
if (discoveryTopic != "")
|
||||
if (_discoveryTopic != "")
|
||||
{
|
||||
JsonDocument json;
|
||||
json = createHassJson(uidString, uidStringPostfix, displayName, name, baseTopic, stateTopic, deviceType, deviceClass, stateClass, entityCat, commandTopic, additionalEntries);
|
||||
@@ -3467,8 +3465,7 @@ void NukiNetwork::publishHassTopic(const String& mqttDeviceType,
|
||||
|
||||
String NukiNetwork::createHassTopicPath(const String& mqttDeviceType, const String& mqttDeviceName, const String& uidString)
|
||||
{
|
||||
String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery);
|
||||
String path = discoveryTopic;
|
||||
String path = _discoveryTopic;
|
||||
path.concat("/");
|
||||
path.concat(mqttDeviceType);
|
||||
path.concat("/");
|
||||
@@ -3482,9 +3479,7 @@ String NukiNetwork::createHassTopicPath(const String& mqttDeviceType, const Stri
|
||||
|
||||
void NukiNetwork::removeHassTopic(const String& mqttDeviceType, const String& mqttDeviceName, const String& uidString)
|
||||
{
|
||||
String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery);
|
||||
|
||||
if (discoveryTopic != "")
|
||||
if (_discoveryTopic != "")
|
||||
{
|
||||
String path = createHassTopicPath(mqttDeviceType, mqttDeviceName, uidString);
|
||||
_device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, "");
|
||||
@@ -3883,4 +3878,9 @@ String NukiNetwork::localIP()
|
||||
{
|
||||
return _device->localIP();
|
||||
}
|
||||
|
||||
bool NukiNetwork::isConnected()
|
||||
{
|
||||
return _device->isConnected();
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user