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

37 lines
1023 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, "light", name, baseLight),
light(&baseLight) {}
JSON_DOCUMENT_TYPE HALightBrightness::createConfigJSON() {
JSON_DOCUMENT_TYPE doc = HALight::createConfigJSON();
doc["brightness"] = true;
doc["brightness_scale"] = light->getBrightnessScale();
// doc["color_mode"] = true;
// doc["supported_color_modes"] =
// JSON_DOCUMENT_TYPE doc;
return doc;
}
JSON_DOCUMENT_TYPE HALightBrightness::createStateJSON() {
JSON_DOCUMENT_TYPE doc = HALight::createStateJSON();
doc["brightness"] = light->getBrightness();
// JSON_DOCUMENT_TYPE doc;
return doc;
}
void HALightBrightness::innerHanlder(JSON_DOCUMENT_TYPE &doc) {
if (doc.containsKey("brightness")) {
light->setBrightness(doc["brightness"]);
}
delay(50);
HALight::innerHanlder(doc);
}