37 lines
1023 B
C++
37 lines
1023 B
C++
|
#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);
|
||
|
}
|