diff --git a/gateway/include/devices.h b/gateway/include/devices.h index 6238ffe..ef4c115 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -19,8 +19,8 @@ namespace OilTank { return Builder::instance(id) .asDevice(device) .withValueTemplate("{{ value_json.sensor.temperature }}") - .withDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) - .withDiagnostic(new BatterySensor{id, "Battery level", "{{ ((states('sensor.oil_tank_room_battery_voltage')|float-2.5)|round(2)*100/2)|int }}"}) + .asDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) + .asDiagnostic(new BatterySensor{id, "Battery level", "{{ ((states('sensor.oil_tank_room_battery_voltage')|float-2.5)|round(2)*100/2)|int }}"}) .build(); } @@ -36,14 +36,14 @@ namespace OilTank { .withDeviceClass("distance") .withUnitMseasure("cm") .withValueTemplate("{{ value_json.sensor.value }}") - .withSecondary( + .asSecondary( Builder::instance(new Sensor{ "Level", id }) .withUnitMseasure("%") .withValueTemplate("{{ 100 - ((value_json.sensor.value-7)|float*100/110)|round(2) }}") .build() ) - .withDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) - .withDiagnostic(new BatterySensor{id, "Battery level", "{{ ((states('sensor.oil_tank_battery_voltage')|float-3.6)|round(2)*100/1.6)|int }}"}) + .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 }}"}) .build(); } } diff --git a/gateway/include/ha.h b/gateway/include/ha.h index ef64de7..abec285 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -162,15 +162,14 @@ namespace Ha { return *this; } - Builder& withSecondary(Component* c) { + Builder& asSecondary(Component* c) { c->mainDevice = &DeviceConfig::create(cmp->id); return *this; } - Builder& withDiagnostic(Component* c) { + Builder& asDiagnostic(Component* c) { c->entityCategory = "diagnostic"; - c->mainDevice = &DeviceConfig::create(cmp->id); - return *this; + return asSecondary(c); } Builder& asDevice(DeviceConfig* deviceConfig) {