Collection of DeviceClass related typing fixes (#82931)

This commit is contained in:
Franck Nijhof 2022-11-29 20:31:25 +01:00 committed by GitHub
parent 2785b2b52f
commit 368694d6bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 49 additions and 41 deletions

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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