Refractor

This commit is contained in:
iranl
2024-11-07 23:11:47 +01:00
parent d764ef313a
commit c2d3a3e77d
28 changed files with 827 additions and 705 deletions

View File

@@ -2,6 +2,9 @@
#include <vector>
#include "Config.h"
#ifndef CONFIG_IDF_TARGET_ESP32H2
#include "esp_wifi.h"
#endif
//CHANGE REQUIRES REBOOT TO TAKE EFFECT
#define preference_ip_dhcp_enabled (char*)"dhcpena"
@@ -129,17 +132,17 @@
#define preference_presence_detection_timeout (char*)"prdtimeout"
#define preference_network_wifi_fallback_disabled (char*)"nwwififb"
inline bool initPreferences(Preferences* preferences)
inline void initPreferences(Preferences* preferences)
{
#ifdef NUKI_HUB_UPDATER
bool firstStart = false;
return firstStart;
return;
#else
bool firstStart = !preferences->getBool(preference_started_before);
#endif
if(firstStart)
{
Serial.println("First start, setting preference defaults");
preferences->putBool(preference_started_before, true);
preferences->putBool(preference_lock_enabled, true);
uint32_t aclPrefs[17] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
@@ -152,6 +155,69 @@ inline bool initPreferences(Preferences* preferences)
preferences->putBytes(preference_conf_lock_advanced_acl, (byte*)(&advancedLockConfigAclPrefs), sizeof(advancedLockConfigAclPrefs));
uint32_t advancedOpenerConfigAclPrefs[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs));
#ifndef CONFIG_IDF_TARGET_ESP32H2
wifi_config_t wifi_cfg;
if(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK)
{
Serial.println("Failed to get Wi-Fi configuration in RAM");
}
if (esp_wifi_set_storage(WIFI_STORAGE_FLASH) != ESP_OK)
{
Serial.println("Failed to set storage Wi-Fi");
}
memset(wifi_cfg.sta.ssid, 0, sizeof(wifi_cfg.sta.ssid));
memset(wifi_cfg.sta.password, 0, sizeof(wifi_cfg.sta.password));
if (esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK)
{
Serial.println("Failed to clear NVS Wi-Fi configuration");
}
#endif
preferences->putString(preference_mqtt_lock_path, "nukihub");
preferences->putBool(preference_check_updates, true);
preferences->putBool(preference_opener_continuous_mode, false);
preferences->putBool(preference_official_hybrid_enabled, false);
preferences->putBool(preference_official_hybrid_actions, false);
preferences->putBool(preference_official_hybrid_retry, false);
preferences->putBool(preference_disable_non_json, false);
preferences->putBool(preference_update_from_mqtt, false);
preferences->putBool(preference_ip_dhcp_enabled, true);
preferences->putBool(preference_enable_bootloop_reset, false);
preferences->putBool(preference_show_secrets, false);
preferences->putBool(preference_conf_info_enabled, true);
preferences->putBool(preference_keypad_info_enabled, false);
preferences->putBool(preference_keypad_topic_per_entry, false);
preferences->putBool(preference_keypad_publish_code, false);
preferences->putBool(preference_keypad_control_enabled, false);
preferences->putBool(preference_timecontrol_info_enabled, false);
preferences->putBool(preference_timecontrol_topic_per_entry, false);
preferences->putBool(preference_timecontrol_control_enabled, false);
preferences->putBool(preference_publish_authdata, false);
preferences->putBool(preference_register_as_app, false);
preferences->putBool(preference_register_opener_as_app, false);
preferences->putInt(preference_mqtt_broker_port, 1883);
preferences->putInt(preference_buffer_size, CHAR_BUFFER_SIZE);
preferences->putInt(preference_task_size_network, NETWORK_TASK_SIZE);
preferences->putInt(preference_task_size_nuki, NUKI_TASK_SIZE);
preferences->putInt(preference_authlog_max_entries, MAX_AUTHLOG);
preferences->putInt(preference_keypad_max_entries, MAX_KEYPAD);
preferences->putInt(preference_timecontrol_max_entries, MAX_TIMECONTROL);
preferences->putInt(preference_query_interval_hybrid_lockstate, 600);
preferences->putInt(preference_rssi_publish_interval, 60);
preferences->putInt(preference_network_timeout, 60);
preferences->putInt(preference_command_nr_of_retries, 3);
preferences->putInt(preference_command_retry_delay, 100);
preferences->putInt(preference_restart_ble_beacon_lost, 60);
preferences->putInt(preference_query_interval_lockstate, 1800);
preferences->putInt(preference_query_interval_configuration, 3600);
preferences->putInt(preference_query_interval_battery, 1800);
preferences->putInt(preference_query_interval_keypad, 1800);
}
else
{
@@ -266,8 +332,7 @@ inline bool initPreferences(Preferences* preferences)
preferences->putInt(preference_config_version, atof(NUKI_HUB_VERSION) * 100);
}
}
return firstStart;
#endif
}
class DebugPreferences