move area completely under DeviceConfig

This commit is contained in:
Nicu Hodos 2024-05-09 13:46:22 +02:00
parent d822e3438c
commit 1ecd5bbdc6
2 changed files with 14 additions and 23 deletions

View File

@ -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<T*>(this);
}
T* asDevice(DeviceConfig* deviceConfig) {
mainDevice = deviceConfig;
return static_cast<T*>(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<T*>(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 {

View File

@ -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")
};