d1_mini_pro-sensor-mqtt/lib/HomeAssistantDevices/HALightBrightness.cpp

30 lines
920 B
C++
Raw Normal View History

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