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