добавляет HALightColorTemperatureBrightness
This commit is contained in:
@@ -18,6 +18,12 @@ JSON_DOCUMENT_TYPE HALight::createConfigJSON() {
|
||||
doc["stat_t"] = "~/state";
|
||||
doc["schema"] = "json";
|
||||
|
||||
patchConfigJSON(doc);
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
JSON_DOCUMENT_TYPE HALight::patchConfigJSON(JSON_DOCUMENT_TYPE &doc) {
|
||||
return doc;
|
||||
}
|
||||
|
||||
@@ -30,10 +36,16 @@ JSON_DOCUMENT_TYPE HALight::createStateJSON() {
|
||||
doc["state"] = "OFF";
|
||||
}
|
||||
|
||||
patchStateJSON(doc);
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
void HALight::innerHanlder(JSON_DOCUMENT_TYPE &doc) {
|
||||
JSON_DOCUMENT_TYPE HALight::patchStateJSON(JSON_DOCUMENT_TYPE &doc) {
|
||||
return doc;
|
||||
}
|
||||
|
||||
void HALight::innerHandler(const JSON_DOCUMENT_TYPE &doc) {
|
||||
if (strcmp(doc["state"], "ON") == 0) {
|
||||
light->setState(true);
|
||||
} else {
|
||||
@@ -65,7 +77,7 @@ void HALight::handle(char *topic, byte *payload, unsigned int length) {
|
||||
JSON_DOCUMENT_TYPE doc;
|
||||
deserializeJson(doc, (const byte *)payload, length);
|
||||
|
||||
innerHanlder(doc);
|
||||
innerHandler(doc);
|
||||
|
||||
sendState();
|
||||
}
|
@@ -16,13 +16,15 @@ private:
|
||||
|
||||
protected:
|
||||
virtual JSON_DOCUMENT_TYPE createConfigJSON();
|
||||
virtual JSON_DOCUMENT_TYPE patchConfigJSON(JSON_DOCUMENT_TYPE &doc);
|
||||
virtual JSON_DOCUMENT_TYPE createStateJSON();
|
||||
virtual void innerHanlder(JSON_DOCUMENT_TYPE &doc);
|
||||
virtual JSON_DOCUMENT_TYPE patchStateJSON(JSON_DOCUMENT_TYPE &doc);
|
||||
virtual void innerHandler(const JSON_DOCUMENT_TYPE &doc);
|
||||
HALight(PubSubClient &client, const char *name, const char *unique_id);
|
||||
public:
|
||||
HALight(PubSubClient &client, const char *name, const char *unique_id,
|
||||
HALightController &baseLight);
|
||||
void handle(char *topic, byte *payload, unsigned int length);
|
||||
void sendConfig();
|
||||
void sendState();
|
||||
void handle(char *topic, byte *payload, unsigned int length) override;
|
||||
void sendConfig() override;
|
||||
void sendState() override;
|
||||
};
|
@@ -3,35 +3,28 @@
|
||||
|
||||
HALightBrightness::HALightBrightness(PubSubClient &client, const char *name, const char *unique_id,
|
||||
HALightBrightnessController &baseLight)
|
||||
: HALight(client, "light", name, baseLight),
|
||||
light(&baseLight) {}
|
||||
: HALight(client, name, unique_id, baseLight), light(&baseLight) {}
|
||||
|
||||
|
||||
JSON_DOCUMENT_TYPE HALightBrightness::createConfigJSON() {
|
||||
JSON_DOCUMENT_TYPE doc = HALight::createConfigJSON();
|
||||
|
||||
JSON_DOCUMENT_TYPE HALightBrightness::patchConfigJSON(JSON_DOCUMENT_TYPE &doc) {
|
||||
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();
|
||||
|
||||
JSON_DOCUMENT_TYPE HALightBrightness::patchStateJSON(JSON_DOCUMENT_TYPE &doc) {
|
||||
doc["brightness"] = light->getBrightness();
|
||||
|
||||
// JSON_DOCUMENT_TYPE doc;
|
||||
return doc;
|
||||
}
|
||||
|
||||
void HALightBrightness::innerHanlder(JSON_DOCUMENT_TYPE &doc) {
|
||||
void HALightBrightness::handleBrightness(const JSON_DOCUMENT_TYPE &doc) {
|
||||
if (doc.containsKey("brightness")) {
|
||||
light->setBrightness(doc["brightness"]);
|
||||
}
|
||||
}
|
||||
|
||||
void HALightBrightness::innerHandler(const JSON_DOCUMENT_TYPE &doc) {
|
||||
handleBrightness(doc);
|
||||
delay(50);
|
||||
HALight::innerHanlder(doc);
|
||||
HALight::innerHandler(doc);
|
||||
}
|
@@ -2,23 +2,25 @@
|
||||
|
||||
#include <HALight.hpp>
|
||||
|
||||
class HALightBrightnessController: public HALightController {
|
||||
class HALightBrightnessController: public virtual HALightController {
|
||||
public:
|
||||
virtual void setBrightness(int value) = 0;
|
||||
virtual int getBrightness() = 0;
|
||||
|
||||
|
||||
virtual int getBrightnessScale() = 0;
|
||||
};
|
||||
|
||||
class HALightBrightness : public HALight {
|
||||
class HALightBrightness : public virtual HALight {
|
||||
private:
|
||||
HALightBrightnessController *light;
|
||||
|
||||
protected:
|
||||
JSON_DOCUMENT_TYPE createConfigJSON() override;
|
||||
JSON_DOCUMENT_TYPE createStateJSON() override;
|
||||
void innerHanlder(JSON_DOCUMENT_TYPE &doc) override;
|
||||
virtual JSON_DOCUMENT_TYPE patchConfigJSON(JSON_DOCUMENT_TYPE &doc) override;
|
||||
virtual JSON_DOCUMENT_TYPE patchStateJSON(JSON_DOCUMENT_TYPE &doc) override;
|
||||
virtual void innerHandler(const JSON_DOCUMENT_TYPE &doc) override;
|
||||
|
||||
void handleBrightness(const JSON_DOCUMENT_TYPE &doc);
|
||||
|
||||
public:
|
||||
HALightBrightness(PubSubClient &client, const char *name, const char *unique_id,
|
||||
HALightBrightnessController &baseLight);
|
||||
|
28
lib/HomeAssistantDevices/HALightColorTemperature.cpp
Normal file
28
lib/HomeAssistantDevices/HALightColorTemperature.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <HALightColorTemperature.hpp>
|
||||
|
||||
HALightColorTemperature::HALightColorTemperature(PubSubClient &client, const char *name, const char *unique_id,
|
||||
HALightColorTemperatureController &baseLight)
|
||||
: HALight(client, "light", name, baseLight),
|
||||
light(&baseLight) {}
|
||||
|
||||
JSON_DOCUMENT_TYPE HALightColorTemperature::patchConfigJSON(JSON_DOCUMENT_TYPE &doc) {
|
||||
doc["color_temp"] = true;
|
||||
return doc;
|
||||
}
|
||||
|
||||
JSON_DOCUMENT_TYPE HALightColorTemperature::patchStateJSON(JSON_DOCUMENT_TYPE &doc) {
|
||||
doc["color_temp"] = light->getColorTemperature();
|
||||
return doc;
|
||||
}
|
||||
|
||||
void HALightColorTemperature::handleColorTemperature(const JSON_DOCUMENT_TYPE &doc) {
|
||||
if (doc.containsKey("color_temp")) {
|
||||
light->setColorTemperature(doc["color_temp"]);
|
||||
}
|
||||
}
|
||||
|
||||
void HALightColorTemperature::innerHandler(const JSON_DOCUMENT_TYPE &doc) {
|
||||
handleColorTemperature(doc);
|
||||
delay(50);
|
||||
HALight::innerHandler(doc);
|
||||
}
|
26
lib/HomeAssistantDevices/HALightColorTemperature.hpp
Normal file
26
lib/HomeAssistantDevices/HALightColorTemperature.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <HALight.hpp>
|
||||
|
||||
class HALightColorTemperatureController: public virtual HALightController {
|
||||
public:
|
||||
virtual void setColorTemperature(int value) = 0;
|
||||
virtual int getColorTemperature() = 0;
|
||||
|
||||
virtual int getBrightnessScale() = 0;
|
||||
};
|
||||
|
||||
class HALightColorTemperature : public virtual HALight {
|
||||
private:
|
||||
HALightColorTemperatureController *light;
|
||||
|
||||
protected:
|
||||
virtual JSON_DOCUMENT_TYPE patchConfigJSON(JSON_DOCUMENT_TYPE &doc) override;
|
||||
virtual JSON_DOCUMENT_TYPE patchStateJSON(JSON_DOCUMENT_TYPE &doc) override;
|
||||
virtual void innerHandler(const JSON_DOCUMENT_TYPE &doc) override;
|
||||
|
||||
void handleColorTemperature(const JSON_DOCUMENT_TYPE &doc);
|
||||
public:
|
||||
HALightColorTemperature(PubSubClient &client, const char *name, const char *unique_id,
|
||||
HALightColorTemperatureController &baseLight);
|
||||
};
|
@@ -0,0 +1,34 @@
|
||||
#include <HALightColorTemperatureBrightness.hpp>
|
||||
|
||||
HALightColorTemperatureBrightness::HALightColorTemperatureBrightness(
|
||||
PubSubClient &client,
|
||||
const char *name,
|
||||
const char *unique_id,
|
||||
HALightColorTemperatureBrightnessController &baseLight
|
||||
) :
|
||||
HALightBrightness(client, name, unique_id, baseLight),
|
||||
HALightColorTemperature(client, name, unique_id, baseLight),
|
||||
HALight(client, name, unique_id, baseLight),
|
||||
light(&baseLight)
|
||||
{
|
||||
}
|
||||
|
||||
JSON_DOCUMENT_TYPE HALightColorTemperatureBrightness::patchConfigJSON(JSON_DOCUMENT_TYPE &doc) {
|
||||
HALightBrightness::patchConfigJSON(doc);
|
||||
HALightColorTemperature::patchConfigJSON(doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
JSON_DOCUMENT_TYPE HALightColorTemperatureBrightness::patchStateJSON(JSON_DOCUMENT_TYPE &doc) {
|
||||
HALightBrightness::patchStateJSON(doc);
|
||||
HALightColorTemperature::patchStateJSON(doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
void HALightColorTemperatureBrightness::innerHandler(const JSON_DOCUMENT_TYPE &doc) {
|
||||
handleBrightness(doc);
|
||||
delay(50);
|
||||
handleColorTemperature(doc);
|
||||
delay(50);
|
||||
HALight::innerHandler(doc);
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <HALightBrightness.hpp>
|
||||
#include <HALightColorTemperature.hpp>
|
||||
|
||||
class HALightColorTemperatureBrightnessController:
|
||||
public HALightBrightnessController,
|
||||
public HALightColorTemperatureController
|
||||
{
|
||||
};
|
||||
|
||||
class HALightColorTemperatureBrightness :
|
||||
public HALightBrightness,
|
||||
public HALightColorTemperature
|
||||
{
|
||||
private:
|
||||
HALightColorTemperatureBrightnessController *light;
|
||||
|
||||
protected:
|
||||
JSON_DOCUMENT_TYPE patchConfigJSON(JSON_DOCUMENT_TYPE &doc) override;
|
||||
JSON_DOCUMENT_TYPE patchStateJSON(JSON_DOCUMENT_TYPE &doc) override;
|
||||
virtual void innerHandler(const JSON_DOCUMENT_TYPE &doc) override;
|
||||
public:
|
||||
HALightColorTemperatureBrightness(PubSubClient &client, const char *name, const char *unique_id,
|
||||
HALightColorTemperatureBrightnessController &baseLight);
|
||||
};
|
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <HALight.hpp>
|
||||
#include <HALightBrightness.hpp>
|
||||
#include <HALightBrightness.hpp>
|
||||
#include <HALightColorTemperature.hpp>
|
||||
#include <HALightColorTemperatureBrightness.hpp>
|
Reference in New Issue
Block a user