1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 17:49:37 +01:00

Mark device_class type hints as compulsory in sensor platform (#160931)

This commit is contained in:
epenet
2026-01-14 15:46:40 +01:00
committed by GitHub
parent 4dbab23ada
commit 77dd4189b1
5 changed files with 6 additions and 5 deletions
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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
@@ -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
@@ -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
@@ -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",