diff --git a/custom_components/bosch/sensor/energy.py b/custom_components/bosch/sensor/energy.py index 6e2c844..06eabb0 100644 --- a/custom_components/bosch/sensor/energy.py +++ b/custom_components/bosch/sensor/energy.py @@ -4,7 +4,7 @@ from datetime import timedelta, datetime from bosch_thermostat_client.const import UNITS from .statistic_helper import StatisticHelper -from homeassistant.components.sensor import SensorDeviceClass +from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, STATE_UNAVAILABLE, @@ -87,6 +87,8 @@ def __init__( super().__init__(name=sensor_attributes.get("name"), uuid=uuid, **kwargs) self._unit_of_measurement = sensor_attributes.get(UNITS) self._attr_device_class = sensor_attributes.get("deviceClass", SensorDeviceClass.ENERGY) + if self._attr_state_class and self._attr_device_class == SensorDeviceClass.TEMPERATURE: + self._attr_device_class = SensorStateClass.MEASUREMENT @property def device_name(self) -> str: diff --git a/custom_components/bosch/sensor/statistic_helper.py b/custom_components/bosch/sensor/statistic_helper.py index 0d350bc..4a47a2e 100644 --- a/custom_components/bosch/sensor/statistic_helper.py +++ b/custom_components/bosch/sensor/statistic_helper.py @@ -2,12 +2,10 @@ from __future__ import annotations import logging import asyncio -from typing import Any from datetime import datetime, timedelta from homeassistant.components.recorder.models import ( StatisticData, StatisticMetaData, - timestamp_to_datetime_or_none, datetime_to_timestamp_or_none, ) from sqlalchemy.exc import IntegrityError