EasyHomeSwitch: separate codes for all buttons because they common to all switches and thus the same across all class instances

This commit is contained in:
Nicu Hodos 2025-10-08 21:52:25 +02:00
parent ecac0a3d81
commit ccfa0f427a
2 changed files with 14 additions and 12 deletions

View File

@ -71,8 +71,8 @@ Command* commands[] = {
) )
.build(), .build(),
#endif #endif
new EasyHomeSwitch{'A', (uint32_t[4]) { 4483136, 4626800, 4661552, 4819632 }, (uint32_t[4]) { 4326544, 4537104, 4767520, 4972704 }, "KabelBox", "Basement"}, new EasyHomeSwitch{'A', array<uint32_t, 4>{ 4483136, 4626800, 4661552, 4819632 }, array<uint32_t, 4>{ 4326544, 4537104, 4767520, 4972704 }, "KabelBox", "Basement"},
new EasyHomeSwitch{'B', (uint32_t[4]) { 4483140, 4626804, 4661556, 4819636 }, (uint32_t[4]) { 4326548, 4537108, 4767524, 4972708 }}, new EasyHomeSwitch{'B', array<uint32_t, 4>{ 4483140, 4626804, 4661556, 4819636 }, array<uint32_t, 4>{ 4326548, 4537108, 4767524, 4972708 }},
new PollinSwitch{"00001", 1}, new PollinSwitch{"00001", 1},
new PollinSwitch{"00001", 2, "Fire Tv", "Living room"}, new PollinSwitch{"00001", 2, "Fire Tv", "Living room"},
new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"}, new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"},

View File

@ -41,17 +41,17 @@ struct PollinSwitch : Switch {
}; };
struct EasyHomeSwitch : Switch { struct EasyHomeSwitch : Switch {
uint32_t on[8] = { 4326554, 4537114, 4767530, 4972714, 0, 0, 0, 0 }; constexpr static const array<uint32_t, 4> onAll = { 4326554, 4537114, 4767530, 4972714 };
uint32_t off[8] = { 4483146, 4626810, 4661562, 4819642, 0, 0, 0, 0 }; constexpr static const array<uint32_t, 4> offAll = { 4483146, 4626810, 4661562, 4819642 };
array<uint32_t, 4> onButton;
array<uint32_t, 4> offButton;
EasyHomeSwitch(const char remotePosition, uint32_t on[4], uint32_t off[4], const char* name = nullptr, const char* area = nullptr) EasyHomeSwitch(const char remotePosition, array<uint32_t, 4> on, array<uint32_t, 4> off, const char* name = nullptr, const char* area = nullptr)
: Switch(nullptr, [remotePosition] { : Switch(nullptr, [remotePosition] {
auto uId = new string("easy_home_"); auto uId = new string("easy_home_");
(*uId) += tolower(remotePosition); (*uId) += tolower(remotePosition);
return uId->c_str(); return uId->c_str();
}()) { }()), onButton(on), offButton(off) {
memcpy(&this->on[4], on, 4 * sizeof(uint32_t)); // cppcheck-suppress [overlappingWriteFunction]
memcpy(&this->off[4], off, 4 * sizeof(uint32_t)); // cppcheck-suppress [overlappingWriteFunction]
if (!name) { if (!name) {
auto n = new string("Easy Home "); auto n = new string("Easy Home ");
(*n) += remotePosition; (*n) += remotePosition;
@ -60,15 +60,17 @@ struct EasyHomeSwitch : Switch {
mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer("Intertek").withModel("Easy Home").withArea(area).withParent(gatewayDevice); mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer("Intertek").withModel("Easy Home").withArea(area).withParent(gatewayDevice);
withStateTopic(); withStateTopic();
deviceClass = "outlet"; deviceClass = "outlet";
for (int i = 0; i < 8; i++) { for (int i = 0; i < 4; i++) {
onSwitches.insert({ this->on[i], this }); onSwitches.insert({ onAll[i], this });
offSwitches.insert({ this->off[i], this }); onSwitches.insert({ onButton[i], this });
offSwitches.insert({ offAll[i], this });
offSwitches.insert({ offButton[i], this });
} }
} }
void onCommand(const char* msg) override { void onCommand(const char* msg) override {
mySwitch.setProtocol(4); mySwitch.setProtocol(4);
strcmp("ON", msg) == 0 ? mySwitch.send(on[4], 24) : mySwitch.send(off[4], 24); strcmp("ON", msg) == 0 ? mySwitch.send(onButton[0], 24) : mySwitch.send(offButton[0], 24);
publisher(State::topic, msg); publisher(State::topic, msg);
} }
}; };