diff --git a/homeassistant/components/ovo_energy/sensor.py b/homeassistant/components/ovo_energy/sensor.py index 7615a7011d3..f678caf02b0 100644 --- a/homeassistant/components/ovo_energy/sensor.py +++ b/homeassistant/components/ovo_energy/sensor.py @@ -1,4 +1,6 @@ """Support for OVO Energy sensors.""" +from __future__ import annotations + from datetime import timedelta from ovoenergy import OVODailyUsage @@ -6,8 +8,10 @@ from ovoenergy.ovoenergy import OVOEnergy from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry +from homeassistant.const import DEVICE_CLASS_ENERGY, DEVICE_CLASS_MONETARY from homeassistant.core import HomeAssistant from homeassistant.helpers.update_coordinator import DataUpdateCoordinator +from homeassistant.util.dt import utc_from_timestamp from . import OVOEnergyDeviceEntity from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN @@ -57,6 +61,9 @@ async def async_setup_entry( class OVOEnergySensor(OVOEnergyDeviceEntity, SensorEntity): """Defines a OVO Energy sensor.""" + _attr_last_reset = utc_from_timestamp(0) + _attr_state_class = "measurement" + def __init__( self, coordinator: DataUpdateCoordinator, @@ -64,15 +71,17 @@ class OVOEnergySensor(OVOEnergyDeviceEntity, SensorEntity): key: str, name: str, icon: str, - unit_of_measurement: str = "", + device_class: str | None, + unit_of_measurement: str | None, ) -> None: """Initialize OVO Energy sensor.""" + self._attr_device_class = device_class self._unit_of_measurement = unit_of_measurement super().__init__(coordinator, client, key, name, icon) @property - def unit_of_measurement(self) -> str: + def unit_of_measurement(self) -> str | None: """Return the unit this state is expressed in.""" return self._unit_of_measurement @@ -89,6 +98,7 @@ class OVOEnergyLastElectricityReading(OVOEnergySensor): f"{client.account_id}_last_electricity_reading", "OVO Last Electricity Reading", "mdi:flash", + DEVICE_CLASS_ENERGY, "kWh", ) @@ -124,6 +134,7 @@ class OVOEnergyLastGasReading(OVOEnergySensor): f"{DOMAIN}_{client.account_id}_last_gas_reading", "OVO Last Gas Reading", "mdi:gas-cylinder", + DEVICE_CLASS_ENERGY, "kWh", ) @@ -160,6 +171,7 @@ class OVOEnergyLastElectricityCost(OVOEnergySensor): f"{DOMAIN}_{client.account_id}_last_electricity_cost", "OVO Last Electricity Cost", "mdi:cash-multiple", + DEVICE_CLASS_MONETARY, currency, ) @@ -196,6 +208,7 @@ class OVOEnergyLastGasCost(OVOEnergySensor): f"{DOMAIN}_{client.account_id}_last_gas_cost", "OVO Last Gas Cost", "mdi:cash-multiple", + DEVICE_CLASS_MONETARY, currency, )