Fix type hints in zha platforms (#73745)

* Adjust binary_sensor

* Adjust device_action

* Adjust device_tracker

* Adjust fan

* Adjust lock

* Adjust siren
This commit is contained in:
epenet 2022-06-20 17:31:16 +02:00 committed by GitHub
parent 9a95649a22
commit f43cc18aa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 39 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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