Factory reset feature (#114)

Implemented factory-reset feature
Extract factory settings into separate ini file
Hide reset/factory reset from guest user

Co-authored-by: kasedy <kasedy@gmail.com>
This commit is contained in:
rjwats
2020-05-20 00:32:49 +01:00
committed by GitHub
parent 51dabb705f
commit a59f32c420
31 changed files with 410 additions and 1592 deletions

View File

@ -3,18 +3,11 @@
#include <HttpEndpoint.h>
#include <FSPersistence.h>
#include <ESPUtils.h>
#define LIGHT_BROKER_SETTINGS_FILE "/config/brokerSettings.json"
#define LIGHT_BROKER_SETTINGS_PATH "/rest/brokerSettings"
static String defaultDeviceValue(String prefix = "") {
#ifdef ESP32
return prefix + String((unsigned long)ESP.getEfuseMac(), HEX);
#elif defined(ESP8266)
return prefix + String(ESP.getChipId(), HEX);
#endif
}
class LightMqttSettings {
public:
String mqttPath;
@ -28,9 +21,9 @@ class LightMqttSettings {
}
static void deserialize(JsonObject& root, LightMqttSettings& settings) {
settings.mqttPath = root["mqtt_path"] | defaultDeviceValue("homeassistant/light/");
settings.name = root["name"] | defaultDeviceValue("light-");
settings.uniqueId = root["unique_id"] | defaultDeviceValue("light-");
settings.mqttPath = root["mqtt_path"] | ESPUtils::defaultDeviceValue("homeassistant/light/");
settings.name = root["name"] | ESPUtils::defaultDeviceValue("light-");
settings.uniqueId = root["unique_id"] | ESPUtils::defaultDeviceValue("light-");
}
};

View File

@ -70,4 +70,4 @@ void LightStateService::registerConfig() {
_mqttClient->publish(configTopic.c_str(), 0, false, payload.c_str());
_mqttPubSub.configureTopics(stateTopic, setTopic);
}
}