Add extra power meter for YouLess (#56528)

* #55535 added extra power meter

* Update sensor.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Roel van der Ark 2021-09-22 14:08:23 +02:00 committed by GitHub
parent 783cc1eacd
commit aab4b5ec06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,7 +47,7 @@ async def async_setup_entry(
DeliveryMeterSensor(coordinator, device, "low"),
DeliveryMeterSensor(coordinator, device, "high"),
ExtraMeterSensor(coordinator, device, "total"),
ExtraMeterSensor(coordinator, device, "usage"),
ExtraMeterPowerSensor(coordinator, device, "usage"),
]
)
@ -191,7 +191,8 @@ class ExtraMeterSensor(YoulessBaseSensor):
"""The Youless extra meter value sensor (s0)."""
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_device_class = DEVICE_CLASS_POWER
_attr_device_class = DEVICE_CLASS_ENERGY
_attr_state_class = STATE_CLASS_TOTAL_INCREASING
def __init__(
self, coordinator: DataUpdateCoordinator, device: str, dev_type: str
@ -210,3 +211,29 @@ class ExtraMeterSensor(YoulessBaseSensor):
return None
return getattr(self.coordinator.data.extra_meter, f"_{self._type}", None)
class ExtraMeterPowerSensor(YoulessBaseSensor):
"""The Youless extra meter power value sensor (s0)."""
_attr_native_unit_of_measurement = POWER_WATT
_attr_device_class = DEVICE_CLASS_POWER
_attr_state_class = STATE_CLASS_MEASUREMENT
def __init__(
self, coordinator: DataUpdateCoordinator, device: str, dev_type: str
) -> None:
"""Instantiate an extra meter power sensor."""
super().__init__(
coordinator, device, "extra", "Extra meter", f"extra_{dev_type}"
)
self._type = dev_type
self._attr_name = f"Extra {dev_type}"
@property
def get_sensor(self) -> YoulessSensor | None:
"""Get the sensor for providing the value."""
if self.coordinator.data.extra_meter is None:
return None
return getattr(self.coordinator.data.extra_meter, f"_{self._type}", None)