publish config from list of all components
This commit is contained in:
parent
86b2d75ea6
commit
6357ad1436
@ -15,6 +15,7 @@ struct PollinSwitch : Switch {
|
||||
PollinSwitch(const char* name, const char* group, const unsigned char channel)
|
||||
: Switch(name, Protocol_1::buildId(group, channel)), group(group), channel(channel) {
|
||||
asDevice((new DeviceConfig{id, name})->withManufacturer("Pollin")->withParent(gatewayConfig));
|
||||
addToMap();
|
||||
}
|
||||
|
||||
void onCommand(const char* msg) override {
|
||||
@ -37,6 +38,7 @@ struct EasyHomeSwitch : Switch {
|
||||
memcpy(&this->on[4], on, 4 * sizeof(unsigned long));
|
||||
memcpy(&this->off[4], off, 4 * sizeof(unsigned long));
|
||||
asDevice((new DeviceConfig{id, name})->withManufacturer("Intertek")->withModel("Easy Home")->withParent(gatewayConfig));
|
||||
addToMap();
|
||||
}
|
||||
|
||||
void onCommand(const char* msg) override {
|
||||
|
||||
@ -56,14 +56,14 @@ namespace Ha {
|
||||
};
|
||||
|
||||
struct Component {
|
||||
char* id = nullptr;
|
||||
const char* name;
|
||||
char* id;
|
||||
const char* type;
|
||||
char configTopic[TOPIC_SIZE];
|
||||
DeviceConfig* mainDevice;
|
||||
DeviceConfig* mainDevice = nullptr;
|
||||
static List<Component> components;
|
||||
|
||||
Component(const char* name, const char* id, const char* type) : name(name), id((char*)id), type(type) {
|
||||
Component(const char* name, const char* id, const char* type) : id((char*)id), name(name), type(type) {
|
||||
sprintf(configTopic, "homeassistant/%s/%s/%s/config", type, MAIN_DEVICE_ID, id);
|
||||
components.add(this);
|
||||
}
|
||||
@ -103,6 +103,7 @@ namespace Ha {
|
||||
char commandTopic[TOPIC_SIZE];
|
||||
|
||||
Command(const char* name, const char* id, const char* type) : EntityConfig<T>(name, id, type) {
|
||||
sprintf(commandTopic, "homeassistant/%s/%s/%s", type, MAIN_DEVICE_ID, id);
|
||||
}
|
||||
|
||||
void buildUniqueId(char* uniqueId) override {
|
||||
@ -118,10 +119,9 @@ namespace Ha {
|
||||
|
||||
typedef void (*onMessage)(const char* msg);
|
||||
struct Button : Command<Button> {
|
||||
static constexpr const char* type = "button";
|
||||
onMessage f;
|
||||
|
||||
Button(const char* name, const char* id, onMessage f) : Command(name, id, type), f(f) {}
|
||||
Button(const char* name, const char* id, onMessage f) : Command(name, id, "button"), f(f) {}
|
||||
|
||||
};
|
||||
|
||||
@ -136,13 +136,12 @@ namespace Ha {
|
||||
};
|
||||
|
||||
struct Switch : Command<Switch>, StateConfig<Switch> {
|
||||
static constexpr const char* type = "switch";
|
||||
const char* area;
|
||||
|
||||
virtual void onCommand(const char* msg){}
|
||||
virtual void addToMap(){}
|
||||
|
||||
Switch(const char* name, const char* id) : Command(name, id, type) {
|
||||
Switch(const char* name, const char* id) : Command(name, id, "switch") {
|
||||
sprintf(commandTopic, "homeassistant/%s/%s/%s/set", type, MAIN_DEVICE_ID, id);
|
||||
}
|
||||
|
||||
|
||||
@ -67,16 +67,9 @@ namespace Mqtt {
|
||||
}
|
||||
|
||||
void publishInit() {
|
||||
// for (Ha::Component* cmp : sensors) {
|
||||
// publishComponentConfig(*cmp);
|
||||
// }
|
||||
Ha::publisher = publish;
|
||||
for (Ha::Component* cmp : buttons) {
|
||||
publishComponentConfig(*cmp);
|
||||
}
|
||||
for (Ha::Switch* cmp : switches) {
|
||||
cmp->addToMap();
|
||||
publishComponentConfig(*cmp);
|
||||
for (List<Ha::Component>::Container* c = Ha::Component::components.first; c; c = c->next) {
|
||||
publishComponentConfig(*c->t);
|
||||
}
|
||||
ts.deleteTask(tPublishInit);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user