diff --git a/homeassistant/components/xiaomi_aqara/binary_sensor.py b/homeassistant/components/xiaomi_aqara/binary_sensor.py index c81d29729c9..b7a6d7ba935 100644 --- a/homeassistant/components/xiaomi_aqara/binary_sensor.py +++ b/homeassistant/components/xiaomi_aqara/binary_sensor.py @@ -1,6 +1,9 @@ """Support for Xiaomi aqara binary sensors.""" import logging +from typing import Any + +from xiaomi_gateway import XiaomiGateway from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, @@ -137,7 +140,15 @@ async def async_setup_entry( class XiaomiBinarySensor(XiaomiDevice, BinarySensorEntity): """Representation of a base XiaomiBinarySensor.""" - def __init__(self, device, name, xiaomi_hub, data_key, device_class, config_entry): + def __init__( + self, + device: dict[str, Any], + name: str, + xiaomi_hub: XiaomiGateway, + data_key: str, + device_class: BinarySensorDeviceClass | None, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiSmokeSensor.""" self._data_key = data_key self._attr_device_class = device_class @@ -152,11 +163,21 @@ class XiaomiBinarySensor(XiaomiDevice, BinarySensorEntity): class XiaomiNatgasSensor(XiaomiBinarySensor): """Representation of a XiaomiNatgasSensor.""" - def __init__(self, device, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiSmokeSensor.""" self._density = None super().__init__( - device, "Natgas Sensor", xiaomi_hub, "alarm", "gas", config_entry + device, + "Natgas Sensor", + xiaomi_hub, + "alarm", + BinarySensorDeviceClass.GAS, + config_entry, ) @property @@ -197,7 +218,13 @@ class XiaomiNatgasSensor(XiaomiBinarySensor): class XiaomiMotionSensor(XiaomiBinarySensor): """Representation of a XiaomiMotionSensor.""" - def __init__(self, device, hass, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + hass: HomeAssistant, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiMotionSensor.""" self._hass = hass self._no_motion_since = 0 @@ -207,7 +234,12 @@ class XiaomiMotionSensor(XiaomiBinarySensor): else: data_key = "motion_status" super().__init__( - device, "Motion Sensor", xiaomi_hub, data_key, "motion", config_entry + device, + "Motion Sensor", + xiaomi_hub, + data_key, + BinarySensorDeviceClass.MOTION, + config_entry, ) @property @@ -295,7 +327,12 @@ class XiaomiMotionSensor(XiaomiBinarySensor): class XiaomiDoorSensor(XiaomiBinarySensor, RestoreEntity): """Representation of a XiaomiDoorSensor.""" - def __init__(self, device, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiDoorSensor.""" self._open_since = 0 if "proto" not in device or int(device["proto"][0:1]) == 1: @@ -356,7 +393,12 @@ class XiaomiDoorSensor(XiaomiBinarySensor, RestoreEntity): class XiaomiWaterLeakSensor(XiaomiBinarySensor): """Representation of a XiaomiWaterLeakSensor.""" - def __init__(self, device, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiWaterLeakSensor.""" if "proto" not in device or int(device["proto"][0:1]) == 1: data_key = "status" @@ -402,11 +444,21 @@ class XiaomiWaterLeakSensor(XiaomiBinarySensor): class XiaomiSmokeSensor(XiaomiBinarySensor): """Representation of a XiaomiSmokeSensor.""" - def __init__(self, device, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiSmokeSensor.""" self._density = 0 super().__init__( - device, "Smoke Sensor", xiaomi_hub, "alarm", "smoke", config_entry + device, + "Smoke Sensor", + xiaomi_hub, + "alarm", + BinarySensorDeviceClass.SMOKE, + config_entry, ) @property @@ -446,7 +498,14 @@ class XiaomiSmokeSensor(XiaomiBinarySensor): class XiaomiVibration(XiaomiBinarySensor): """Representation of a Xiaomi Vibration Sensor.""" - def __init__(self, device, name, data_key, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + name: str, + data_key: str, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiVibration.""" self._last_action = None super().__init__(device, name, xiaomi_hub, data_key, None, config_entry) @@ -485,7 +544,15 @@ class XiaomiVibration(XiaomiBinarySensor): class XiaomiButton(XiaomiBinarySensor): """Representation of a Xiaomi Button.""" - def __init__(self, device, name, data_key, hass, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + name: str, + data_key: str, + hass: HomeAssistant, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiButton.""" self._hass = hass self._last_action = None @@ -545,7 +612,13 @@ class XiaomiButton(XiaomiBinarySensor): class XiaomiCube(XiaomiBinarySensor): """Representation of a Xiaomi Cube.""" - def __init__(self, device, hass, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + hass: HomeAssistant, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the Xiaomi Cube.""" self._hass = hass self._last_action = None diff --git a/homeassistant/components/xiaomi_aqara/cover.py b/homeassistant/components/xiaomi_aqara/cover.py index 82d5129ac5e..ebab3344250 100644 --- a/homeassistant/components/xiaomi_aqara/cover.py +++ b/homeassistant/components/xiaomi_aqara/cover.py @@ -2,6 +2,8 @@ from typing import Any +from xiaomi_gateway import XiaomiGateway + from homeassistant.components.cover import ATTR_POSITION, CoverEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -40,7 +42,14 @@ async def async_setup_entry( class XiaomiGenericCover(XiaomiDevice, CoverEntity): """Representation of a XiaomiGenericCover.""" - def __init__(self, device, name, data_key, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + name: str, + data_key: str, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiGenericCover.""" self._data_key = data_key self._pos = 0 diff --git a/homeassistant/components/xiaomi_aqara/entity.py b/homeassistant/components/xiaomi_aqara/entity.py index 11c20db8b0b..3f640b67516 100644 --- a/homeassistant/components/xiaomi_aqara/entity.py +++ b/homeassistant/components/xiaomi_aqara/entity.py @@ -2,8 +2,11 @@ from datetime import timedelta import logging -from typing import Any +from typing import TYPE_CHECKING, Any +from xiaomi_gateway import XiaomiGateway + +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_VOLTAGE, CONF_MAC from homeassistant.core import callback from homeassistant.helpers import device_registry as dr @@ -24,7 +27,13 @@ class XiaomiDevice(Entity): _attr_should_poll = False - def __init__(self, device, device_type, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + device_type: str, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the Xiaomi device.""" self._is_available = True self._sid = device["sid"] @@ -50,6 +59,8 @@ class XiaomiDevice(Entity): if config_entry.data[CONF_MAC] == format_mac(self._sid): # this entity belongs to the gateway itself self._is_gateway = True + if TYPE_CHECKING: + assert config_entry.unique_id self._device_id = config_entry.unique_id else: # this entity is connected through zigbee @@ -86,6 +97,8 @@ class XiaomiDevice(Entity): model=self._model, ) else: + if TYPE_CHECKING: + assert self._gateway_id is not None device_info = DeviceInfo( connections={(dr.CONNECTION_ZIGBEE, self._device_id)}, identifiers={(DOMAIN, self._device_id)}, diff --git a/homeassistant/components/xiaomi_aqara/light.py b/homeassistant/components/xiaomi_aqara/light.py index 88b138eebfa..47b9e5a6730 100644 --- a/homeassistant/components/xiaomi_aqara/light.py +++ b/homeassistant/components/xiaomi_aqara/light.py @@ -5,6 +5,8 @@ import logging import struct from typing import Any +from xiaomi_gateway import XiaomiGateway + from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_HS_COLOR, @@ -45,7 +47,13 @@ class XiaomiGatewayLight(XiaomiDevice, LightEntity): _attr_color_mode = ColorMode.HS _attr_supported_color_modes = {ColorMode.HS} - def __init__(self, device, name, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + name: str, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiGatewayLight.""" self._data_key = "rgb" self._hs = (0, 0) diff --git a/homeassistant/components/xiaomi_aqara/lock.py b/homeassistant/components/xiaomi_aqara/lock.py index 16686983230..86d20a7024f 100644 --- a/homeassistant/components/xiaomi_aqara/lock.py +++ b/homeassistant/components/xiaomi_aqara/lock.py @@ -2,6 +2,10 @@ from __future__ import annotations +from typing import Any + +from xiaomi_gateway import XiaomiGateway + from homeassistant.components.lock import LockEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback @@ -38,7 +42,13 @@ async def async_setup_entry( class XiaomiAqaraLock(LockEntity, XiaomiDevice): """Representation of a XiaomiAqaraLock.""" - def __init__(self, device, name, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + name: str, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiAqaraLock.""" self._attr_changed_by = "0" self._verified_wrong_times = 0 diff --git a/homeassistant/components/xiaomi_aqara/sensor.py b/homeassistant/components/xiaomi_aqara/sensor.py index 1d686147d0c..2855bf14a3f 100644 --- a/homeassistant/components/xiaomi_aqara/sensor.py +++ b/homeassistant/components/xiaomi_aqara/sensor.py @@ -3,6 +3,9 @@ from __future__ import annotations import logging +from typing import Any + +from xiaomi_gateway import XiaomiGateway from homeassistant.components.sensor import ( SensorDeviceClass, @@ -164,7 +167,14 @@ async def async_setup_entry( class XiaomiSensor(XiaomiDevice, SensorEntity): """Representation of a XiaomiSensor.""" - def __init__(self, device, name, data_key, xiaomi_hub, config_entry): + def __init__( + self, + device: dict[str, Any], + name: str, + data_key: str, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiSensor.""" self._data_key = data_key self.entity_description = SENSOR_TYPES[data_key] diff --git a/homeassistant/components/xiaomi_aqara/switch.py b/homeassistant/components/xiaomi_aqara/switch.py index 1ac15fe148c..e9e2c92314e 100644 --- a/homeassistant/components/xiaomi_aqara/switch.py +++ b/homeassistant/components/xiaomi_aqara/switch.py @@ -3,6 +3,8 @@ import logging from typing import Any +from xiaomi_gateway import XiaomiGateway + from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -138,13 +140,13 @@ class XiaomiGenericSwitch(XiaomiDevice, SwitchEntity): def __init__( self, - device, - name, - data_key, - supports_power_consumption, - xiaomi_hub, - config_entry, - ): + device: dict[str, Any], + name: str, + data_key: str, + supports_power_consumption: bool, + xiaomi_hub: XiaomiGateway, + config_entry: ConfigEntry, + ) -> None: """Initialize the XiaomiPlug.""" self._data_key = data_key self._in_use = None