fix on/off all switches
This commit is contained in:
parent
aaeb0a85e6
commit
a9d66e29e3
@ -159,19 +159,19 @@ namespace Ha {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct EasyHomeSwitch : Switch {
|
struct EasyHomeSwitch : Switch {
|
||||||
unsigned long on[8] = {4972714, 4767530, 4537114, 4326554};
|
unsigned long on[8] = {4326554, 4537114, 4767530, 4972714};
|
||||||
unsigned long off[8] = {4483146, 4626810, 4819642, 4661562};
|
unsigned long off[8] = {4483146, 4626810, 4661562, 4819642};
|
||||||
|
|
||||||
EasyHomeSwitch(const char* name, const char* id, unsigned long on[4], unsigned long off[4], publisherFunc publisher)
|
EasyHomeSwitch(const char* name, const char* id, unsigned long on[4], unsigned long off[4], publisherFunc publisher)
|
||||||
: Switch(name, id, publisher) {
|
: Switch(name, id, publisher) {
|
||||||
memccpy(&this->on[4], on, 4, sizeof(unsigned long));
|
memcpy(&this->on[4], on, 4*sizeof(unsigned long));
|
||||||
memccpy(&this->off[4], off, 4, sizeof(unsigned long));
|
memcpy(&this->off[4], off, 4*sizeof(unsigned long));
|
||||||
sprintf(commandTopic, "homeassistant/%s/rc-gateway/%s/set", type, id);
|
sprintf(commandTopic, "homeassistant/%s/rc-gateway/%s/set", type, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCommand(const char* msg) override {
|
void onCommand(const char* msg) override {
|
||||||
mySwitch.setProtocol(4);
|
mySwitch.setProtocol(4);
|
||||||
String{ "ON" }.equals(msg) ? mySwitch.send(on[0], 24) : mySwitch.send(off[0], 24);
|
String{ "ON" }.equals(msg) ? mySwitch.send(on[4], 24) : mySwitch.send(off[4], 24);
|
||||||
publisher(stateTopic, msg);
|
publisher(stateTopic, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,15 +55,15 @@ namespace Mqtt {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ha::EasyHomeSwitch* otherSwitches[] = {
|
Ha::EasyHomeSwitch* otherSwitches[] = {
|
||||||
(Ha::Switch::Builder<Ha::EasyHomeSwitch>{new Ha::EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4819632, 4661552 }, (unsigned long[4]) { 4767520, 4537104, 4326544, 4972704 }, publish}})
|
(Ha::Switch::Builder<Ha::EasyHomeSwitch>{new Ha::EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }, publish}})
|
||||||
.withArea("Basement")->withStateTopic()->build(),
|
.withArea("Basement")->withStateTopic()->build(),
|
||||||
(Ha::Switch::Builder<Ha::EasyHomeSwitch>{new Ha::EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4661556, 4819636, 4626804, 4483140 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }, publish}})
|
(Ha::Switch::Builder<Ha::EasyHomeSwitch>{new Ha::EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }, publish}})
|
||||||
.withArea("Basement")->withStateTopic()->build()
|
.withArea("Basement")->withStateTopic()->build()
|
||||||
};
|
};
|
||||||
|
|
||||||
unordered_map<string, Ha::Switch*> mapSwitches;
|
unordered_map<string, Ha::Switch*> mapSwitches;
|
||||||
unordered_multimap<unsigned long, Ha::Switch*> onSwitches;
|
unordered_multimap<unsigned long, Ha::Switch*> onSwitches;
|
||||||
unordered_map<unsigned long, Ha::Switch*> offSwitches;
|
unordered_multimap<unsigned long, Ha::Switch*> offSwitches;
|
||||||
|
|
||||||
void publishComponentConfig(Ha::Component& component) {
|
void publishComponentConfig(Ha::Component& component) {
|
||||||
StaticJsonDocument<JSON_SIZE> jsonDoc;
|
StaticJsonDocument<JSON_SIZE> jsonDoc;
|
||||||
@ -87,8 +87,10 @@ namespace Mqtt {
|
|||||||
publishComponentConfig(*cmp);
|
publishComponentConfig(*cmp);
|
||||||
}
|
}
|
||||||
for (Ha::EasyHomeSwitch* cmp : otherSwitches) {
|
for (Ha::EasyHomeSwitch* cmp : otherSwitches) {
|
||||||
for (int i = 0; i < 4; i++) onSwitches.insert({cmp->on[i], cmp});
|
for (int i = 0; i < 8; i++) {
|
||||||
for (int i = 0; i < 4; i++) offSwitches.insert({cmp->off[i], cmp});
|
onSwitches.insert({cmp->on[i], cmp});
|
||||||
|
offSwitches.insert({cmp->off[i], cmp});
|
||||||
|
}
|
||||||
publishComponentConfig(*cmp);
|
publishComponentConfig(*cmp);
|
||||||
}
|
}
|
||||||
ts.deleteTask(tPublishInit);
|
ts.deleteTask(tPublishInit);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user