light info has unique id no

This commit is contained in:
2025-08-30 21:38:24 +02:00
parent 14041120cd
commit 3c018ebba5
2 changed files with 27 additions and 10 deletions

View File

@@ -16,8 +16,8 @@ const struct {
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, std::string uniqueId) Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, std::string uniqueId)
: pinR(pinR), pinG(pinG), pinB(pinB), pinCW(nullptr), pinWW(nullptr) { : pinR(pinR), pinG(pinG), pinB(pinB), pinCW(nullptr), pinWW(nullptr), lightInfo(uniqueId) {
lightInfo.uniqueId = uniqueId;
lightType = LightType::rgb; lightType = LightType::rgb;
uint8_t bits = pinR->getLedResolutionBits(); uint8_t bits = pinR->getLedResolutionBits();
maxPwm = (bits >= 1 && bits <= 31) ? ((1u << bits) - 1u) : 255u; maxPwm = (bits >= 1 && bits <= 31) ? ((1u << bits) - 1u) : 255u;
@@ -25,8 +25,7 @@ Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, std::string uniqueId)
} }
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, std::string uniqueId) 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) { : pinR(pinR), pinG(pinG), pinB(pinB), pinCW(pinCW), pinWW(pinWW), lightInfo(uniqueId) {
lightInfo.uniqueId = uniqueId;
lightType = LightType::rgbww; lightType = LightType::rgbww;
uint8_t bits = pinR->getLedResolutionBits(); uint8_t bits = pinR->getLedResolutionBits();
maxPwm = (bits >= 1 && bits <= 31) ? ((1u << bits) - 1u) : 255u; maxPwm = (bits >= 1 && bits <= 31) ? ((1u << bits) - 1u) : 255u;

View File

@@ -4,14 +4,32 @@
#include "pin.h" #include "pin.h"
struct LightInfo { struct LightInfo {
LightInfo() = default;
LightInfo(const std::string& id) {
uniqueId = id;
updateTopics();
}
void setUniqueId(const std::string& id) {
uniqueId = id;
updateTopics();
}
void updateTopics() {
discoveryTopic = discoveryTopicBase + uniqueId + "/config";
availabilityTopic = topicBase + uniqueId + "/availability";
stateTopic = topicBase + uniqueId + "/state";
jsonAttributesTopic = topicBase + uniqueId + "/attributes";
commandTopic = topicBase + uniqueId + "/state/set";
}
std::string uniqueId; std::string uniqueId;
const std::string name = "Smart RGB Light"; const std::string name = "Smart RGB Light";
const std::string discoveryTopic = "homeassistant/light/smart_rgb_light/light/config"; const std::string discoveryTopicBase = "homeassistant/light/";
const std::string availabilityTopic = "studiotj/smart-rgb/light/status"; std::string discoveryTopic = discoveryTopicBase + uniqueId + "/config";
const std::string stateTopic = "studiotj/smart-rgb/light/state"; const std::string topicBase = "studiotj/";
const std::string jsonAttributesTopic = "studiotj/smart-rgb/light/attributes"; std::string availabilityTopic = topicBase + uniqueId + "/availability";
const std::string stateValueTemplate = "{{ value_json.state }}"; std::string stateTopic = topicBase + uniqueId + "/state";
const std::string commandTopic = "studiotj/smart-rgb/light/state/set"; std::string jsonAttributesTopic = topicBase + uniqueId + "/attributes";
std::string stateValueTemplate = "{{ value_json.state }}";
std::string commandTopic = topicBase + uniqueId + "/state/set";
const std::string supportedColorModesValue = "['rgb', 'brightness']"; const std::string supportedColorModesValue = "['rgb', 'brightness']";
const std::string availabilityTemplate = "{{ value_json.availability }}"; const std::string availabilityTemplate = "{{ value_json.availability }}";
}; };