extract StateConfig into a dedicated class
This commit is contained in:
parent
eace33902b
commit
e67ce3b33c
@ -75,9 +75,18 @@ namespace Ha {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Switch : Command {
|
template <class T>
|
||||||
static constexpr const char* type = "switch";
|
struct StateConfig {
|
||||||
char stateTopic[TOPIC_SIZE];
|
char stateTopic[TOPIC_SIZE];
|
||||||
|
|
||||||
|
T* withStateTopic() {
|
||||||
|
sprintf(stateTopic, "homeassistant/%s/rc-gateway/%s/state", ((T*)this)->type, ((T*)this)->id);
|
||||||
|
return (T*)this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Switch : Command, StateConfig<Switch> {
|
||||||
|
static constexpr const char* type = "switch";
|
||||||
const char* area;
|
const char* area;
|
||||||
|
|
||||||
virtual void onCommand(const char* msg){}
|
virtual void onCommand(const char* msg){}
|
||||||
@ -105,11 +114,6 @@ namespace Ha {
|
|||||||
if (stateTopic[0]) jsonDoc["state_topic"] = stateTopic;
|
if (stateTopic[0]) jsonDoc["state_topic"] = stateTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
Switch* withStateTopic() {
|
|
||||||
sprintf(stateTopic, "homeassistant/%s/rc-gateway/%s/state", type, id);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Switch* withArea(const char* area) {
|
Switch* withArea(const char* area) {
|
||||||
this->area = area;
|
this->area = area;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user