From 06e45893aab613fbd221028af86d9d01a97c0bcf Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 20 Jun 2022 11:28:53 +0200 Subject: [PATCH] Remove invalid type definitions in zha (#73596) --- .../components/zha/alarm_control_panel.py | 9 ++++-- homeassistant/components/zha/api.py | 6 ++-- homeassistant/components/zha/button.py | 24 ++++++++------- .../components/zha/core/channels/base.py | 7 +++-- .../components/zha/core/channels/general.py | 7 +++-- .../zha/core/channels/manufacturerspecific.py | 8 ++++- .../components/zha/core/channels/security.py | 6 +++- .../zha/core/channels/smartenergy.py | 6 +++- homeassistant/components/zha/core/device.py | 9 +++--- homeassistant/components/zha/core/helpers.py | 4 +-- .../components/zha/core/registries.py | 22 +++++++------- homeassistant/components/zha/core/store.py | 15 +++++----- homeassistant/components/zha/core/typing.py | 27 +---------------- homeassistant/components/zha/cover.py | 10 +++++-- homeassistant/components/zha/entity.py | 12 +++++--- homeassistant/components/zha/light.py | 8 +++-- homeassistant/components/zha/select.py | 23 +++++++++------ homeassistant/components/zha/sensor.py | 29 ++++++++++--------- homeassistant/components/zha/siren.py | 11 ++++--- mypy.ini | 18 ------------ script/hassfest/mypy_config.py | 6 ---- 21 files changed, 135 insertions(+), 132 deletions(-) diff --git a/homeassistant/components/zha/alarm_control_panel.py b/homeassistant/components/zha/alarm_control_panel.py index ef616a8f894..15d27f95c5c 100644 --- a/homeassistant/components/zha/alarm_control_panel.py +++ b/homeassistant/components/zha/alarm_control_panel.py @@ -1,5 +1,8 @@ """Alarm control panels on Zigbee Home Automation networks.""" +from __future__ import annotations + import functools +from typing import TYPE_CHECKING from zigpy.zcl.clusters.security import IasAce @@ -38,9 +41,11 @@ from .core.const import ( ) from .core.helpers import async_get_zha_config_value from .core.registries import ZHA_ENTITIES -from .core.typing import ZhaDeviceType from .entity import ZhaEntity +if TYPE_CHECKING: + from .core.device import ZHADevice + STRICT_MATCH = functools.partial( ZHA_ENTITIES.strict_match, Platform.ALARM_CONTROL_PANEL ) @@ -83,7 +88,7 @@ class ZHAAlarmControlPanel(ZhaEntity, AlarmControlPanelEntity): | AlarmControlPanelEntityFeature.TRIGGER ) - def __init__(self, unique_id, zha_device: ZhaDeviceType, channels, **kwargs): + def __init__(self, unique_id, zha_device: ZHADevice, channels, **kwargs): """Initialize the ZHA alarm control device.""" super().__init__(unique_id, zha_device, channels, **kwargs) cfg_entry = zha_device.gateway.config_entry diff --git a/homeassistant/components/zha/api.py b/homeassistant/components/zha/api.py index f99255f55a9..737bef5ddff 100644 --- a/homeassistant/components/zha/api.py +++ b/homeassistant/components/zha/api.py @@ -69,11 +69,11 @@ from .core.helpers import ( get_matched_clusters, qr_to_install_code, ) -from .core.typing import ZhaDeviceType if TYPE_CHECKING: from homeassistant.components.websocket_api.connection import ActiveConnection + from .core.device import ZHADevice from .core.gateway import ZHAGateway _LOGGER = logging.getLogger(__name__) @@ -559,7 +559,7 @@ async def websocket_reconfigure_node( """Reconfigure a ZHA nodes entities by its ieee address.""" zha_gateway: ZHAGateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] ieee: EUI64 = msg[ATTR_IEEE] - device: ZhaDeviceType = zha_gateway.get_device(ieee) + device: ZHADevice = zha_gateway.get_device(ieee) async def forward_messages(data): """Forward events to websocket.""" @@ -1084,7 +1084,7 @@ def async_load_api(hass: HomeAssistant) -> None: """Remove a node from the network.""" zha_gateway: ZHAGateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] ieee: EUI64 = service.data[ATTR_IEEE] - zha_device: ZhaDeviceType = zha_gateway.get_device(ieee) + zha_device: ZHADevice = zha_gateway.get_device(ieee) if zha_device is not None and ( zha_device.is_coordinator and zha_device.ieee == zha_gateway.application_controller.ieee diff --git a/homeassistant/components/zha/button.py b/homeassistant/components/zha/button.py index 9f241795267..ed0836042d2 100644 --- a/homeassistant/components/zha/button.py +++ b/homeassistant/components/zha/button.py @@ -4,7 +4,7 @@ from __future__ import annotations import abc import functools import logging -from typing import Any +from typing import TYPE_CHECKING, Any import zigpy.exceptions from zigpy.zcl.foundation import Status @@ -20,9 +20,13 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .core import discovery from .core.const import CHANNEL_IDENTIFY, DATA_ZHA, SIGNAL_ADD_ENTITIES from .core.registries import ZHA_ENTITIES -from .core.typing import ChannelType, ZhaDeviceType from .entity import ZhaEntity +if TYPE_CHECKING: + from .core.channels.base import ZigbeeChannel + from .core.device import ZHADevice + + MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, Platform.BUTTON) CONFIG_DIAGNOSTIC_MATCH = functools.partial( ZHA_ENTITIES.config_diagnostic_match, Platform.BUTTON @@ -60,13 +64,13 @@ class ZHAButton(ZhaEntity, ButtonEntity): def __init__( self, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> None: """Init this button.""" super().__init__(unique_id, zha_device, channels, **kwargs) - self._channel: ChannelType = channels[0] + self._channel: ZigbeeChannel = channels[0] @abc.abstractmethod def get_args(self) -> list[Any]: @@ -87,8 +91,8 @@ class ZHAIdentifyButton(ZHAButton): def create_entity( cls, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> ZhaEntity | None: """Entity Factory. @@ -120,13 +124,13 @@ class ZHAAttributeButton(ZhaEntity, ButtonEntity): def __init__( self, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> None: """Init this button.""" super().__init__(unique_id, zha_device, channels, **kwargs) - self._channel: ChannelType = channels[0] + self._channel: ZigbeeChannel = channels[0] async def async_press(self) -> None: """Write attribute with defined value.""" diff --git a/homeassistant/components/zha/core/channels/base.py b/homeassistant/components/zha/core/channels/base.py index 7ba28a52116..c5df31f0602 100644 --- a/homeassistant/components/zha/core/channels/base.py +++ b/homeassistant/components/zha/core/channels/base.py @@ -5,7 +5,7 @@ import asyncio from enum import Enum from functools import partialmethod, wraps import logging -from typing import Any +from typing import TYPE_CHECKING, Any import zigpy.exceptions from zigpy.zcl.foundation import ( @@ -40,6 +40,9 @@ from ..const import ( ) from ..helpers import LogMixin, retryable_req, safe_read +if TYPE_CHECKING: + from . import ChannelPool + _LOGGER = logging.getLogger(__name__) @@ -105,7 +108,7 @@ class ZigbeeChannel(LogMixin): ZCL_INIT_ATTRS: dict[int | str, bool] = {} def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: zha_typing.ChannelPoolType + self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool ) -> None: """Initialize ZigbeeChannel.""" self._generic_id = f"channel_0x{cluster.cluster_id:04x}" diff --git a/homeassistant/components/zha/core/channels/general.py b/homeassistant/components/zha/core/channels/general.py index 8b67c81db44..99c5a81688b 100644 --- a/homeassistant/components/zha/core/channels/general.py +++ b/homeassistant/components/zha/core/channels/general.py @@ -3,7 +3,7 @@ from __future__ import annotations import asyncio from collections.abc import Coroutine -from typing import Any +from typing import TYPE_CHECKING, Any import zigpy.exceptions import zigpy.types as t @@ -28,6 +28,9 @@ from ..const import ( ) from .base import ClientChannel, ZigbeeChannel, parse_and_log_command +if TYPE_CHECKING: + from . import ChannelPool + @registries.ZIGBEE_CHANNEL_REGISTRY.register(general.Alarms.cluster_id) class Alarms(ZigbeeChannel): @@ -305,7 +308,7 @@ class OnOffChannel(ZigbeeChannel): } def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: zha_typing.ChannelPoolType + self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool ) -> None: """Initialize OnOffChannel.""" super().__init__(cluster, ch_pool) diff --git a/homeassistant/components/zha/core/channels/manufacturerspecific.py b/homeassistant/components/zha/core/channels/manufacturerspecific.py index 0ec9c7c2f4e..a89c74c54e8 100644 --- a/homeassistant/components/zha/core/channels/manufacturerspecific.py +++ b/homeassistant/components/zha/core/channels/manufacturerspecific.py @@ -1,5 +1,8 @@ """Manufacturer specific channels module for Zigbee Home Automation.""" +from __future__ import annotations + import logging +from typing import TYPE_CHECKING from homeassistant.core import callback @@ -16,6 +19,9 @@ from ..const import ( ) from .base import ClientChannel, ZigbeeChannel +if TYPE_CHECKING: + from . import ChannelPool + _LOGGER = logging.getLogger(__name__) @@ -55,7 +61,7 @@ class OppleRemote(ZigbeeChannel): REPORT_CONFIG = [] def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: zha_typing.ChannelPoolType + self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool ) -> None: """Initialize Opple channel.""" super().__init__(cluster, ch_pool) diff --git a/homeassistant/components/zha/core/channels/security.py b/homeassistant/components/zha/core/channels/security.py index 0e1e0f8e8a3..510237eee60 100644 --- a/homeassistant/components/zha/core/channels/security.py +++ b/homeassistant/components/zha/core/channels/security.py @@ -7,6 +7,7 @@ https://home-assistant.io/integrations/zha/ from __future__ import annotations import asyncio +from typing import TYPE_CHECKING from zigpy.exceptions import ZigbeeException from zigpy.zcl.clusters import security @@ -26,6 +27,9 @@ from ..const import ( from ..typing import CALLABLE_T from .base import ChannelStatus, ZigbeeChannel +if TYPE_CHECKING: + from . import ChannelPool + IAS_ACE_ARM = 0x0000 # ("arm", (t.enum8, t.CharacterString, t.uint8_t), False), IAS_ACE_BYPASS = 0x0001 # ("bypass", (t.LVList(t.uint8_t), t.CharacterString), False), IAS_ACE_EMERGENCY = 0x0002 # ("emergency", (), False), @@ -48,7 +52,7 @@ class IasAce(ZigbeeChannel): """IAS Ancillary Control Equipment channel.""" def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: zha_typing.ChannelPoolType + self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool ) -> None: """Initialize IAS Ancillary Control Equipment channel.""" super().__init__(cluster, ch_pool) diff --git a/homeassistant/components/zha/core/channels/smartenergy.py b/homeassistant/components/zha/core/channels/smartenergy.py index 927ceb248c5..d8f148c3dc5 100644 --- a/homeassistant/components/zha/core/channels/smartenergy.py +++ b/homeassistant/components/zha/core/channels/smartenergy.py @@ -3,6 +3,7 @@ from __future__ import annotations import enum from functools import partialmethod +from typing import TYPE_CHECKING from zigpy.zcl.clusters import smartenergy @@ -15,6 +16,9 @@ from ..const import ( ) from .base import ZigbeeChannel +if TYPE_CHECKING: + from . import ChannelPool + @registries.ZIGBEE_CHANNEL_REGISTRY.register(smartenergy.Calendar.cluster_id) class Calendar(ZigbeeChannel): @@ -115,7 +119,7 @@ class Metering(ZigbeeChannel): SUMMATION = 1 def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: zha_typing.ChannelPoolType + self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool ) -> None: """Initialize Metering.""" super().__init__(cluster, ch_pool) diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index 6e72c17ef42..009b28b10d5 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -78,6 +78,7 @@ from .helpers import LogMixin, async_get_zha_config_value if TYPE_CHECKING: from ..api import ClusterBinding + from .gateway import ZHAGateway _LOGGER = logging.getLogger(__name__) _UPDATE_ALIVE_INTERVAL = (60, 90) @@ -100,7 +101,7 @@ class ZHADevice(LogMixin): self, hass: HomeAssistant, zigpy_device: zha_typing.ZigpyDeviceType, - zha_gateway: zha_typing.ZhaGatewayType, + zha_gateway: ZHAGateway, ) -> None: """Initialize the gateway.""" self.hass = hass @@ -155,12 +156,12 @@ class ZHADevice(LogMixin): return self._zigpy_device @property - def channels(self) -> zha_typing.ChannelsType: + def channels(self) -> channels.Channels: """Return ZHA channels.""" return self._channels @channels.setter - def channels(self, value: zha_typing.ChannelsType) -> None: + def channels(self, value: channels.Channels) -> None: """Channels setter.""" assert isinstance(value, channels.Channels) self._channels = value @@ -332,7 +333,7 @@ class ZHADevice(LogMixin): cls, hass: HomeAssistant, zigpy_dev: zha_typing.ZigpyDeviceType, - gateway: zha_typing.ZhaGatewayType, + gateway: ZHAGateway, restored: bool = False, ): """Create new device.""" diff --git a/homeassistant/components/zha/core/helpers.py b/homeassistant/components/zha/core/helpers.py index 33d68822b9f..1c75846ee7e 100644 --- a/homeassistant/components/zha/core/helpers.py +++ b/homeassistant/components/zha/core/helpers.py @@ -35,7 +35,7 @@ from .const import ( DATA_ZHA_GATEWAY, ) from .registries import BINDABLE_CLUSTERS -from .typing import ZhaDeviceType, ZigpyClusterType +from .typing import ZigpyClusterType if TYPE_CHECKING: from .device import ZHADevice @@ -82,7 +82,7 @@ async def safe_read( async def get_matched_clusters( - source_zha_device: ZhaDeviceType, target_zha_device: ZhaDeviceType + source_zha_device: ZHADevice, target_zha_device: ZHADevice ) -> list[BindingPair]: """Get matched input/output cluster pairs for 2 devices.""" source_clusters = source_zha_device.async_get_std_clusters() diff --git a/homeassistant/components/zha/core/registries.py b/homeassistant/components/zha/core/registries.py index fb00e23ac6f..ed6b047566c 100644 --- a/homeassistant/components/zha/core/registries.py +++ b/homeassistant/components/zha/core/registries.py @@ -17,7 +17,7 @@ from homeassistant.const import Platform # importing channels updates registries from . import channels as zha_channels # noqa: F401 pylint: disable=unused-import from .decorators import DictRegistry, SetRegistry -from .typing import CALLABLE_T, ChannelType +from .typing import CALLABLE_T if TYPE_CHECKING: from .channels.base import ClientChannel, ZigbeeChannel @@ -161,7 +161,7 @@ class MatchRule: weight += 1 * len(self.aux_channels) return weight - def claim_channels(self, channel_pool: list[ChannelType]) -> list[ChannelType]: + def claim_channels(self, channel_pool: list[ZigbeeChannel]) -> list[ZigbeeChannel]: """Return a list of channels this rule matches + aux channels.""" claimed = [] if isinstance(self.channel_names, frozenset): @@ -216,7 +216,7 @@ class EntityClassAndChannels: """Container for entity class and corresponding channels.""" entity_class: CALLABLE_T - claimed_channel: list[ChannelType] + claimed_channel: list[ZigbeeChannel] class ZHAEntityRegistry: @@ -247,9 +247,9 @@ class ZHAEntityRegistry: component: str, manufacturer: str, model: str, - channels: list[ChannelType], + channels: list[ZigbeeChannel], default: CALLABLE_T = None, - ) -> tuple[CALLABLE_T, list[ChannelType]]: + ) -> tuple[CALLABLE_T, list[ZigbeeChannel]]: """Match a ZHA Channels to a ZHA Entity class.""" matches = self._strict_registry[component] for match in sorted(matches, key=lambda x: x.weight, reverse=True): @@ -263,11 +263,11 @@ class ZHAEntityRegistry: self, manufacturer: str, model: str, - channels: list[ChannelType], - ) -> tuple[dict[str, list[EntityClassAndChannels]], list[ChannelType]]: + channels: list[ZigbeeChannel], + ) -> tuple[dict[str, list[EntityClassAndChannels]], list[ZigbeeChannel]]: """Match ZHA Channels to potentially multiple ZHA Entity classes.""" result: dict[str, list[EntityClassAndChannels]] = collections.defaultdict(list) - all_claimed: set[ChannelType] = set() + all_claimed: set[ZigbeeChannel] = set() for component, stop_match_groups in self._multi_entity_registry.items(): for stop_match_grp, matches in stop_match_groups.items(): sorted_matches = sorted(matches, key=lambda x: x.weight, reverse=True) @@ -287,11 +287,11 @@ class ZHAEntityRegistry: self, manufacturer: str, model: str, - channels: list[ChannelType], - ) -> tuple[dict[str, list[EntityClassAndChannels]], list[ChannelType]]: + channels: list[ZigbeeChannel], + ) -> tuple[dict[str, list[EntityClassAndChannels]], list[ZigbeeChannel]]: """Match ZHA Channels to potentially multiple ZHA Entity classes.""" result: dict[str, list[EntityClassAndChannels]] = collections.defaultdict(list) - all_claimed: set[ChannelType] = set() + all_claimed: set[ZigbeeChannel] = set() for ( component, stop_match_groups, diff --git a/homeassistant/components/zha/core/store.py b/homeassistant/components/zha/core/store.py index 28983bdb427..c82f05303a5 100644 --- a/homeassistant/components/zha/core/store.py +++ b/homeassistant/components/zha/core/store.py @@ -5,7 +5,7 @@ from collections import OrderedDict from collections.abc import MutableMapping import datetime import time -from typing import cast +from typing import TYPE_CHECKING, cast import attr @@ -13,7 +13,8 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.storage import Store from homeassistant.loader import bind_hass -from .typing import ZhaDeviceType +if TYPE_CHECKING: + from .device import ZHADevice DATA_REGISTRY = "zha_storage" @@ -42,7 +43,7 @@ class ZhaStorage: self._store = Store(hass, STORAGE_VERSION, STORAGE_KEY) @callback - def async_create_device(self, device: ZhaDeviceType) -> ZhaDeviceEntry: + def async_create_device(self, device: ZHADevice) -> ZhaDeviceEntry: """Create a new ZhaDeviceEntry.""" device_entry: ZhaDeviceEntry = ZhaDeviceEntry( name=device.name, ieee=str(device.ieee), last_seen=device.last_seen @@ -52,7 +53,7 @@ class ZhaStorage: return device_entry @callback - def async_get_or_create_device(self, device: ZhaDeviceType) -> ZhaDeviceEntry: + def async_get_or_create_device(self, device: ZHADevice) -> ZhaDeviceEntry: """Create a new ZhaDeviceEntry.""" ieee_str: str = str(device.ieee) if ieee_str in self.devices: @@ -60,14 +61,14 @@ class ZhaStorage: return self.async_create_device(device) @callback - def async_create_or_update_device(self, device: ZhaDeviceType) -> ZhaDeviceEntry: + def async_create_or_update_device(self, device: ZHADevice) -> ZhaDeviceEntry: """Create or update a ZhaDeviceEntry.""" if str(device.ieee) in self.devices: return self.async_update_device(device) return self.async_create_device(device) @callback - def async_delete_device(self, device: ZhaDeviceType) -> None: + def async_delete_device(self, device: ZHADevice) -> None: """Delete ZhaDeviceEntry.""" ieee_str: str = str(device.ieee) if ieee_str in self.devices: @@ -75,7 +76,7 @@ class ZhaStorage: self.async_schedule_save() @callback - def async_update_device(self, device: ZhaDeviceType) -> ZhaDeviceEntry: + def async_update_device(self, device: ZHADevice) -> ZhaDeviceEntry: """Update name of ZhaDeviceEntry.""" ieee_str: str = str(device.ieee) old = self.devices[ieee_str] diff --git a/homeassistant/components/zha/core/typing.py b/homeassistant/components/zha/core/typing.py index 7e5cce8fec5..4c513ea7f21 100644 --- a/homeassistant/components/zha/core/typing.py +++ b/homeassistant/components/zha/core/typing.py @@ -1,6 +1,6 @@ """Typing helpers for ZHA component.""" from collections.abc import Callable -from typing import TYPE_CHECKING, TypeVar +from typing import TypeVar import zigpy.device import zigpy.endpoint @@ -10,33 +10,8 @@ import zigpy.zdo # pylint: disable=invalid-name CALLABLE_T = TypeVar("CALLABLE_T", bound=Callable) -ChannelType = "ZigbeeChannel" -ChannelsType = "Channels" -ChannelPoolType = "ChannelPool" -ClientChannelType = "ClientChannel" -ZDOChannelType = "ZDOChannel" -ZhaDeviceType = "ZHADevice" -ZhaEntityType = "ZHAEntity" -ZhaGatewayType = "ZHAGateway" -ZhaGroupType = "ZHAGroupType" ZigpyClusterType = zigpy.zcl.Cluster ZigpyDeviceType = zigpy.device.Device ZigpyEndpointType = zigpy.endpoint.Endpoint ZigpyGroupType = zigpy.group.Group ZigpyZdoType = zigpy.zdo.ZDO - -if TYPE_CHECKING: - import homeassistant.components.zha.entity - - from . import channels, device, gateway, group - from .channels import base as base_channels - - ChannelType = base_channels.ZigbeeChannel - ChannelsType = channels.Channels - ChannelPoolType = channels.ChannelPool - ClientChannelType = base_channels.ClientChannel - ZDOChannelType = base_channels.ZDOChannel - ZhaDeviceType = device.ZHADevice - ZhaEntityType = homeassistant.components.zha.entity.ZhaEntity - ZhaGatewayType = gateway.ZHAGateway - ZhaGroupType = group.ZHAGroup diff --git a/homeassistant/components/zha/cover.py b/homeassistant/components/zha/cover.py index 0fdb4daeaa5..2a61c5b4bc8 100644 --- a/homeassistant/components/zha/cover.py +++ b/homeassistant/components/zha/cover.py @@ -4,6 +4,7 @@ from __future__ import annotations import asyncio import functools import logging +from typing import TYPE_CHECKING from zigpy.zcl.foundation import Status @@ -37,9 +38,12 @@ from .core.const import ( SIGNAL_SET_LEVEL, ) from .core.registries import ZHA_ENTITIES -from .core.typing import ChannelType, ZhaDeviceType from .entity import ZhaEntity +if TYPE_CHECKING: + from .core.channels.base import ZigbeeChannel + from .core.device import ZHADevice + _LOGGER = logging.getLogger(__name__) MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, Platform.COVER) @@ -191,8 +195,8 @@ class Shade(ZhaEntity, CoverEntity): def __init__( self, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> None: """Initialize the ZHA light.""" diff --git a/homeassistant/components/zha/entity.py b/homeassistant/components/zha/entity.py index e9ea9ee871a..88dc9454f37 100644 --- a/homeassistant/components/zha/entity.py +++ b/homeassistant/components/zha/entity.py @@ -29,7 +29,7 @@ from .core.const import ( SIGNAL_REMOVE, ) from .core.helpers import LogMixin -from .core.typing import CALLABLE_T, ChannelType, ZhaDeviceType +from .core.typing import CALLABLE_T if TYPE_CHECKING: from .core.channels.base import ZigbeeChannel @@ -127,7 +127,11 @@ class BaseZhaEntity(LogMixin, entity.Entity): @callback def async_accept_signal( - self, channel: ChannelType, signal: str, func: CALLABLE_T, signal_override=False + self, + channel: ZigbeeChannel, + signal: str, + func: CALLABLE_T, + signal_override=False, ): """Accept a signal from a channel.""" unsub = None @@ -181,8 +185,8 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity): def create_entity( cls, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> ZhaEntity | None: """Entity Factory. diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index 30ae9688729..520916d469b 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -7,7 +7,7 @@ import functools import itertools import logging import random -from typing import Any, cast +from typing import TYPE_CHECKING, Any, cast from zigpy.zcl.clusters.general import Identify, LevelControl, OnOff from zigpy.zcl.clusters.lighting import Color @@ -62,9 +62,11 @@ from .core.const import ( ) from .core.helpers import LogMixin, async_get_zha_config_value from .core.registries import ZHA_ENTITIES -from .core.typing import ZhaDeviceType from .entity import ZhaEntity, ZhaGroupEntity +if TYPE_CHECKING: + from .core.device import ZHADevice + _LOGGER = logging.getLogger(__name__) CAPABILITIES_COLOR_LOOP = 0x4 @@ -341,7 +343,7 @@ class Light(BaseLight, ZhaEntity): _attr_supported_color_modes: set(ColorMode) _REFRESH_INTERVAL = (45, 75) - def __init__(self, unique_id, zha_device: ZhaDeviceType, channels, **kwargs): + def __init__(self, unique_id, zha_device: ZHADevice, channels, **kwargs): """Initialize the ZHA light.""" super().__init__(unique_id, zha_device, channels, **kwargs) self._on_off_channel = self.cluster_channels.get(CHANNEL_ON_OFF) diff --git a/homeassistant/components/zha/select.py b/homeassistant/components/zha/select.py index 8714d804790..231120ba806 100644 --- a/homeassistant/components/zha/select.py +++ b/homeassistant/components/zha/select.py @@ -4,6 +4,7 @@ from __future__ import annotations from enum import Enum import functools import logging +from typing import TYPE_CHECKING from zigpy import types from zigpy.zcl.clusters.general import OnOff @@ -26,9 +27,13 @@ from .core.const import ( Strobe, ) from .core.registries import ZHA_ENTITIES -from .core.typing import ChannelType, ZhaDeviceType from .entity import ZhaEntity +if TYPE_CHECKING: + from .core.channels.base import ZigbeeChannel + from .core.device import ZHADevice + + CONFIG_DIAGNOSTIC_MATCH = functools.partial( ZHA_ENTITIES.config_diagnostic_match, Platform.SELECT ) @@ -64,14 +69,14 @@ class ZHAEnumSelectEntity(ZhaEntity, SelectEntity): def __init__( self, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> None: """Init this select entity.""" self._attr_name = self._enum.__name__ self._attr_options = [entry.name.replace("_", " ") for entry in self._enum] - self._channel: ChannelType = channels[0] + self._channel: ZigbeeChannel = channels[0] super().__init__(unique_id, zha_device, channels, **kwargs) @property @@ -150,8 +155,8 @@ class ZCLEnumSelectEntity(ZhaEntity, SelectEntity): def create_entity( cls, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> ZhaEntity | None: """Entity Factory. @@ -175,13 +180,13 @@ class ZCLEnumSelectEntity(ZhaEntity, SelectEntity): def __init__( self, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> None: """Init this select entity.""" self._attr_options = [entry.name.replace("_", " ") for entry in self._enum] - self._channel: ChannelType = channels[0] + self._channel: ZigbeeChannel = channels[0] super().__init__(unique_id, zha_device, channels, **kwargs) @property diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index cdc37876889..e579967345c 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -3,7 +3,7 @@ from __future__ import annotations import functools import numbers -from typing import Any +from typing import TYPE_CHECKING, Any from homeassistant.components.climate.const import HVACAction from homeassistant.components.sensor import ( @@ -63,9 +63,12 @@ from .core.const import ( SIGNAL_ATTR_UPDATED, ) from .core.registries import SMARTTHINGS_HUMIDITY_CLUSTER, ZHA_ENTITIES -from .core.typing import ChannelType, ZhaDeviceType from .entity import ZhaEntity +if TYPE_CHECKING: + from .core.channels.base import ZigbeeChannel + from .core.device import ZHADevice + PARALLEL_UPDATES = 5 BATTERY_SIZES = { @@ -121,20 +124,20 @@ class Sensor(ZhaEntity, SensorEntity): def __init__( self, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> None: """Init this sensor.""" super().__init__(unique_id, zha_device, channels, **kwargs) - self._channel: ChannelType = channels[0] + self._channel: ZigbeeChannel = channels[0] @classmethod def create_entity( cls, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> ZhaEntity | None: """Entity Factory. @@ -213,8 +216,8 @@ class Battery(Sensor): def create_entity( cls, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> ZhaEntity | None: """Entity Factory. @@ -637,8 +640,8 @@ class ThermostatHVACAction(Sensor, id_suffix="hvac_action"): def create_entity( cls, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> ZhaEntity | None: """Entity Factory. @@ -762,8 +765,8 @@ class RSSISensor(Sensor, id_suffix="rssi"): def create_entity( cls, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> ZhaEntity | None: """Entity Factory. diff --git a/homeassistant/components/zha/siren.py b/homeassistant/components/zha/siren.py index 38b58b8dc54..b509f9585db 100644 --- a/homeassistant/components/zha/siren.py +++ b/homeassistant/components/zha/siren.py @@ -2,7 +2,7 @@ from __future__ import annotations import functools -from typing import Any +from typing import TYPE_CHECKING, Any from zigpy.zcl.clusters.security import IasWd as WD @@ -38,9 +38,12 @@ from .core.const import ( Strobe, ) from .core.registries import ZHA_ENTITIES -from .core.typing import ChannelType, ZhaDeviceType from .entity import ZhaEntity +if TYPE_CHECKING: + from .core.channels.base import ZigbeeChannel + from .core.device import ZHADevice + MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, Platform.SIREN) DEFAULT_DURATION = 5 # seconds @@ -72,8 +75,8 @@ class ZHASiren(ZhaEntity, SirenEntity): def __init__( self, unique_id: str, - zha_device: ZhaDeviceType, - channels: list[ChannelType], + zha_device: ZHADevice, + channels: list[ZigbeeChannel], **kwargs, ) -> None: """Init this siren.""" diff --git a/mypy.ini b/mypy.ini index f19f5f5dc68..dcbb2839b57 100644 --- a/mypy.ini +++ b/mypy.ini @@ -3000,9 +3000,6 @@ ignore_errors = true [mypy-homeassistant.components.xiaomi_miio.switch] ignore_errors = true -[mypy-homeassistant.components.zha.alarm_control_panel] -ignore_errors = true - [mypy-homeassistant.components.zha.api] ignore_errors = true @@ -3018,9 +3015,6 @@ ignore_errors = true [mypy-homeassistant.components.zha.config_flow] ignore_errors = true -[mypy-homeassistant.components.zha.core.channels] -ignore_errors = true - [mypy-homeassistant.components.zha.core.channels.base] ignore_errors = true @@ -3039,27 +3033,18 @@ ignore_errors = true [mypy-homeassistant.components.zha.core.channels.lighting] ignore_errors = true -[mypy-homeassistant.components.zha.core.channels.lightlink] -ignore_errors = true - [mypy-homeassistant.components.zha.core.channels.manufacturerspecific] ignore_errors = true [mypy-homeassistant.components.zha.core.channels.measurement] ignore_errors = true -[mypy-homeassistant.components.zha.core.channels.protocol] -ignore_errors = true - [mypy-homeassistant.components.zha.core.channels.security] ignore_errors = true [mypy-homeassistant.components.zha.core.channels.smartenergy] ignore_errors = true -[mypy-homeassistant.components.zha.core.decorators] -ignore_errors = true - [mypy-homeassistant.components.zha.core.device] ignore_errors = true @@ -3081,9 +3066,6 @@ ignore_errors = true [mypy-homeassistant.components.zha.core.store] ignore_errors = true -[mypy-homeassistant.components.zha.core.typing] -ignore_errors = true - [mypy-homeassistant.components.zha.cover] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 09a9820e7b4..9de6e9c6ad8 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -149,26 +149,21 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.xiaomi_miio.light", "homeassistant.components.xiaomi_miio.sensor", "homeassistant.components.xiaomi_miio.switch", - "homeassistant.components.zha.alarm_control_panel", "homeassistant.components.zha.api", "homeassistant.components.zha.binary_sensor", "homeassistant.components.zha.button", "homeassistant.components.zha.climate", "homeassistant.components.zha.config_flow", - "homeassistant.components.zha.core.channels", "homeassistant.components.zha.core.channels.base", "homeassistant.components.zha.core.channels.closures", "homeassistant.components.zha.core.channels.general", "homeassistant.components.zha.core.channels.homeautomation", "homeassistant.components.zha.core.channels.hvac", "homeassistant.components.zha.core.channels.lighting", - "homeassistant.components.zha.core.channels.lightlink", "homeassistant.components.zha.core.channels.manufacturerspecific", "homeassistant.components.zha.core.channels.measurement", - "homeassistant.components.zha.core.channels.protocol", "homeassistant.components.zha.core.channels.security", "homeassistant.components.zha.core.channels.smartenergy", - "homeassistant.components.zha.core.decorators", "homeassistant.components.zha.core.device", "homeassistant.components.zha.core.discovery", "homeassistant.components.zha.core.gateway", @@ -176,7 +171,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.zha.core.helpers", "homeassistant.components.zha.core.registries", "homeassistant.components.zha.core.store", - "homeassistant.components.zha.core.typing", "homeassistant.components.zha.cover", "homeassistant.components.zha.device_action", "homeassistant.components.zha.device_tracker",