2020-05-14 22:23:45 +00:00
|
|
|
#ifndef LightMqttSettingsService_h
|
|
|
|
#define LightMqttSettingsService_h
|
|
|
|
|
|
|
|
#include <HttpEndpoint.h>
|
|
|
|
#include <FSPersistence.h>
|
2020-05-19 23:32:49 +00:00
|
|
|
#include <ESPUtils.h>
|
2020-05-14 22:23:45 +00:00
|
|
|
|
|
|
|
#define LIGHT_BROKER_SETTINGS_FILE "/config/brokerSettings.json"
|
|
|
|
#define LIGHT_BROKER_SETTINGS_PATH "/rest/brokerSettings"
|
|
|
|
|
|
|
|
class LightMqttSettings {
|
|
|
|
public:
|
|
|
|
String mqttPath;
|
|
|
|
String name;
|
|
|
|
String uniqueId;
|
|
|
|
|
|
|
|
static void serialize(LightMqttSettings& settings, JsonObject& root) {
|
|
|
|
root["mqtt_path"] = settings.mqttPath;
|
|
|
|
root["name"] = settings.name;
|
|
|
|
root["unique_id"] = settings.uniqueId;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void deserialize(JsonObject& root, LightMqttSettings& settings) {
|
2020-05-19 23:32:49 +00:00
|
|
|
settings.mqttPath = root["mqtt_path"] | ESPUtils::defaultDeviceValue("homeassistant/light/");
|
|
|
|
settings.name = root["name"] | ESPUtils::defaultDeviceValue("light-");
|
|
|
|
settings.uniqueId = root["unique_id"] | ESPUtils::defaultDeviceValue("light-");
|
2020-05-14 22:23:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class LightMqttSettingsService : public StatefulService<LightMqttSettings> {
|
|
|
|
public:
|
|
|
|
LightMqttSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
|
|
|
|
void begin();
|
|
|
|
|
|
|
|
private:
|
|
|
|
HttpEndpoint<LightMqttSettings> _httpEndpoint;
|
|
|
|
FSPersistence<LightMqttSettings> _fsPersistence;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // end LightMqttSettingsService_h
|