2022-12-30 18:31:20 +03:00
|
|
|
#include <HALightBrightness.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
HALightBrightness::HALightBrightness(PubSubClient &client, const char *name, const char *unique_id,
|
|
|
|
HALightBrightnessController &baseLight)
|
2023-01-18 19:23:01 +03:00
|
|
|
: HALight(client, name, unique_id, baseLight), light(&baseLight) {}
|
2022-12-30 18:31:20 +03:00
|
|
|
|
|
|
|
|
2023-01-18 19:23:01 +03:00
|
|
|
JSON_DOCUMENT_TYPE HALightBrightness::patchConfigJSON(JSON_DOCUMENT_TYPE &doc) {
|
2022-12-30 18:31:20 +03:00
|
|
|
doc["brightness"] = true;
|
|
|
|
doc["brightness_scale"] = light->getBrightnessScale();
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2023-01-18 19:23:01 +03:00
|
|
|
JSON_DOCUMENT_TYPE HALightBrightness::patchStateJSON(JSON_DOCUMENT_TYPE &doc) {
|
2022-12-30 18:31:20 +03:00
|
|
|
doc["brightness"] = light->getBrightness();
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2023-01-18 19:23:01 +03:00
|
|
|
void HALightBrightness::handleBrightness(const JSON_DOCUMENT_TYPE &doc) {
|
2022-12-30 18:31:20 +03:00
|
|
|
if (doc.containsKey("brightness")) {
|
|
|
|
light->setBrightness(doc["brightness"]);
|
|
|
|
}
|
2023-01-18 19:23:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HALightBrightness::innerHandler(const JSON_DOCUMENT_TYPE &doc) {
|
|
|
|
handleBrightness(doc);
|
2022-12-30 18:31:20 +03:00
|
|
|
delay(50);
|
2023-01-18 19:23:01 +03:00
|
|
|
HALight::innerHandler(doc);
|
2022-12-30 18:31:20 +03:00
|
|
|
}
|