From 1ecd5bbdc6b41070143f3a3cce062c0e1d223612 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Thu, 9 May 2024 13:46:22 +0200 Subject: [PATCH] move area completely under DeviceConfig --- gateway/include/ha.h | 23 +++++++---------------- gateway/include/mqtt.h | 14 +++++++------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/gateway/include/ha.h b/gateway/include/ha.h index 7dca89a..570621c 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -19,7 +19,6 @@ namespace Ha { DeviceConfig() {} DeviceConfig(const char* id) : id(id) {} - DeviceConfig(const char* id, const char* name) : id(id), name(name) {} DeviceConfig(DeviceConfig& d) : id(d.id), name(d.name), model(d.model), manufacturer(d.manufacturer), area(d.area), parent(d.parent) {} void buildConfig(JsonDocument& jsonDoc) { @@ -33,6 +32,11 @@ namespace Ha { identifiers.add(id); } + DeviceConfig* withName(const char* value) { + name = value; + return this; + } + DeviceConfig* withModel(const char* value) { model = value; return this; @@ -96,21 +100,13 @@ namespace Ha { EntityConfig(const char* name, const char* id, const char* type) : Component(name, id, type) { } - T* withArea(const char* value) { - if (mainDevice) mainDevice->withArea(value); - return static_cast(this); - } - T* asDevice(DeviceConfig* deviceConfig) { mainDevice = deviceConfig; return static_cast(this); } - T* copyFromDevice(DeviceConfig* deviceConfig) { - mainDevice = new DeviceConfig{*deviceConfig}; - mainDevice->id = id; - mainDevice->name = name; - mainDevice->parent = deviceConfig->parent; + T* ofDevice(const char* id) { + mainDevice = new DeviceConfig{id}; return static_cast(this); } }; @@ -194,11 +190,6 @@ namespace Ha { jsonDoc["state_topic"] = stateTopic; jsonDoc["suggested_display_precision"] = 2; } - - Sensor* withDeviceName(const char* value) { - if (mainDevice) mainDevice->name = value; - return this; - } }; struct TemperatureSensor : Sensor { diff --git a/gateway/include/mqtt.h b/gateway/include/mqtt.h index 66c2187..96957cb 100644 --- a/gateway/include/mqtt.h +++ b/gateway/include/mqtt.h @@ -40,16 +40,16 @@ namespace Mqtt { }; Ha::Switch* switches[] = { - (new PollinSwitch{"Meeting sensor", "00001", 1})->withArea("Dining room")->withStateTopic(), - (new PollinSwitch{"Fire Tv", "00001", 2})->withArea("Living room")->withStateTopic(), - (new PollinSwitch{"Diningroom player", "00001", 3})->withArea("Dining room")->withStateTopic(), - (new PollinSwitch{"Train", "11111", 4})->withArea("Playroom")->withStateTopic(), - (new EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }})->withArea("Basement")->withStateTopic(), - (new EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }})->withArea("Basement")->withStateTopic() + (new PollinSwitch{"Meeting sensor", "00001", 1, "Dining room"})->withStateTopic(), + (new PollinSwitch{"Fire Tv", "00001", 2, "Living room"})->withStateTopic(), + (new PollinSwitch{"Diningroom player", "00001", 3, "Dining room"})->withStateTopic(), + (new PollinSwitch{"Train", "11111", 4, "Playroom"})->withStateTopic(), + (new EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }, "Basement"})->withStateTopic(), + (new EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }, "Basement"})->withStateTopic() }; Ha::Sensor* sensors[] = { - SensorBuilder::withVoltage((new Ha::TemperatureSensor{"4"})->copyFromDevice(atTinyDevice)->withDeviceName("Oil tank room")->withArea("Basement")), + OilTankRoomSensorBuilder::build("4"), OilSensorBuilder::build("7") };