diff --git a/gateway/include/devices.h b/gateway/include/devices.h index 33efd72..f4977b8 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -55,18 +55,17 @@ namespace OilTank { } struct PollinSwitch : Switch { + constexpr static const char* man = "Pollin"; 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); - 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) { - 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 }); @@ -83,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"; @@ -122,13 +130,13 @@ 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{"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 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"}, + new PollinSwitch{"00001", 4}, + new PollinSwitch{"11111", 4, "Train", "Playroom"} }; Sensor* sensors[] = {