diff --git a/homeassistant/components/youless/sensor.py b/homeassistant/components/youless/sensor.py index bc0f1ee873b..22fecfe1ec6 100644 --- a/homeassistant/components/youless/sensor.py +++ b/homeassistant/components/youless/sensor.py @@ -3,10 +3,22 @@ from __future__ import annotations from youless_api.youless_sensor import YoulessSensor -from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor import ( + STATE_CLASS_MEASUREMENT, + STATE_CLASS_TOTAL_INCREASING, + SensorEntity, +) from homeassistant.components.youless import DOMAIN from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_DEVICE, DEVICE_CLASS_POWER +from homeassistant.const import ( + CONF_DEVICE, + DEVICE_CLASS_ENERGY, + DEVICE_CLASS_GAS, + DEVICE_CLASS_POWER, + ENERGY_KILO_WATT_HOUR, + POWER_WATT, + VOLUME_CUBIC_METERS, +) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -95,6 +107,10 @@ class YoulessBaseSensor(CoordinatorEntity, SensorEntity): class GasSensor(YoulessBaseSensor): """The Youless gas sensor.""" + _attr_native_unit_of_measurement = VOLUME_CUBIC_METERS + _attr_device_class = DEVICE_CLASS_GAS + _attr_state_class = STATE_CLASS_TOTAL_INCREASING + def __init__(self, coordinator: DataUpdateCoordinator, device: str) -> None: """Instantiate a gas sensor.""" super().__init__(coordinator, device, "gas", "Gas meter", "gas") @@ -110,7 +126,9 @@ class GasSensor(YoulessBaseSensor): class CurrentPowerSensor(YoulessBaseSensor): """The current power usage sensor.""" + _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) -> None: """Instantiate the usage meter.""" @@ -127,7 +145,9 @@ class CurrentPowerSensor(YoulessBaseSensor): class DeliveryMeterSensor(YoulessBaseSensor): """The Youless delivery meter value sensor.""" - _attr_device_class = DEVICE_CLASS_POWER + _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_device_class = DEVICE_CLASS_ENERGY + _attr_state_class = STATE_CLASS_TOTAL_INCREASING def __init__( self, coordinator: DataUpdateCoordinator, device: str, dev_type: str @@ -151,7 +171,9 @@ class DeliveryMeterSensor(YoulessBaseSensor): class PowerMeterSensor(YoulessBaseSensor): """The Youless low meter value sensor.""" - _attr_device_class = DEVICE_CLASS_POWER + _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_device_class = DEVICE_CLASS_ENERGY + _attr_state_class = STATE_CLASS_TOTAL_INCREASING def __init__( self, coordinator: DataUpdateCoordinator, device: str, dev_type: str @@ -176,6 +198,7 @@ class PowerMeterSensor(YoulessBaseSensor): 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 def __init__(