From f43cc18aa305c9014e9892006497fceb6b851241 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 20 Jun 2022 17:31:16 +0200 Subject: [PATCH] Fix type hints in zha platforms (#73745) * Adjust binary_sensor * Adjust device_action * Adjust device_tracker * Adjust fan * Adjust lock * Adjust siren --- homeassistant/components/zha/binary_sensor.py | 6 ++++-- homeassistant/components/zha/device_action.py | 6 ++++-- homeassistant/components/zha/device_tracker.py | 6 +++--- homeassistant/components/zha/fan.py | 2 +- homeassistant/components/zha/lock.py | 8 ++++---- homeassistant/components/zha/siren.py | 7 ++++--- mypy.ini | 18 ------------------ script/hassfest/mypy_config.py | 6 ------ 8 files changed, 20 insertions(+), 39 deletions(-) diff --git a/homeassistant/components/zha/binary_sensor.py b/homeassistant/components/zha/binary_sensor.py index 954c60fa895..8130e7d5f98 100644 --- a/homeassistant/components/zha/binary_sensor.py +++ b/homeassistant/components/zha/binary_sensor.py @@ -1,4 +1,6 @@ """Binary sensors on Zigbee Home Automation networks.""" +from __future__ import annotations + import functools from homeassistant.components.binary_sensor import ( @@ -60,7 +62,7 @@ async def async_setup_entry( class BinarySensor(ZhaEntity, BinarySensorEntity): """ZHA BinarySensor.""" - SENSOR_ATTR = None + SENSOR_ATTR: str | None = None def __init__(self, unique_id, zha_device, channels, **kwargs): """Initialize the ZHA binary sensor.""" @@ -161,7 +163,7 @@ class IASZone(BinarySensor): SENSOR_ATTR = "zone_status" @property - def device_class(self) -> str: + def device_class(self) -> BinarySensorDeviceClass | None: """Return device class from component DEVICE_CLASSES.""" return CLASS_MAPPING.get(self._channel.cluster.get("zone_type")) diff --git a/homeassistant/components/zha/device_action.py b/homeassistant/components/zha/device_action.py index 049ffbd40f3..3ee8694b09c 100644 --- a/homeassistant/components/zha/device_action.py +++ b/homeassistant/components/zha/device_action.py @@ -1,6 +1,8 @@ """Provides device actions for ZHA devices.""" from __future__ import annotations +from typing import Any + import voluptuous as vol from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_TYPE @@ -82,9 +84,9 @@ async def async_get_actions( async def _execute_service_based_action( hass: HomeAssistant, - config: ACTION_SCHEMA, + config: dict[str, Any], variables: TemplateVarsType, - context: Context, + context: Context | None, ) -> None: action_type = config[CONF_TYPE] service_name = SERVICE_NAMES[action_type] diff --git a/homeassistant/components/zha/device_tracker.py b/homeassistant/components/zha/device_tracker.py index c08491ab782..cf4a830f4da 100644 --- a/homeassistant/components/zha/device_tracker.py +++ b/homeassistant/components/zha/device_tracker.py @@ -107,10 +107,10 @@ class ZHADeviceScannerEntity(ScannerEntity, ZhaEntity): """ return self._battery_level - @property + @property # type: ignore[misc] def device_info( # pylint: disable=overridden-final-method self, - ) -> DeviceInfo | None: + ) -> DeviceInfo: """Return device info.""" # We opt ZHA device tracker back into overriding this method because # it doesn't track IP-based devices. @@ -118,7 +118,7 @@ class ZHADeviceScannerEntity(ScannerEntity, ZhaEntity): return super(ZhaEntity, self).device_info @property - def unique_id(self) -> str | None: + def unique_id(self) -> str: """Return unique ID.""" # Call Super because ScannerEntity overrode it. return super(ZhaEntity, self).unique_id diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index 1c2f52c6038..a4b9baa5f0a 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -97,7 +97,7 @@ class BaseFan(FanEntity): """Turn the entity off.""" await self.async_set_percentage(0) - async def async_set_percentage(self, percentage: int | None) -> None: + async def async_set_percentage(self, percentage: int) -> None: """Set the speed percenage of the fan.""" fan_mode = math.ceil(percentage_to_ranged_value(SPEED_RANGE, percentage)) await self._async_set_fan_mode(fan_mode) diff --git a/homeassistant/components/zha/lock.py b/homeassistant/components/zha/lock.py index b26d7087b75..449fd1089eb 100644 --- a/homeassistant/components/zha/lock.py +++ b/homeassistant/components/zha/lock.py @@ -53,7 +53,7 @@ async def async_setup_entry( platform = entity_platform.async_get_current_platform() - platform.async_register_entity_service( # type: ignore + platform.async_register_entity_service( SERVICE_SET_LOCK_USER_CODE, { vol.Required("code_slot"): vol.Coerce(int), @@ -62,7 +62,7 @@ async def async_setup_entry( "async_set_lock_user_code", ) - platform.async_register_entity_service( # type: ignore + platform.async_register_entity_service( SERVICE_ENABLE_LOCK_USER_CODE, { vol.Required("code_slot"): vol.Coerce(int), @@ -70,7 +70,7 @@ async def async_setup_entry( "async_enable_lock_user_code", ) - platform.async_register_entity_service( # type: ignore + platform.async_register_entity_service( SERVICE_DISABLE_LOCK_USER_CODE, { vol.Required("code_slot"): vol.Coerce(int), @@ -78,7 +78,7 @@ async def async_setup_entry( "async_disable_lock_user_code", ) - platform.async_register_entity_service( # type: ignore + platform.async_register_entity_service( SERVICE_CLEAR_LOCK_USER_CODE, { vol.Required("code_slot"): vol.Coerce(int), diff --git a/homeassistant/components/zha/siren.py b/homeassistant/components/zha/siren.py index b509f9585db..66cd2bf4002 100644 --- a/homeassistant/components/zha/siren.py +++ b/homeassistant/components/zha/siren.py @@ -1,8 +1,9 @@ """Support for ZHA sirens.""" from __future__ import annotations +from collections.abc import Callable import functools -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, cast from zigpy.zcl.clusters.security import IasWd as WD @@ -96,9 +97,9 @@ class ZHASiren(ZhaEntity, SirenEntity): WARNING_DEVICE_MODE_EMERGENCY_PANIC: "Emergency Panic", } super().__init__(unique_id, zha_device, channels, **kwargs) - self._channel: IasWd = channels[0] + self._channel: IasWd = cast(IasWd, channels[0]) self._attr_is_on: bool = False - self._off_listener = None + self._off_listener: Callable[[], None] | None = None async def async_turn_on(self, **kwargs: Any) -> None: """Turn on siren.""" diff --git a/mypy.ini b/mypy.ini index d5b5ca39183..27aa6653357 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2988,9 +2988,6 @@ ignore_errors = true [mypy-homeassistant.components.zha.api] ignore_errors = true -[mypy-homeassistant.components.zha.binary_sensor] -ignore_errors = true - [mypy-homeassistant.components.zha.button] ignore_errors = true @@ -3051,32 +3048,17 @@ ignore_errors = true [mypy-homeassistant.components.zha.cover] ignore_errors = true -[mypy-homeassistant.components.zha.device_action] -ignore_errors = true - -[mypy-homeassistant.components.zha.device_tracker] -ignore_errors = true - [mypy-homeassistant.components.zha.entity] ignore_errors = true -[mypy-homeassistant.components.zha.fan] -ignore_errors = true - [mypy-homeassistant.components.zha.light] ignore_errors = true -[mypy-homeassistant.components.zha.lock] -ignore_errors = true - [mypy-homeassistant.components.zha.select] ignore_errors = true [mypy-homeassistant.components.zha.sensor] ignore_errors = true -[mypy-homeassistant.components.zha.siren] -ignore_errors = true - [mypy-homeassistant.components.zha.switch] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index bb46ba39212..a16faf7f34e 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -145,7 +145,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.xiaomi_miio.sensor", "homeassistant.components.xiaomi_miio.switch", "homeassistant.components.zha.api", - "homeassistant.components.zha.binary_sensor", "homeassistant.components.zha.button", "homeassistant.components.zha.climate", "homeassistant.components.zha.core.channels.base", @@ -166,15 +165,10 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.zha.core.registries", "homeassistant.components.zha.core.store", "homeassistant.components.zha.cover", - "homeassistant.components.zha.device_action", - "homeassistant.components.zha.device_tracker", "homeassistant.components.zha.entity", - "homeassistant.components.zha.fan", "homeassistant.components.zha.light", - "homeassistant.components.zha.lock", "homeassistant.components.zha.select", "homeassistant.components.zha.sensor", - "homeassistant.components.zha.siren", "homeassistant.components.zha.switch", ]