diff --git a/homeassistant/components/concord232/binary_sensor.py b/homeassistant/components/concord232/binary_sensor.py index a60cf31a646..4eee5bd2d47 100644 --- a/homeassistant/components/concord232/binary_sensor.py +++ b/homeassistant/components/concord232/binary_sensor.py @@ -119,7 +119,7 @@ class Concord232ZoneSensor(BinarySensorEntity): self._zone_type = zone_type @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor, from DEVICE_CLASSES.""" return self._zone_type diff --git a/homeassistant/components/digital_ocean/binary_sensor.py b/homeassistant/components/digital_ocean/binary_sensor.py index f0bb6eba049..b0041f5220b 100644 --- a/homeassistant/components/digital_ocean/binary_sensor.py +++ b/homeassistant/components/digital_ocean/binary_sensor.py @@ -84,7 +84,7 @@ class DigitalOceanBinarySensor(BinarySensorEntity): return self.data.status == "active" @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.MOVING diff --git a/homeassistant/components/egardia/binary_sensor.py b/homeassistant/components/egardia/binary_sensor.py index 53505f58d3b..8124b5516f8 100644 --- a/homeassistant/components/egardia/binary_sensor.py +++ b/homeassistant/components/egardia/binary_sensor.py @@ -75,6 +75,6 @@ class EgardiaBinarySensor(BinarySensorEntity): return self._state == STATE_ON @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | None: """Return the device class.""" return self._device_class diff --git a/homeassistant/components/envisalink/binary_sensor.py b/homeassistant/components/envisalink/binary_sensor.py index 6c4e2b528e9..4b548ddb572 100644 --- a/homeassistant/components/envisalink/binary_sensor.py +++ b/homeassistant/components/envisalink/binary_sensor.py @@ -5,7 +5,10 @@ from __future__ import annotations import datetime import logging -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + BinarySensorDeviceClass, + BinarySensorEntity, +) from homeassistant.const import ATTR_LAST_TRIP_TIME from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -102,7 +105,7 @@ class EnvisalinkBinarySensor(EnvisalinkEntity, BinarySensorEntity): return self._info["status"]["open"] @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor, from DEVICE_CLASSES.""" return self._zone_type diff --git a/homeassistant/components/homematic/binary_sensor.py b/homeassistant/components/homematic/binary_sensor.py index 0d94c2bb78b..4d8b4178f54 100644 --- a/homeassistant/components/homematic/binary_sensor.py +++ b/homeassistant/components/homematic/binary_sensor.py @@ -66,7 +66,7 @@ class HMBinarySensor(HMDevice, BinarySensorEntity): return bool(self._hm_get_state()) @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | None: """Return the class of this sensor from DEVICE_CLASSES.""" # If state is MOTION (Only RemoteMotion working) if self._state == "MOTION": diff --git a/homeassistant/components/ness_alarm/binary_sensor.py b/homeassistant/components/ness_alarm/binary_sensor.py index bb0fa38ef72..8ea12142043 100644 --- a/homeassistant/components/ness_alarm/binary_sensor.py +++ b/homeassistant/components/ness_alarm/binary_sensor.py @@ -2,7 +2,10 @@ from __future__ import annotations -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + BinarySensorDeviceClass, + BinarySensorEntity, +) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -75,7 +78,7 @@ class NessZoneBinarySensor(BinarySensorEntity): return self._state == 1 @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor, from DEVICE_CLASSES.""" return self._type diff --git a/homeassistant/components/nx584/binary_sensor.py b/homeassistant/components/nx584/binary_sensor.py index 69e2f626049..7d0439fbf0c 100644 --- a/homeassistant/components/nx584/binary_sensor.py +++ b/homeassistant/components/nx584/binary_sensor.py @@ -96,7 +96,7 @@ class NX584ZoneSensor(BinarySensorEntity): self._zone_type = zone_type @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor, from DEVICE_CLASSES.""" return self._zone_type diff --git a/homeassistant/components/qwikswitch/binary_sensor.py b/homeassistant/components/qwikswitch/binary_sensor.py index bbe8d309e50..5f00631f0e4 100644 --- a/homeassistant/components/qwikswitch/binary_sensor.py +++ b/homeassistant/components/qwikswitch/binary_sensor.py @@ -6,7 +6,10 @@ import logging from pyqwikswitch.qwikswitch import SENSORS -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + BinarySensorDeviceClass, + BinarySensorEntity, +) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -76,6 +79,6 @@ class QSBinarySensor(QSEntity, BinarySensorEntity): return f"qs{self.qsid}:{self.channel}" @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return self._class diff --git a/homeassistant/components/w800rf32/binary_sensor.py b/homeassistant/components/w800rf32/binary_sensor.py index 06e9e0dfdac..11e4d1193c3 100644 --- a/homeassistant/components/w800rf32/binary_sensor.py +++ b/homeassistant/components/w800rf32/binary_sensor.py @@ -10,6 +10,7 @@ import W800rf32 as w800 from homeassistant.components.binary_sensor import ( DEVICE_CLASSES_SCHEMA, PLATFORM_SCHEMA as BINARY_SENSOR_PLATFORM_SCHEMA, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.const import CONF_DEVICE_CLASS, CONF_DEVICES, CONF_NAME @@ -98,7 +99,7 @@ class W800rf32BinarySensor(BinarySensorEntity): return self._name @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | None: """Return the sensor class.""" return self._device_class diff --git a/homeassistant/components/wirelesstag/binary_sensor.py b/homeassistant/components/wirelesstag/binary_sensor.py index 8a0957e16e3..6094c195272 100644 --- a/homeassistant/components/wirelesstag/binary_sensor.py +++ b/homeassistant/components/wirelesstag/binary_sensor.py @@ -6,6 +6,7 @@ import voluptuous as vol from homeassistant.components.binary_sensor import ( PLATFORM_SCHEMA as BINARY_SENSOR_PLATFORM_SCHEMA, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.const import CONF_MONITORED_CONDITIONS, STATE_OFF, STATE_ON, Platform @@ -124,7 +125,7 @@ class WirelessTagBinarySensor(WirelessTagBaseSensor, BinarySensorEntity): return self._state == STATE_ON @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass: """Return the class of the binary sensor.""" return self._sensor_type diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 923b2d013bf..b4f7a5a4a5a 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -931,6 +931,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { TypeHintMatch( function_name="device_class", return_type=["BinarySensorDeviceClass", None], + mandatory=True, ), TypeHintMatch( function_name="is_on",