From b4daba4cb29740440c1eee32077364ad1d2fb071 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 29 May 2024 16:08:05 +0200 Subject: [PATCH] rename secondary entities and add support for configuration type entity --- gateway/include/devices.h | 10 +++++----- gateway/include/ha.h | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/gateway/include/devices.h b/gateway/include/devices.h index bb686c5..e38b2cf 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -25,8 +25,8 @@ namespace OilTank { return Builder::instance(id) .asDevice(device) .withValueTemplate("{{ value_json.sensor.temperature }}") - .asDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) - .asDiagnostic(new BatterySensor{id, "Battery level", "{{ ((states('sensor.servers_room_battery_voltage')|float-2.5)|round(2)*100/2)|int }}"}) + .addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) + .addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((states('sensor.servers_room_battery_voltage')|float-2.5)|round(2)*100/2)|int }}"}) .build(); } @@ -42,14 +42,14 @@ namespace OilTank { .withDeviceClass("distance") .withUnitMseasure("cm") .withValueTemplate("{{ value_json.sensor.value }}") - .asSecondary( + .addSecondary( Builder::instance(new Sensor{ "Level", id }) .withUnitMseasure("%") .withValueTemplate("{{ 100 - ((value_json.sensor.value-7)|float*100/110)|round(2) }}") .build() ) - .asDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) - .asDiagnostic(new BatterySensor{id, "Battery level", "{{ ((states('sensor.oil_tank_battery_voltage')|float-3.6)|round(2)*100/1.6)|int }}"}) + .addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) + .addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((states('sensor.oil_tank_battery_voltage')|float-3.6)|round(2)*100/1.6)|int }}"}) .build(); } } diff --git a/gateway/include/ha.h b/gateway/include/ha.h index e37bbaa..c280d02 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -160,14 +160,19 @@ namespace Ha { return *this; } - Builder& asSecondary(Component* c) { - c->mainDevice = &DeviceConfig::create(cmp->id); + Builder& addSecondary(Component* c) { + if (cmp->mainDevice) c->mainDevice = &DeviceConfig::create(cmp->mainDevice->id); return *this; } - Builder& asDiagnostic(Component* c) { + Builder& addDiagnostic(Component* c) { c->entityCategory = "diagnostic"; - return asSecondary(c); + return addSecondary(c); + } + + Builder& addConfiguration(Component* c) { + c->entityCategory = "config"; + return addSecondary(c); } Builder& asDevice(DeviceConfig* deviceConfig) {