From a9d66e29e3916d4535f28832ff3beadff00a6bd9 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Tue, 30 Apr 2024 21:17:33 +0200 Subject: [PATCH] fix on/off all switches --- gateway/include/ha.h | 10 +++++----- gateway/include/mqtt.h | 12 +++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/gateway/include/ha.h b/gateway/include/ha.h index 41d7694..2079534 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -159,19 +159,19 @@ namespace Ha { }; struct EasyHomeSwitch : Switch { - unsigned long on[8] = {4972714, 4767530, 4537114, 4326554}; - unsigned long off[8] = {4483146, 4626810, 4819642, 4661562}; + unsigned long on[8] = {4326554, 4537114, 4767530, 4972714}; + 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) : Switch(name, id, publisher) { - memccpy(&this->on[4], on, 4, sizeof(unsigned long)); - memccpy(&this->off[4], off, 4, sizeof(unsigned long)); + memcpy(&this->on[4], on, 4*sizeof(unsigned long)); + memcpy(&this->off[4], off, 4*sizeof(unsigned long)); sprintf(commandTopic, "homeassistant/%s/rc-gateway/%s/set", type, id); } void onCommand(const char* msg) override { 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); } diff --git a/gateway/include/mqtt.h b/gateway/include/mqtt.h index 4731fed..a70ef9c 100644 --- a/gateway/include/mqtt.h +++ b/gateway/include/mqtt.h @@ -55,15 +55,15 @@ namespace Mqtt { }; Ha::EasyHomeSwitch* otherSwitches[] = { - (Ha::Switch::Builder{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{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(), - (Ha::Switch::Builder{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{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() }; unordered_map mapSwitches; unordered_multimap onSwitches; - unordered_map offSwitches; + unordered_multimap offSwitches; void publishComponentConfig(Ha::Component& component) { StaticJsonDocument jsonDoc; @@ -87,8 +87,10 @@ namespace Mqtt { publishComponentConfig(*cmp); } for (Ha::EasyHomeSwitch* cmp : otherSwitches) { - for (int i = 0; i < 4; i++) onSwitches.insert({cmp->on[i], cmp}); - for (int i = 0; i < 4; i++) offSwitches.insert({cmp->off[i], cmp}); + for (int i = 0; i < 8; i++) { + onSwitches.insert({cmp->on[i], cmp}); + offSwitches.insert({cmp->off[i], cmp}); + } publishComponentConfig(*cmp); } ts.deleteTask(tPublishInit);