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:
@@ -1,5 +1,4 @@
|
||||
#include "NukiWrapper.h"
|
||||
#include <RTOS.h>
|
||||
#include "PreferencesKeys.h"
|
||||
#include "MqttTopics.h"
|
||||
#include "Logger.h"
|
||||
@@ -35,7 +34,7 @@ NukiWrapper::NukiWrapper(const std::string& deviceName, NukiDeviceId* deviceId,
|
||||
network->setLockActionReceivedCallback(nukiInst->onLockActionReceivedCallback);
|
||||
network->setOfficialUpdateReceivedCallback(nukiInst->onOfficialUpdateReceivedCallback);
|
||||
network->setConfigUpdateReceivedCallback(nukiInst->onConfigUpdateReceivedCallback);
|
||||
if(_preferences->getBool(preference_disable_non_json, false)) network->setKeypadCommandReceivedCallback(nukiInst->onKeypadCommandReceivedCallback);
|
||||
if(_disableNonJSON) network->setKeypadCommandReceivedCallback(nukiInst->onKeypadCommandReceivedCallback);
|
||||
network->setKeypadJsonCommandReceivedCallback(nukiInst->onKeypadJsonCommandReceivedCallback);
|
||||
network->setTimeControlCommandReceivedCallback(nukiInst->onTimeControlCommandReceivedCallback);
|
||||
|
||||
@@ -54,15 +53,16 @@ void NukiWrapper::initialize(const bool& firstStart)
|
||||
_nukiLock.initialize();
|
||||
|
||||
esp_power_level_t powerLevel;
|
||||
int pwrLvl = _preferences->getInt(preference_ble_tx_power, 9);
|
||||
|
||||
if(_preferences->getInt(preference_ble_tx_power, 9) >= 9) powerLevel = ESP_PWR_LVL_P9;
|
||||
else if(_preferences->getInt(preference_ble_tx_power, 9) >= 6) powerLevel = ESP_PWR_LVL_P6;
|
||||
else if(_preferences->getInt(preference_ble_tx_power, 9) >= 3) powerLevel = ESP_PWR_LVL_P6;
|
||||
else if(_preferences->getInt(preference_ble_tx_power, 9) >= 0) powerLevel = ESP_PWR_LVL_P3;
|
||||
else if(_preferences->getInt(preference_ble_tx_power, 9) >= -3) powerLevel = ESP_PWR_LVL_N3;
|
||||
else if(_preferences->getInt(preference_ble_tx_power, 9) >= -6) powerLevel = ESP_PWR_LVL_N6;
|
||||
else if(_preferences->getInt(preference_ble_tx_power, 9) >= -9) powerLevel = ESP_PWR_LVL_N9;
|
||||
else if(_preferences->getInt(preference_ble_tx_power, 9) >= -12) powerLevel = ESP_PWR_LVL_N12;
|
||||
if(pwrLvl >= 9) powerLevel = ESP_PWR_LVL_P9;
|
||||
else if(pwrLvl >= 6) powerLevel = ESP_PWR_LVL_P6;
|
||||
else if(pwrLvl >= 3) powerLevel = ESP_PWR_LVL_P6;
|
||||
else if(pwrLvl >= 0) powerLevel = ESP_PWR_LVL_P3;
|
||||
else if(pwrLvl >= -3) powerLevel = ESP_PWR_LVL_N3;
|
||||
else if(pwrLvl >= -6) powerLevel = ESP_PWR_LVL_N6;
|
||||
else if(pwrLvl >= -9) powerLevel = ESP_PWR_LVL_N9;
|
||||
else if(pwrLvl >= -12) powerLevel = ESP_PWR_LVL_N12;
|
||||
|
||||
_nukiLock.setPower(powerLevel);
|
||||
_nukiLock.registerBleScanner(_bleScanner);
|
||||
@@ -81,6 +81,11 @@ void NukiWrapper::initialize(const bool& firstStart)
|
||||
_nrOfRetries = _preferences->getInt(preference_command_nr_of_retries, 200);
|
||||
_retryDelay = _preferences->getInt(preference_command_retry_delay);
|
||||
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000;
|
||||
_offEnabled = _preferences->getBool(preference_official_hybrid, false);
|
||||
_disableNonJSON = _preferences->getBool(preference_disable_non_json, false);
|
||||
|
||||
_preferences->getBytes(preference_conf_lock_basic_acl, &_basicLockConfigaclPrefs, sizeof(_basicLockConfigaclPrefs));
|
||||
_preferences->getBytes(preference_conf_lock_advanced_acl, &_advancedLockConfigaclPrefs, sizeof(_advancedLockConfigaclPrefs));
|
||||
|
||||
if(firstStart)
|
||||
{
|
||||
@@ -128,9 +133,9 @@ void NukiWrapper::initialize(const bool& firstStart)
|
||||
_preferences->putInt(preference_query_interval_configuration, 3600);
|
||||
_preferences->putInt(preference_query_interval_battery, 1800);
|
||||
_preferences->putInt(preference_query_interval_keypad, 1800);
|
||||
#if PRESENCE_DETECTION_ENABLED
|
||||
#if PRESENCE_DETECTION_ENABLED
|
||||
_preferences->putInt(preference_presence_detection_timeout, -1);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
if(_nrOfRetries < 0 || _nrOfRetries == 200)
|
||||
@@ -898,6 +903,7 @@ LockActionResult NukiWrapper::onLockActionReceivedCallback(const char *value)
|
||||
}
|
||||
|
||||
nukiLockPreferences->end();
|
||||
|
||||
return LockActionResult::AccessDenied;
|
||||
}
|
||||
|
||||
@@ -1041,10 +1047,7 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
Log->print(F("Lockstate: "));
|
||||
Log->println(str);
|
||||
|
||||
if(_preferences->getString(preference_mqtt_hass_discovery) != "")
|
||||
{
|
||||
_network->publishState((NukiLock::LockState)_network->_offState);
|
||||
}
|
||||
_network->publishState((NukiLock::LockState)_network->_offState);
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_doorsensorState) == 0)
|
||||
{
|
||||
@@ -1066,7 +1069,7 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
Log->print(F("Battery critical: "));
|
||||
Log->println(_network->_offCritical);
|
||||
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_critical, _network->_offCritical, true);
|
||||
if(!_disableNonJSON) _network->publishBool(mqtt_topic_battery_critical, _network->_offCritical, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_batteryCharging) == 0)
|
||||
@@ -1076,7 +1079,7 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
Log->print(F("Battery charging: "));
|
||||
Log->println(_network->_offCharging);
|
||||
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_charging, _network->_offCharging, true);
|
||||
if(!_disableNonJSON) _network->publishBool(mqtt_topic_battery_charging, _network->_offCharging, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_batteryChargeState) == 0)
|
||||
@@ -1086,19 +1089,19 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
Log->print(F("Battery level: "));
|
||||
Log->println(_network->_offChargeState);
|
||||
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishInt(mqtt_topic_battery_level, _network->_offChargeState, true);
|
||||
if(!_disableNonJSON) _network->publishInt(mqtt_topic_battery_level, _network->_offChargeState, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_keypadBatteryCritical) == 0)
|
||||
{
|
||||
_network->_offKeypadCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_keypad_critical, _network->_offKeypadCritical, true);
|
||||
if(!_disableNonJSON) _network->publishBool(mqtt_topic_battery_keypad_critical, _network->_offKeypadCritical, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_doorsensorBatteryCritical) == 0)
|
||||
{
|
||||
_network->_offDoorsensorCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_doorsensor_critical, _network->_offDoorsensorCritical, true);
|
||||
if(!_disableNonJSON) _network->publishBool(mqtt_topic_battery_doorsensor_critical, _network->_offDoorsensorCritical, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_commandResponse) == 0)
|
||||
@@ -1197,13 +1200,6 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
const char *advancedKeys[22] = {"unlockedPositionOffsetDegrees", "lockedPositionOffsetDegrees", "singleLockedPositionOffsetDegrees", "unlockedToLockedTransitionOffsetDegrees", "lockNgoTimeout", "singleButtonPressAction", "doubleButtonPressAction", "detachedCylinder", "batteryType", "automaticBatteryTypeDetection", "unlatchDuration", "autoLockTimeOut", "autoUnLockDisabled", "nightModeEnabled", "nightModeStartTime", "nightModeEndTime", "nightModeAutoLockEnabled", "nightModeAutoUnlockDisabled", "nightModeImmediateLockOnStart", "autoLockEnabled", "immediateAutoLockEnabled", "autoUpdateEnabled"};
|
||||
bool basicUpdated = false;
|
||||
bool advancedUpdated = false;
|
||||
uint32_t basicLockConfigAclPrefs[16];
|
||||
uint32_t advancedLockConfigAclPrefs[22];
|
||||
|
||||
nukiLockPreferences = new Preferences();
|
||||
nukiLockPreferences->begin("nukihub", true);
|
||||
nukiLockPreferences->getBytes(preference_conf_lock_basic_acl, &basicLockConfigAclPrefs, sizeof(basicLockConfigAclPrefs));
|
||||
nukiLockPreferences->getBytes(preference_conf_lock_advanced_acl, &advancedLockConfigAclPrefs, sizeof(advancedLockConfigAclPrefs));
|
||||
|
||||
for(int i=0; i < 16; i++)
|
||||
{
|
||||
@@ -1217,7 +1213,7 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
continue;
|
||||
}
|
||||
|
||||
if((int)basicLockConfigAclPrefs[i] == 1)
|
||||
if((int)_basicLockConfigaclPrefs[i] == 1)
|
||||
{
|
||||
cmdResult = Nuki::CmdResult::Error;
|
||||
_retryCount = 0;
|
||||
@@ -1429,7 +1425,7 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
continue;
|
||||
}
|
||||
|
||||
if((int)advancedLockConfigAclPrefs[j] == 1)
|
||||
if((int)_advancedLockConfigaclPrefs[j] == 1)
|
||||
{
|
||||
cmdResult = Nuki::CmdResult::Error;
|
||||
_retryCount = 0;
|
||||
@@ -1701,8 +1697,6 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
}
|
||||
}
|
||||
|
||||
nukiLockPreferences->end();
|
||||
|
||||
if(basicUpdated || advancedUpdated) jsonResult["general"] = "success";
|
||||
else jsonResult["general"] = "noChange";
|
||||
|
||||
@@ -1731,9 +1725,6 @@ void NukiWrapper::onTimeControlCommandReceivedCallback(const char *value)
|
||||
|
||||
void NukiWrapper::gpioActionCallback(const GpioAction &action, const int& pin)
|
||||
{
|
||||
nukiLockPreferences = new Preferences();
|
||||
nukiLockPreferences->begin("nukihub", true);
|
||||
|
||||
switch(action)
|
||||
{
|
||||
case GpioAction::Lock:
|
||||
@@ -1782,13 +1773,11 @@ void NukiWrapper::gpioActionCallback(const GpioAction &action, const int& pin)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
nukiLockPreferences->end();
|
||||
}
|
||||
|
||||
void NukiWrapper::onKeypadCommandReceived(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;
|
||||
|
||||
if(!_preferences->getBool(preference_keypad_control_enabled))
|
||||
{
|
||||
@@ -2619,7 +2608,7 @@ void NukiWrapper::notify(Nuki::EventType eventType)
|
||||
{
|
||||
if(!_network->_offConnected)
|
||||
{
|
||||
if(_preferences->getBool(preference_official_hybrid, false) && _intervalHybridLockstate > 0 && (esp_timer_get_time() / 1000) > (_intervalHybridLockstate * 1000))
|
||||
if(_offEnabled && _intervalHybridLockstate > 0 && (esp_timer_get_time() / 1000) > (_intervalHybridLockstate * 1000))
|
||||
{
|
||||
Log->println("OffKeyTurnerStatusUpdated");
|
||||
_statusUpdated = true;
|
||||
|
||||
Reference in New Issue
Block a user