Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

  1. #ifndef LightMqttSettingsService_h
  2. #define LightMqttSettingsService_h
  3. #include <HttpEndpoint.h>
  4. #include <FSPersistence.h>
  5. #include <ESPUtils.h>
  6. #define LIGHT_BROKER_SETTINGS_FILE "/config/brokerSettings.json"
  7. #define LIGHT_BROKER_SETTINGS_PATH "/rest/brokerSettings"
  8. class LightMqttSettings {
  9. public:
  10. String mqttPath;
  11. String name;
  12. String uniqueId;
  13. static void serialize(LightMqttSettings& settings, JsonObject& root) {
  14. root["mqtt_path"] = settings.mqttPath;
  15. root["name"] = settings.name;
  16. root["unique_id"] = settings.uniqueId;
  17. }
  18. static void deserialize(JsonObject& root, LightMqttSettings& settings) {
  19. settings.mqttPath = root["mqtt_path"] | ESPUtils::defaultDeviceValue("homeassistant/light/");
  20. settings.name = root["name"] | ESPUtils::defaultDeviceValue("light-");
  21. settings.uniqueId = root["unique_id"] | ESPUtils::defaultDeviceValue("light-");
  22. }
  23. };
  24. class LightMqttSettingsService : public StatefulService<LightMqttSettings> {
  25. public:
  26. LightMqttSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
  27. void begin();
  28. private:
  29. HttpEndpoint<LightMqttSettings> _httpEndpoint;
  30. FSPersistence<LightMqttSettings> _fsPersistence;
  31. };
  32. #endif // end LightMqttSettingsService_h