0d39c5ca00
* Rename "serialize" and "deserialize" functions to "read" and "update" to reflect API in StatefulService * Move new definitions to StatefulService.h so it is obvious it is not general purpose * Update README
42 lines
1.3 KiB
C++
42 lines
1.3 KiB
C++
#ifndef LightMqttSettingsService_h
|
|
#define LightMqttSettingsService_h
|
|
|
|
#include <HttpEndpoint.h>
|
|
#include <FSPersistence.h>
|
|
#include <ESPUtils.h>
|
|
|
|
#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 read(LightMqttSettings& settings, JsonObject& root) {
|
|
root["mqtt_path"] = settings.mqttPath;
|
|
root["name"] = settings.name;
|
|
root["unique_id"] = settings.uniqueId;
|
|
}
|
|
|
|
static StateUpdateResult update(JsonObject& root, LightMqttSettings& settings) {
|
|
settings.mqttPath = root["mqtt_path"] | ESPUtils::defaultDeviceValue("homeassistant/light/");
|
|
settings.name = root["name"] | ESPUtils::defaultDeviceValue("light-");
|
|
settings.uniqueId = root["unique_id"] | ESPUtils::defaultDeviceValue("light-");
|
|
return StateUpdateResult::CHANGED;
|
|
}
|
|
};
|
|
|
|
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
|