From 7e44a0710acfbf84e5492daaa32e4c060db9b3e7 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sat, 5 Oct 2024 11:02:47 +0200 Subject: [PATCH 1/5] make name optional for PollinSwitch --- gateway/include/devices.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gateway/include/devices.h b/gateway/include/devices.h index 33efd72..37ce2b2 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -58,7 +58,7 @@ struct PollinSwitch : Switch { const char* group; unsigned char channel; - PollinSwitch(const char* name, const char* group, const unsigned char channel, const char* area = nullptr) + PollinSwitch(const char* group, const unsigned char channel, const char* name = nullptr, const char* area = nullptr) : Switch(nullptr, [group, channel]{ // copy id from string into a new pointer, to avoid memory leaks string s = Protocol_1::buildId(group, channel); @@ -124,11 +124,11 @@ Command* commands[] = { .build(), new EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }, "Basement"}, new EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }, "Basement"}, - new PollinSwitch{"Meeting sensor", "00001", 1, "Dining room"}, - new PollinSwitch{"Fire Tv", "00001", 2, "Living room"}, - new PollinSwitch{"Diningroom player", "00001", 3, "Dining room"}, - new PollinSwitch{"Bedroom player", "00001", 4, "Bedroom"}, - new PollinSwitch{"Train", "11111", 4, "Playroom"} + new PollinSwitch{"00001", 1, "Meeting sensor", "Dining room"}, + new PollinSwitch{"00001", 2, "Fire Tv", "Living room"}, + new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"}, + new PollinSwitch{"00001", 4, "Bedroom player", "Bedroom"}, + new PollinSwitch{"11111", 4, "Train", "Playroom"} }; Sensor* sensors[] = { From e246158502a71bbf571346848fecca28450b51de Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sat, 5 Oct 2024 21:28:54 +0200 Subject: [PATCH 2/5] build a default name for Pollin switches --- gateway/include/devices.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gateway/include/devices.h b/gateway/include/devices.h index 37ce2b2..d552cbb 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -55,6 +55,7 @@ namespace OilTank { } struct PollinSwitch : Switch { + constexpr static const char* man = "Pollin"; const char* group; unsigned char channel; @@ -66,7 +67,8 @@ struct PollinSwitch : Switch { strcpy(uId, s.c_str()); return uId; }()), group(group), channel(channel) { - mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer("Pollin").withArea(area).withParent(gatewayDevice); + if (!name) name = (new string{string(man).append(" ").append(id)})->c_str(); + mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer(man).withArea(area).withParent(gatewayDevice); withStateTopic(); deviceClass = "outlet"; p1Switches.insert({ string(id), this }); @@ -127,7 +129,7 @@ Command* commands[] = { new PollinSwitch{"00001", 1, "Meeting sensor", "Dining room"}, new PollinSwitch{"00001", 2, "Fire Tv", "Living room"}, new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"}, - new PollinSwitch{"00001", 4, "Bedroom player", "Bedroom"}, + new PollinSwitch{"00001", 4}, new PollinSwitch{"11111", 4, "Train", "Playroom"} }; From 996683d43c3133177187e78d9b7da9509d8ef519 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sat, 5 Oct 2024 21:29:52 +0200 Subject: [PATCH 3/5] use string as a pointer to keep the reference to id --- gateway/include/devices.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gateway/include/devices.h b/gateway/include/devices.h index d552cbb..9d66ff3 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -62,10 +62,7 @@ struct PollinSwitch : Switch { PollinSwitch(const char* group, const unsigned char channel, const char* name = nullptr, const char* area = nullptr) : Switch(nullptr, [group, channel]{ // copy id from string into a new pointer, to avoid memory leaks - string s = Protocol_1::buildId(group, channel); - char* uId = new char[s.length() + 1]; - strcpy(uId, s.c_str()); - return uId; + return (new string{Protocol_1::buildId(group, channel)})->c_str(); }()), group(group), channel(channel) { if (!name) name = (new string{string(man).append(" ").append(id)})->c_str(); mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer(man).withArea(area).withParent(gatewayDevice); From 36f96bb9a1cb445230bfee8b2d9529024181d5f2 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sat, 5 Oct 2024 21:30:27 +0200 Subject: [PATCH 4/5] use generic name for easy_home_b switch --- gateway/include/devices.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/include/devices.h b/gateway/include/devices.h index 9d66ff3..924331b 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -122,7 +122,7 @@ Command* commands[] = { ) .build(), new EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }, "Basement"}, - new EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }, "Basement"}, + new EasyHomeSwitch{"Easy Home B", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }}, new PollinSwitch{"00001", 1, "Meeting sensor", "Dining room"}, new PollinSwitch{"00001", 2, "Fire Tv", "Living room"}, new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"}, From 247e0fbb3704c74514ace1787fbe8c11743e8b14 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 7 Oct 2024 09:13:45 +0200 Subject: [PATCH 5/5] generate default name for easy home switches --- gateway/include/devices.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gateway/include/devices.h b/gateway/include/devices.h index 924331b..f4977b8 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -82,10 +82,19 @@ struct EasyHomeSwitch : Switch { 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], const char* area = nullptr) - : Switch(nullptr, id) { + EasyHomeSwitch(const char remotePosition, unsigned long on[4], unsigned long off[4], 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(unsigned long)); memcpy(&this->off[4], off, 4 * sizeof(unsigned long)); + if (!name) { + auto n = new string("Easy Home "); + (*n) += remotePosition; + name = n->c_str(); + } mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer("Intertek").withModel("Easy Home").withArea(area).withParent(gatewayDevice); withStateTopic(); deviceClass = "outlet"; @@ -121,8 +130,8 @@ Command* commands[] = { .withParent(gatewayDevice) ) .build(), - new EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }, "Basement"}, - new EasyHomeSwitch{"Easy Home B", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }}, + new EasyHomeSwitch{'A', (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }, "FritzBox", "Basement"}, + new EasyHomeSwitch{'B', (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }}, new PollinSwitch{"00001", 1, "Meeting sensor", "Dining room"}, new PollinSwitch{"00001", 2, "Fire Tv", "Living room"}, new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"},