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.

41 lines
1.3 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 read(LightMqttSettings& settings, JsonObject& root) {
  14. root["mqtt_path"] = settings.mqttPath;
  15. root["name"] = settings.name;
  16. root["unique_id"] = settings.uniqueId;
  17. }
  18. static StateUpdateResult update(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. return StateUpdateResult::CHANGED;
  23. }
  24. };
  25. class LightMqttSettingsService : public StatefulService<LightMqttSettings> {
  26. public:
  27. LightMqttSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
  28. void begin();
  29. private:
  30. HttpEndpoint<LightMqttSettings> _httpEndpoint;
  31. FSPersistence<LightMqttSettings> _fsPersistence;
  32. };
  33. #endif // end LightMqttSettingsService_h