rename secondary entities and add support for configuration type entity

This commit is contained in:
Nicu Hodos 2024-05-29 16:08:05 +02:00
parent ce21dedcd5
commit b4daba4cb2
2 changed files with 14 additions and 9 deletions

View File

@ -25,8 +25,8 @@ namespace OilTank {
return Builder<TemperatureSensor>::instance(id) return Builder<TemperatureSensor>::instance(id)
.asDevice(device) .asDevice(device)
.withValueTemplate("{{ value_json.sensor.temperature }}") .withValueTemplate("{{ value_json.sensor.temperature }}")
.asDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) .addDiagnostic(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 BatterySensor{id, "Battery level", "{{ ((states('sensor.servers_room_battery_voltage')|float-2.5)|round(2)*100/2)|int }}"})
.build(); .build();
} }
@ -42,14 +42,14 @@ namespace OilTank {
.withDeviceClass("distance") .withDeviceClass("distance")
.withUnitMseasure("cm") .withUnitMseasure("cm")
.withValueTemplate("{{ value_json.sensor.value }}") .withValueTemplate("{{ value_json.sensor.value }}")
.asSecondary( .addSecondary(
Builder<Sensor>::instance(new Sensor{ "Level", id }) Builder<Sensor>::instance(new Sensor{ "Level", id })
.withUnitMseasure("%") .withUnitMseasure("%")
.withValueTemplate("{{ 100 - ((value_json.sensor.value-7)|float*100/110)|round(2) }}") .withValueTemplate("{{ 100 - ((value_json.sensor.value-7)|float*100/110)|round(2) }}")
.build() .build()
) )
.asDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"}) .addDiagnostic(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 BatterySensor{id, "Battery level", "{{ ((states('sensor.oil_tank_battery_voltage')|float-3.6)|round(2)*100/1.6)|int }}"})
.build(); .build();
} }
} }

View File

@ -160,14 +160,19 @@ namespace Ha {
return *this; return *this;
} }
Builder& asSecondary(Component* c) { Builder& addSecondary(Component* c) {
c->mainDevice = &DeviceConfig::create(cmp->id); if (cmp->mainDevice) c->mainDevice = &DeviceConfig::create(cmp->mainDevice->id);
return *this; return *this;
} }
Builder& asDiagnostic(Component* c) { Builder& addDiagnostic(Component* c) {
c->entityCategory = "diagnostic"; c->entityCategory = "diagnostic";
return asSecondary(c); return addSecondary(c);
}
Builder& addConfiguration(Component* c) {
c->entityCategory = "config";
return addSecondary(c);
} }
Builder& asDevice(DeviceConfig* deviceConfig) { Builder& asDevice(DeviceConfig* deviceConfig) {