Merge remote-tracking branch 'origin/main' into feature/add_state_machine_usage

This commit is contained in:
2025-08-29 10:27:51 +02:00
2 changed files with 13 additions and 15 deletions

View File

@@ -14,8 +14,8 @@ const struct {
} Availability;
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Mqtt* mqttClient, std::string uniqueId)
: pinR(pinR), pinG(pinG), pinB(pinB), pinCW(nullptr), pinWW(nullptr), mqttClient(mqttClient) {
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, std::string uniqueId)
: pinR(pinR), pinG(pinG), pinB(pinB), pinCW(nullptr), pinWW(nullptr) {
lightInfo.uniqueId = uniqueId;
lightType = LightType::rgb;
uint8_t bits = pinR->getLedResolutionBits();
@@ -24,8 +24,8 @@ Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Mqtt* mqttClient, std::string uniq
subscribeToMqttTopics();
}
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, Mqtt* mqttClient, std::string uniqueId)
: pinR(pinR), pinG(pinG), pinB(pinB), pinCW(pinCW), pinWW(pinWW), mqttClient(mqttClient) {
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, std::string uniqueId)
: pinR(pinR), pinG(pinG), pinB(pinB), pinCW(pinCW), pinWW(pinWW) {
lightInfo.uniqueId = uniqueId;
lightType = LightType::rgbww;
uint8_t bits = pinR->getLedResolutionBits();
@@ -76,7 +76,7 @@ void Light::publishInitialState() {
std::string configJson;
serializeJson(configInfo, configJson);
mqttClient->publish(lightInfo.discoveryTopic, configJson);
Mqtt::publish(lightInfo.discoveryTopic, configJson);
std::string stateJson;
JsonDocument stateInfo;
@@ -95,8 +95,8 @@ void Light::publishInitialState() {
JsonDocument availabilityInfoDoc;
availabilityInfoDoc["availability"] = Availability.available;
serializeJson(availabilityInfoDoc, availabilityJson);
mqttClient->publish(lightInfo.stateTopic, stateJson);
mqttClient->publish(lightInfo.availabilityTopic, availabilityJson);
Mqtt::publish(lightInfo.stateTopic, stateJson);
Mqtt::publish(lightInfo.availabilityTopic, availabilityJson);
}
void Light::operatePin() {
@@ -159,7 +159,7 @@ void Light::operatePin() {
}
void Light::subscribeToMqttTopics() {
mqttClient->subscribe(lightInfo.commandTopic, [this](uint8_t* payload, int length) {
Mqtt::subscribe(lightInfo.commandTopic, [this](uint8_t* payload, int length) {
std::string command(reinterpret_cast<char*>(payload), length);
handleCommand(command);
});
@@ -241,11 +241,11 @@ void Light::publishCurrentState() {
std::string stateJson;
serializeJson(stateInfo, stateJson);
Serial.println("Publishing current state: " + String(stateJson.c_str()));
mqttClient->publish(lightInfo.stateTopic, stateJson);
Mqtt::publish(lightInfo.stateTopic, stateJson);
std::string attributeJson;
serializeJson(attributeInfo, attributeJson);
Serial.println("Publishing current attributes: " + String(attributeJson.c_str()));
mqttClient->publish(lightInfo.jsonAttributesTopic, attributeJson);
Mqtt::publish(lightInfo.jsonAttributesTopic, attributeJson);
}
uint32_t Light::correctGamma(uint32_t originalPwm) {

View File

@@ -2,7 +2,6 @@
#include <cstdint>
#include "pin.h"
#include "mqtt.h"
struct LightInfo {
std::string uniqueId;
@@ -65,9 +64,9 @@ enum ActiveMode {
class Light {
public:
Light(Pin* pinR, Pin* pinG, Pin* pinB, Mqtt* mqttClient, std::string uniqueId);
Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Mqtt* mqttClient, std::string uniqueId);
Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, Mqtt* mqttClient, std::string uniqueId);
Light(Pin* pinR, Pin* pinG, Pin* pinB, std::string uniqueId);
Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, std::string uniqueId);
Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, std::string uniqueId);
void subscribeToMqttTopics();
void publishInitialState();
void publishCurrentState();
@@ -97,7 +96,6 @@ private:
Pin* pinB;
Pin* pinCW;
Pin* pinWW;
Mqtt* mqttClient;
LightInfo lightInfo;
DeviceInfo deviceInfo;
LightType lightType = onOff; // Default light type