From 368694d6bfb3d96a83f6209754be5d4360bff1cd Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 29 Nov 2022 20:31:25 +0100 Subject: [PATCH] Collection of DeviceClass related typing fixes (#82931) --- .../components/command_line/binary_sensor.py | 5 ++-- .../components/fibaro/binary_sensor.py | 6 +++-- homeassistant/components/geniushub/sensor.py | 2 +- .../components/group/binary_sensor.py | 5 ++-- .../homematicip_cloud/binary_sensor.py | 24 +++++++++---------- .../components/homematicip_cloud/sensor.py | 16 ++++++------- homeassistant/components/huisbaasje/sensor.py | 10 +++++--- homeassistant/components/iaqualink/sensor.py | 2 +- homeassistant/components/neato/sensor.py | 2 +- .../components/nina/binary_sensor.py | 10 ++++---- .../components/simplisafe/binary_sensor.py | 2 +- .../components/switcher_kis/sensor.py | 4 ++-- homeassistant/components/vera/sensor.py | 2 +- 13 files changed, 49 insertions(+), 41 deletions(-) diff --git a/homeassistant/components/command_line/binary_sensor.py b/homeassistant/components/command_line/binary_sensor.py index b2c8b29478a..f4a3a29f29f 100644 --- a/homeassistant/components/command_line/binary_sensor.py +++ b/homeassistant/components/command_line/binary_sensor.py @@ -8,6 +8,7 @@ import voluptuous as vol from homeassistant.components.binary_sensor import ( DEVICE_CLASSES_SCHEMA, PLATFORM_SCHEMA, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.const import ( @@ -64,7 +65,7 @@ def setup_platform( command: str = config[CONF_COMMAND] payload_off: str = config[CONF_PAYLOAD_OFF] payload_on: str = config[CONF_PAYLOAD_ON] - device_class: str | None = config.get(CONF_DEVICE_CLASS) + device_class: BinarySensorDeviceClass | None = config.get(CONF_DEVICE_CLASS) value_template: Template | None = config.get(CONF_VALUE_TEMPLATE) command_timeout: int = config[CONF_COMMAND_TIMEOUT] unique_id: str | None = config.get(CONF_UNIQUE_ID) @@ -95,7 +96,7 @@ class CommandBinarySensor(BinarySensorEntity): self, data: CommandSensorData, name: str, - device_class: str | None, + device_class: BinarySensorDeviceClass | None, payload_on: str, payload_off: str, value_template: Template | None, diff --git a/homeassistant/components/fibaro/binary_sensor.py b/homeassistant/components/fibaro/binary_sensor.py index f9baa33c41f..7954334689d 100644 --- a/homeassistant/components/fibaro/binary_sensor.py +++ b/homeassistant/components/fibaro/binary_sensor.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Mapping import json -from typing import Any +from typing import Any, cast from homeassistant.components.binary_sensor import ( ENTITY_ID_FORMAT, @@ -69,7 +69,9 @@ class FibaroBinarySensor(FibaroDevice, BinarySensorEntity): elif fibaro_device.baseType in SENSOR_TYPES: self._fibaro_sensor_type = fibaro_device.baseType if self._fibaro_sensor_type: - self._attr_device_class = SENSOR_TYPES[self._fibaro_sensor_type][2] + self._attr_device_class = cast( + BinarySensorDeviceClass, SENSOR_TYPES[self._fibaro_sensor_type][2] + ) self._attr_icon = SENSOR_TYPES[self._fibaro_sensor_type][1] @property diff --git a/homeassistant/components/geniushub/sensor.py b/homeassistant/components/geniushub/sensor.py index 20acb533a2c..06237b6e8d5 100644 --- a/homeassistant/components/geniushub/sensor.py +++ b/homeassistant/components/geniushub/sensor.py @@ -81,7 +81,7 @@ class GeniusBattery(GeniusDevice, SensorEntity): return icon @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class of the sensor.""" return SensorDeviceClass.BATTERY diff --git a/homeassistant/components/group/binary_sensor.py b/homeassistant/components/group/binary_sensor.py index 473a5a5e885..815e3b76f0b 100644 --- a/homeassistant/components/group/binary_sensor.py +++ b/homeassistant/components/group/binary_sensor.py @@ -7,6 +7,7 @@ from homeassistant.components.binary_sensor import ( DEVICE_CLASSES_SCHEMA, DOMAIN as BINARY_SENSOR_DOMAIN, PLATFORM_SCHEMA, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.config_entries import ConfigEntry @@ -94,7 +95,7 @@ class BinarySensorGroup(GroupEntity, BinarySensorEntity): self, unique_id: str | None, name: str, - device_class: str | None, + device_class: BinarySensorDeviceClass | None, entity_ids: list[str], mode: str | None, ) -> None: @@ -149,6 +150,6 @@ class BinarySensorGroup(GroupEntity, BinarySensorEntity): self._attr_is_on = self.mode(state == STATE_ON for state in states) @property - def device_class(self) -> str | None: + def device_class(self) -> BinarySensorDeviceClass | None: """Return the sensor class of the binary sensor.""" return self._device_class diff --git a/homeassistant/components/homematicip_cloud/binary_sensor.py b/homeassistant/components/homematicip_cloud/binary_sensor.py index db35a5d3ee5..fb4bfdd637e 100644 --- a/homeassistant/components/homematicip_cloud/binary_sensor.py +++ b/homeassistant/components/homematicip_cloud/binary_sensor.py @@ -195,7 +195,7 @@ class HomematicipBaseActionSensor(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP base action sensor.""" @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.MOVING @@ -240,7 +240,7 @@ class HomematicipMultiContactInterface(HomematicipGenericEntity, BinarySensorEnt ) @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.OPENING @@ -274,7 +274,7 @@ class HomematicipShutterContact(HomematicipMultiContactInterface, BinarySensorEn self.has_additional_state = has_additional_state @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.DOOR @@ -295,7 +295,7 @@ class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP motion detector.""" @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.MOTION @@ -309,7 +309,7 @@ class HomematicipPresenceDetector(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP presence detector.""" @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.PRESENCE @@ -323,7 +323,7 @@ class HomematicipSmokeDetector(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP smoke detector.""" @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.SMOKE @@ -342,7 +342,7 @@ class HomematicipWaterDetector(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP water detector.""" @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.MOISTURE @@ -378,7 +378,7 @@ class HomematicipRainSensor(HomematicipGenericEntity, BinarySensorEntity): super().__init__(hap, device, "Raining") @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.MOISTURE @@ -396,7 +396,7 @@ class HomematicipSunshineSensor(HomematicipGenericEntity, BinarySensorEntity): super().__init__(hap, device, post="Sunshine") @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.LIGHT @@ -425,7 +425,7 @@ class HomematicipBatterySensor(HomematicipGenericEntity, BinarySensorEntity): super().__init__(hap, device, post="Battery") @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.BATTERY @@ -445,7 +445,7 @@ class HomematicipPluggableMainsFailureSurveillanceSensor( super().__init__(hap, device) @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.POWER @@ -464,7 +464,7 @@ class HomematicipSecurityZoneSensorGroup(HomematicipGenericEntity, BinarySensorE super().__init__(hap, device, post=post) @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass: """Return the class of this sensor.""" return BinarySensorDeviceClass.SAFETY diff --git a/homeassistant/components/homematicip_cloud/sensor.py b/homeassistant/components/homematicip_cloud/sensor.py index 9da0bb37ed4..fdf125dbfec 100644 --- a/homeassistant/components/homematicip_cloud/sensor.py +++ b/homeassistant/components/homematicip_cloud/sensor.py @@ -205,7 +205,7 @@ class HomematicipHumiditySensor(HomematicipGenericEntity, SensorEntity): super().__init__(hap, device, post="Humidity") @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class of the sensor.""" return SensorDeviceClass.HUMIDITY @@ -230,7 +230,7 @@ class HomematicipTemperatureSensor(HomematicipGenericEntity, SensorEntity): super().__init__(hap, device, post="Temperature") @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class of the sensor.""" return SensorDeviceClass.TEMPERATURE @@ -269,7 +269,7 @@ class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity): super().__init__(hap, device, post="Illuminance") @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class of the sensor.""" return SensorDeviceClass.ILLUMINANCE @@ -308,7 +308,7 @@ class HomematicipPowerSensor(HomematicipGenericEntity, SensorEntity): super().__init__(hap, device, post="Power") @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class of the sensor.""" return SensorDeviceClass.POWER @@ -333,7 +333,7 @@ class HomematicipEnergySensor(HomematicipGenericEntity, SensorEntity): super().__init__(hap, device, post="Energy") @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class of the sensor.""" return SensorDeviceClass.ENERGY @@ -411,7 +411,7 @@ class HomematicpTemperatureExternalSensorCh1(HomematicipGenericEntity, SensorEnt super().__init__(hap, device, post="Channel 1 Temperature") @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class of the sensor.""" return SensorDeviceClass.TEMPERATURE @@ -436,7 +436,7 @@ class HomematicpTemperatureExternalSensorCh2(HomematicipGenericEntity, SensorEnt super().__init__(hap, device, post="Channel 2 Temperature") @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class of the sensor.""" return SensorDeviceClass.TEMPERATURE @@ -461,7 +461,7 @@ class HomematicpTemperatureExternalSensorDelta(HomematicipGenericEntity, SensorE super().__init__(hap, device, post="Delta Temperature") @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class of the sensor.""" return SensorDeviceClass.TEMPERATURE diff --git a/homeassistant/components/huisbaasje/sensor.py b/homeassistant/components/huisbaasje/sensor.py index c963f366323..7c0060067c2 100644 --- a/homeassistant/components/huisbaasje/sensor.py +++ b/homeassistant/components/huisbaasje/sensor.py @@ -3,7 +3,11 @@ from __future__ import annotations import logging -from homeassistant.components.sensor import SensorEntity, SensorStateClass +from homeassistant.components.sensor import ( + SensorDeviceClass, + SensorEntity, + SensorStateClass, +) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ID, POWER_WATT from homeassistant.core import HomeAssistant @@ -42,7 +46,7 @@ class HuisbaasjeSensor(CoordinatorEntity, SensorEntity): user_id: str, name: str, source_type: str, - device_class: str | None = None, + device_class: SensorDeviceClass | None = None, sensor_type: str = SENSOR_TYPE_RATE, unit_of_measurement: str = POWER_WATT, icon: str = "mdi:lightning-bolt", @@ -72,7 +76,7 @@ class HuisbaasjeSensor(CoordinatorEntity, SensorEntity): return self._name @property - def device_class(self) -> str | None: + def device_class(self) -> SensorDeviceClass | None: """Return the device class of the sensor.""" return self._device_class diff --git a/homeassistant/components/iaqualink/sensor.py b/homeassistant/components/iaqualink/sensor.py index 1c567b04a7f..f1636a09c90 100644 --- a/homeassistant/components/iaqualink/sensor.py +++ b/homeassistant/components/iaqualink/sensor.py @@ -54,7 +54,7 @@ class HassAqualinkSensor(AqualinkEntity, SensorEntity): return float(self.dev.state) @property - def device_class(self) -> str | None: + def device_class(self) -> SensorDeviceClass | None: """Return the class of the sensor.""" if self.dev.name.endswith("_temp"): return SensorDeviceClass.TEMPERATURE diff --git a/homeassistant/components/neato/sensor.py b/homeassistant/components/neato/sensor.py index 2e0e7b56cd6..15a6c454263 100644 --- a/homeassistant/components/neato/sensor.py +++ b/homeassistant/components/neato/sensor.py @@ -79,7 +79,7 @@ class NeatoSensor(SensorEntity): return self._robot_serial @property - def device_class(self) -> str: + def device_class(self) -> SensorDeviceClass: """Return the device class.""" return SensorDeviceClass.BATTERY diff --git a/homeassistant/components/nina/binary_sensor.py b/homeassistant/components/nina/binary_sensor.py index 76280ab159e..bdc79c34d92 100644 --- a/homeassistant/components/nina/binary_sensor.py +++ b/homeassistant/components/nina/binary_sensor.py @@ -62,12 +62,12 @@ class NINAMessage(CoordinatorEntity[NINADataUpdateCoordinator], BinarySensorEnti """Initialize.""" super().__init__(coordinator) - self._region: str = region - self._warning_index: int = slot_id - 1 + self._region = region + self._warning_index = slot_id - 1 - self._attr_name: str = f"Warning: {region_name} {slot_id}" - self._attr_unique_id: str = f"{region}-{slot_id}" - self._attr_device_class: str = BinarySensorDeviceClass.SAFETY + self._attr_name = f"Warning: {region_name} {slot_id}" + self._attr_unique_id = f"{region}-{slot_id}" + self._attr_device_class = BinarySensorDeviceClass.SAFETY @property def is_on(self) -> bool: diff --git a/homeassistant/components/simplisafe/binary_sensor.py b/homeassistant/components/simplisafe/binary_sensor.py index 5ccbfb96afb..054bf0b702b 100644 --- a/homeassistant/components/simplisafe/binary_sensor.py +++ b/homeassistant/components/simplisafe/binary_sensor.py @@ -78,7 +78,7 @@ class TriggeredBinarySensor(SimpliSafeEntity, BinarySensorEntity): simplisafe: SimpliSafe, system: SystemV3, sensor: SensorV3, - device_class: str, + device_class: BinarySensorDeviceClass, ) -> None: """Initialize.""" super().__init__(simplisafe, system, device=sensor) diff --git a/homeassistant/components/switcher_kis/sensor.py b/homeassistant/components/switcher_kis/sensor.py index c8dced8663c..34a4de3e9d3 100644 --- a/homeassistant/components/switcher_kis/sensor.py +++ b/homeassistant/components/switcher_kis/sensor.py @@ -30,8 +30,8 @@ class AttributeDescription: name: str icon: str | None = None unit: str | None = None - device_class: str | None = None - state_class: str | None = None + device_class: SensorDeviceClass | None = None + state_class: SensorStateClass | None = None default_enabled: bool = True diff --git a/homeassistant/components/vera/sensor.py b/homeassistant/components/vera/sensor.py index 8f541bf21b4..9f488fad33e 100644 --- a/homeassistant/components/vera/sensor.py +++ b/homeassistant/components/vera/sensor.py @@ -65,7 +65,7 @@ class VeraSensor(VeraDevice[veraApi.VeraSensor], SensorEntity): return self.current_value @property - def device_class(self) -> str | None: + def device_class(self) -> SensorDeviceClass | None: """Return the class of this entity.""" if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR: return SensorDeviceClass.TEMPERATURE