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:
iranl
2024-08-12 17:53:00 +02:00
committed by GitHub
parent 21adca01e7
commit 346c5c65d1
59 changed files with 1459 additions and 1403 deletions

View File

@@ -40,7 +40,7 @@ NukiNetworkLock::~NukiNetworkLock()
void NukiNetworkLock::initialize()
{
String mqttPath = _preferences->getString(preference_mqtt_lock_path);
String mqttPath = _preferences->getString(preference_mqtt_lock_path, "");
if(mqttPath.length() > 0)
{
size_t len = mqttPath.length();
@@ -55,11 +55,13 @@ void NukiNetworkLock::initialize()
_preferences->putString(preference_mqtt_lock_path, _mqttPath);
}
#if PRESENCE_DETECTION_ENABLED
#if PRESENCE_DETECTION_ENABLED
_network->setMqttPresencePath(_mqttPath);
#endif
#endif
_haEnabled = _preferences->getString(preference_mqtt_hass_discovery) != "";
_haEnabled = _preferences->getString(preference_mqtt_hass_discovery, "") != "";
_disableNonJSON = _preferences->getBool(preference_disable_non_json, false);
_offEnabled = _preferences->getBool(preference_official_hybrid, false);
_network->initTopic(_mqttPath, mqtt_topic_lock_action, "--");
_network->subscribe(_mqttPath, mqtt_topic_lock_action);
@@ -86,7 +88,7 @@ void NukiNetworkLock::initialize()
_network->subscribe(_mqttPath, mqtt_topic_query_lockstate);
_network->subscribe(_mqttPath, mqtt_topic_query_battery);
if(_preferences->getBool(preference_disable_non_json, false))
if(_disableNonJSON)
{
_network->removeTopic(_mqttPath, mqtt_topic_keypad_command_action);
_network->removeTopic(_mqttPath, mqtt_topic_keypad_command_id);
@@ -125,7 +127,7 @@ void NukiNetworkLock::initialize()
if(_preferences->getBool(preference_keypad_control_enabled))
{
if(!_preferences->getBool(preference_disable_non_json, false))
if(!_disableNonJSON)
{
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_action);
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_id);
@@ -151,7 +153,7 @@ void NukiNetworkLock::initialize()
_network->initTopic(_mqttPath, mqtt_topic_timecontrol_action, "--");
}
if(_preferences->getBool(preference_official_hybrid, false))
if(_offEnabled)
{
char uidString[20];
itoa(_preferences->getUInt(preference_nuki_id_lock, 0), uidString, 16);
@@ -253,7 +255,7 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const
if(atoi(value) > 0 && atoi(value) > _lastRollingLog) _lastRollingLog = atoi(value);
}
if(_preferences->getBool(preference_official_hybrid, false))
if(_offEnabled)
{
for(auto offTopic : _offTopics)
{
@@ -301,7 +303,7 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const
}
}
if(!_preferences->getBool(preference_disable_non_json, false))
if(!_disableNonJSON)
{
if(comparePrefixedPath(topic, mqtt_topic_keypad_command_action))
{
@@ -515,14 +517,14 @@ void NukiNetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyT
jsonBattery["level"] = level;
jsonBattery["keypadCritical"] = keypadCritical ? "1" : "0";
if((_firstTunerStatePublish || keyTurnerState.criticalBatteryState != lastKeyTurnerState.criticalBatteryState) && !_preferences->getBool(preference_disable_non_json, false))
if((_firstTunerStatePublish || keyTurnerState.criticalBatteryState != lastKeyTurnerState.criticalBatteryState) && !_disableNonJSON)
{
publishBool(mqtt_topic_battery_critical, critical, true);
publishBool(mqtt_topic_battery_charging, charging, true);
publishInt(mqtt_topic_battery_level, level, true);
}
if((_firstTunerStatePublish || keyTurnerState.accessoryBatteryState != lastKeyTurnerState.accessoryBatteryState) && !_preferences->getBool(preference_disable_non_json, false))
if((_firstTunerStatePublish || keyTurnerState.accessoryBatteryState != lastKeyTurnerState.accessoryBatteryState) && !_disableNonJSON)
{
publishBool(mqtt_topic_battery_keypad_critical, keypadCritical, true);
}
@@ -736,7 +738,7 @@ void NukiNetworkLock::publishLockstateCommandResult(const char *resultStr)
void NukiNetworkLock::publishBatteryReport(const NukiLock::BatteryReport& batteryReport)
{
if(!_preferences->getBool(preference_disable_non_json, false))
if(!_disableNonJSON)
{
publishFloat(mqtt_topic_battery_voltage, (float)batteryReport.batteryVoltage / 1000.0, true);
publishInt(mqtt_topic_battery_drain, batteryReport.batteryDrain, true); // milliwatt seconds
@@ -818,7 +820,7 @@ void NukiNetworkLock::publishConfig(const NukiLock::Config &config)
serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_config_basic_json, _buffer, true);
if(!_preferences->getBool(preference_disable_non_json, false))
if(!_disableNonJSON)
{
publishBool(mqtt_topic_config_button_enabled, config.buttonEnabled == 1, true);
publishBool(mqtt_topic_config_led_enabled, config.ledEnabled == 1, true);
@@ -873,7 +875,7 @@ void NukiNetworkLock::publishAdvancedConfig(const NukiLock::AdvancedConfig &conf
serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_config_advanced_json, _buffer, true);
if(!_preferences->getBool(preference_disable_non_json, false))
if(!_disableNonJSON)
{
publishBool(mqtt_topic_config_auto_unlock, config.autoUnLockDisabled == 0, true);
publishBool(mqtt_topic_config_auto_lock, config.autoLockEnabled == 1, true);
@@ -897,6 +899,8 @@ void NukiNetworkLock::publishBleAddress(const std::string &address)
void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount)
{
bool publishCode = _preferences->getBool(preference_keypad_publish_code, false);
bool topicPerEntry = _preferences->getBool(preference_keypad_topic_per_entry, false);
uint index = 0;
char uidString[20];
itoa(_preferences->getUInt(preference_nuki_id_lock, 0), uidString, 16);
@@ -914,11 +918,7 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
jsonEntry["codeId"] = entry.codeId;
if(_preferences->getBool(preference_keypad_publish_code, false))
{
jsonEntry["code"] = entry.code;
}
if(publishCode) jsonEntry["code"] = entry.code;
jsonEntry["enabled"] = entry.enabled;
jsonEntry["name"] = entry.name;
char createdDT[20];
@@ -991,7 +991,7 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
sprintf(allowedUntilTimeT, "%02d:%02d", entry.allowedUntilTimeHour, entry.allowedUntilTimeMin);
jsonEntry["allowedUntilTime"] = allowedUntilTimeT;
if(_preferences->getBool(preference_keypad_topic_per_entry, false))
if(topicPerEntry)
{
basePath = mqtt_topic_keypad;
basePath.concat("/codes/");
@@ -1042,7 +1042,7 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_keypad_json, _buffer, true);
if(!_preferences->getBool(preference_disable_non_json, false))
if(!_disableNonJSON)
{
while(index < maxKeypadCodeCount)
{
@@ -1056,7 +1056,7 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
++index;
}
if(!_preferences->getBool(preference_keypad_publish_code, false))
if(!publishCode)
{
for(int i=0; i<maxKeypadCodeCount; i++)
{
@@ -1107,7 +1107,7 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
void NukiNetworkLock::publishKeypadEntry(const String topic, NukiLock::KeypadEntry entry)
{
if(_preferences->getBool(preference_disable_non_json, false)) return;
if(_disableNonJSON) return;
char codeName[sizeof(entry.name) + 1];
memset(codeName, 0, sizeof(codeName));
@@ -1133,6 +1133,7 @@ void NukiNetworkLock::publishKeypadEntry(const String topic, NukiLock::KeypadEnt
void NukiNetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEntry>& timeControlEntries, uint maxTimeControlEntryCount)
{
bool topicPerEntry = _preferences->getBool(preference_timecontrol_topic_per_entry, false);
uint index = 0;
char str[50];
char uidString[20];
@@ -1202,7 +1203,7 @@ void NukiNetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEn
NukiLock::lockactionToString(entry.lockAction, str);
jsonEntry["lockAction"] = str;
if(_preferences->getBool(preference_timecontrol_topic_per_entry, false))
if(topicPerEntry)
{
String basePath = mqtt_topic_timecontrol;
basePath.concat("/entries/");
@@ -1267,7 +1268,7 @@ void NukiNetworkLock::publishConfigCommandResult(const char* result)
void NukiNetworkLock::publishKeypadCommandResult(const char* result)
{
if(_preferences->getBool(preference_disable_non_json, false)) return;
if(_disableNonJSON) return;
publishString(mqtt_topic_keypad_command_result, result, true);
}
@@ -1303,7 +1304,7 @@ void NukiNetworkLock::setConfigUpdateReceivedCallback(void (*configUpdateReceive
void NukiNetworkLock::setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled))
{
if(_preferences->getBool(preference_disable_non_json, false)) return;
if(_disableNonJSON) return;
_keypadCommandReceivedReceivedCallback = keypadCommandReceivedReceivedCallback;
}