From a14a8c4e432f44d928675140e7f5684e36453cf7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 15 Jan 2026 10:38:34 +0100 Subject: [PATCH] Mark last_reset and state_class type hints as compulsory in sensor platform (#160982) --- homeassistant/components/blebox/sensor.py | 4 +++- homeassistant/components/hue/v1/sensor_base.py | 2 +- homeassistant/components/utility_meter/sensor.py | 2 +- pylint/plugins/hass_enforce_type_hints.py | 3 +++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/blebox/sensor.py b/homeassistant/components/blebox/sensor.py index 5120a7a3c98..14cddf41e45 100644 --- a/homeassistant/components/blebox/sensor.py +++ b/homeassistant/components/blebox/sensor.py @@ -1,5 +1,7 @@ """BleBox sensor entities.""" +from datetime import datetime + import blebox_uniapi.sensor from homeassistant.components.sensor import ( @@ -146,7 +148,7 @@ class BleBoxSensorEntity(BleBoxEntity[blebox_uniapi.sensor.BaseSensor], SensorEn return self._feature.native_value @property - def last_reset(self): + def last_reset(self) -> datetime | None: """Return the time when the sensor was last reset, if implemented.""" native_implementation = getattr(self._feature, "last_reset", None) diff --git a/homeassistant/components/hue/v1/sensor_base.py b/homeassistant/components/hue/v1/sensor_base.py index fb8f3c572c1..0ea079992e0 100644 --- a/homeassistant/components/hue/v1/sensor_base.py +++ b/homeassistant/components/hue/v1/sensor_base.py @@ -181,7 +181,7 @@ class GenericHueSensor(GenericHueDevice, entity.Entity): # pylint: disable=hass ) @property - def state_class(self): + def state_class(self) -> SensorStateClass: """Return the state class of this entity, from STATE_CLASSES, if any.""" return SensorStateClass.MEASUREMENT diff --git a/homeassistant/components/utility_meter/sensor.py b/homeassistant/components/utility_meter/sensor.py index dd0e62b0dbd..071488dc68b 100644 --- a/homeassistant/components/utility_meter/sensor.py +++ b/homeassistant/components/utility_meter/sensor.py @@ -700,7 +700,7 @@ class UtilityMeterSensor(RestoreSensor): return None @property - def state_class(self): + def state_class(self) -> SensorStateClass: """Return the device class of the sensor.""" return ( SensorStateClass.TOTAL diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index b4f7a5a4a5a..a562ea69d68 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -700,6 +700,7 @@ _ENTITY_MATCH: list[TypeHintMatch] = [ TypeHintMatch( function_name="device_class", return_type=["str", None], + mandatory=True, ), TypeHintMatch( function_name="unit_of_measurement", @@ -2518,10 +2519,12 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { TypeHintMatch( function_name="state_class", return_type=["SensorStateClass", "str", None], + mandatory=True, ), TypeHintMatch( function_name="last_reset", return_type=["datetime", None], + mandatory=True, ), TypeHintMatch( function_name="native_value",