diff --git a/homeassistant/components/ebusd/sensor.py b/homeassistant/components/ebusd/sensor.py index ccd04be585e..0db0334f94f 100644 --- a/homeassistant/components/ebusd/sensor.py +++ b/homeassistant/components/ebusd/sensor.py @@ -5,7 +5,7 @@ from __future__ import annotations import datetime import logging -from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -96,7 +96,7 @@ class EbusdSensor(SensorEntity): return None @property - def device_class(self): + def device_class(self) -> SensorDeviceClass | None: """Return the class of this device, from component DEVICE_CLASSES.""" return self._device_class diff --git a/homeassistant/components/mfi/sensor.py b/homeassistant/components/mfi/sensor.py index f666e2d614a..6e792fe1609 100644 --- a/homeassistant/components/mfi/sensor.py +++ b/homeassistant/components/mfi/sensor.py @@ -116,7 +116,7 @@ class MfiSensor(SensorEntity): return round(self._port.value, digits) @property - def device_class(self): + def device_class(self) -> SensorDeviceClass | None: """Return the device class of the sensor.""" try: tag = self._port.tag diff --git a/homeassistant/components/oasa_telematics/sensor.py b/homeassistant/components/oasa_telematics/sensor.py index ddf4942ef25..a1ea90a7b16 100644 --- a/homeassistant/components/oasa_telematics/sensor.py +++ b/homeassistant/components/oasa_telematics/sensor.py @@ -84,7 +84,7 @@ class OASATelematicsSensor(SensorEntity): return self._name @property - def device_class(self): + def device_class(self) -> SensorDeviceClass: """Return the class of this sensor.""" return SensorDeviceClass.TIMESTAMP diff --git a/homeassistant/components/utility_meter/sensor.py b/homeassistant/components/utility_meter/sensor.py index 5ab476edecb..dd0e62b0dbd 100644 --- a/homeassistant/components/utility_meter/sensor.py +++ b/homeassistant/components/utility_meter/sensor.py @@ -688,7 +688,7 @@ class UtilityMeterSensor(RestoreSensor): self._collecting = None @property - def device_class(self): + def device_class(self) -> SensorDeviceClass | None: """Return the device class of the sensor.""" if self._input_device_class is not None: return self._input_device_class diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 5be59a0df2f..8e9bb6552a5 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -2508,6 +2508,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { TypeHintMatch( function_name="device_class", return_type=["SensorDeviceClass", None], + mandatory=True, ), TypeHintMatch( function_name="state_class",