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:
parent
ecac0a3d81
commit
ccfa0f427a
@ -71,8 +71,8 @@ Command* commands[] = {
|
||||
)
|
||||
.build(),
|
||||
#endif
|
||||
new EasyHomeSwitch{'A', (uint32_t[4]) { 4483136, 4626800, 4661552, 4819632 }, (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{'A', array<uint32_t, 4>{ 4483136, 4626800, 4661552, 4819632 }, array<uint32_t, 4>{ 4326544, 4537104, 4767520, 4972704 }, "KabelBox", "Basement"},
|
||||
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", 2, "Fire Tv", "Living room"},
|
||||
new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"},
|
||||
|
||||
@ -41,17 +41,17 @@ struct PollinSwitch : Switch {
|
||||
};
|
||||
|
||||
struct EasyHomeSwitch : Switch {
|
||||
uint32_t on[8] = { 4326554, 4537114, 4767530, 4972714, 0, 0, 0, 0 };
|
||||
uint32_t off[8] = { 4483146, 4626810, 4661562, 4819642, 0, 0, 0, 0 };
|
||||
constexpr static const array<uint32_t, 4> onAll = { 4326554, 4537114, 4767530, 4972714 };
|
||||
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] {
|
||||
auto uId = new string("easy_home_");
|
||||
(*uId) += tolower(remotePosition);
|
||||
return uId->c_str();
|
||||
}()) {
|
||||
memcpy(&this->on[4], on, 4 * sizeof(uint32_t)); // cppcheck-suppress [overlappingWriteFunction]
|
||||
memcpy(&this->off[4], off, 4 * sizeof(uint32_t)); // cppcheck-suppress [overlappingWriteFunction]
|
||||
}()), onButton(on), offButton(off) {
|
||||
if (!name) {
|
||||
auto n = new string("Easy Home ");
|
||||
(*n) += remotePosition;
|
||||
@ -60,15 +60,17 @@ struct EasyHomeSwitch : Switch {
|
||||
mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer("Intertek").withModel("Easy Home").withArea(area).withParent(gatewayDevice);
|
||||
withStateTopic();
|
||||
deviceClass = "outlet";
|
||||
for (int i = 0; i < 8; i++) {
|
||||
onSwitches.insert({ this->on[i], this });
|
||||
offSwitches.insert({ this->off[i], this });
|
||||
for (int i = 0; i < 4; i++) {
|
||||
onSwitches.insert({ onAll[i], this });
|
||||
onSwitches.insert({ onButton[i], this });
|
||||
offSwitches.insert({ offAll[i], this });
|
||||
offSwitches.insert({ offButton[i], this });
|
||||
}
|
||||
}
|
||||
|
||||
void onCommand(const char* msg) override {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user