From 2de4b193e3de269bffdb1d65f84859f552195659 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:49:40 +0200 Subject: [PATCH] Remove unnecessary type definitions in zha (#73735) * Cleanup ZigpyClusterType * Cleanup ZigpyDeviceType * Cleanup ZigpyEndpointType * Cleanup ZigpyGroupType * Cleanup ZigpyZdoType --- homeassistant/components/zha/core/channels/base.py | 6 ++---- homeassistant/components/zha/core/channels/general.py | 7 +++---- .../zha/core/channels/manufacturerspecific.py | 8 ++++---- .../components/zha/core/channels/security.py | 7 +++---- .../components/zha/core/channels/smartenergy.py | 7 +++---- homeassistant/components/zha/core/device.py | 9 +++++---- homeassistant/components/zha/core/helpers.py | 4 ++-- homeassistant/components/zha/core/typing.py | 11 ----------- 8 files changed, 22 insertions(+), 37 deletions(-) diff --git a/homeassistant/components/zha/core/channels/base.py b/homeassistant/components/zha/core/channels/base.py index c5df31f0602..9b3ad6d9572 100644 --- a/homeassistant/components/zha/core/channels/base.py +++ b/homeassistant/components/zha/core/channels/base.py @@ -8,6 +8,7 @@ import logging from typing import TYPE_CHECKING, Any import zigpy.exceptions +import zigpy.zcl from zigpy.zcl.foundation import ( CommandSchema, ConfigureReportingResponseRecord, @@ -19,7 +20,6 @@ from homeassistant.const import ATTR_COMMAND from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_send -from .. import typing as zha_typing from ..const import ( ATTR_ARGS, ATTR_ATTRIBUTE_ID, @@ -107,9 +107,7 @@ class ZigbeeChannel(LogMixin): # attribute read is acceptable. ZCL_INIT_ATTRS: dict[int | str, bool] = {} - def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool - ) -> None: + def __init__(self, cluster: zigpy.zcl.Cluster, ch_pool: ChannelPool) -> None: """Initialize ZigbeeChannel.""" self._generic_id = f"channel_0x{cluster.cluster_id:04x}" self._ch_pool = ch_pool diff --git a/homeassistant/components/zha/core/channels/general.py b/homeassistant/components/zha/core/channels/general.py index 99c5a81688b..aa292013081 100644 --- a/homeassistant/components/zha/core/channels/general.py +++ b/homeassistant/components/zha/core/channels/general.py @@ -7,13 +7,14 @@ from typing import TYPE_CHECKING, Any import zigpy.exceptions import zigpy.types as t +import zigpy.zcl from zigpy.zcl.clusters import general from zigpy.zcl.foundation import Status from homeassistant.core import callback from homeassistant.helpers.event import async_call_later -from .. import registries, typing as zha_typing +from .. import registries from ..const import ( REPORT_CONFIG_ASAP, REPORT_CONFIG_BATTERY_SAVE, @@ -307,9 +308,7 @@ class OnOffChannel(ZigbeeChannel): "start_up_on_off": True, } - def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool - ) -> None: + def __init__(self, cluster: zigpy.zcl.Cluster, ch_pool: ChannelPool) -> None: """Initialize OnOffChannel.""" super().__init__(cluster, ch_pool) self._off_listener = None diff --git a/homeassistant/components/zha/core/channels/manufacturerspecific.py b/homeassistant/components/zha/core/channels/manufacturerspecific.py index a89c74c54e8..144d5736526 100644 --- a/homeassistant/components/zha/core/channels/manufacturerspecific.py +++ b/homeassistant/components/zha/core/channels/manufacturerspecific.py @@ -4,9 +4,11 @@ from __future__ import annotations import logging from typing import TYPE_CHECKING +import zigpy.zcl + from homeassistant.core import callback -from .. import registries, typing as zha_typing +from .. import registries from ..const import ( ATTR_ATTRIBUTE_ID, ATTR_ATTRIBUTE_NAME, @@ -60,9 +62,7 @@ class OppleRemote(ZigbeeChannel): REPORT_CONFIG = [] - def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool - ) -> None: + def __init__(self, cluster: zigpy.zcl.Cluster, ch_pool: ChannelPool) -> None: """Initialize Opple channel.""" super().__init__(cluster, ch_pool) if self.cluster.endpoint.model == "lumi.motion.ac02": diff --git a/homeassistant/components/zha/core/channels/security.py b/homeassistant/components/zha/core/channels/security.py index 510237eee60..4c0d6bbfd59 100644 --- a/homeassistant/components/zha/core/channels/security.py +++ b/homeassistant/components/zha/core/channels/security.py @@ -10,12 +10,13 @@ import asyncio from typing import TYPE_CHECKING from zigpy.exceptions import ZigbeeException +import zigpy.zcl from zigpy.zcl.clusters import security from zigpy.zcl.clusters.security import IasAce as AceCluster from homeassistant.core import callback -from .. import registries, typing as zha_typing +from .. import registries from ..const import ( SIGNAL_ATTR_UPDATED, WARNING_DEVICE_MODE_EMERGENCY, @@ -51,9 +52,7 @@ SIGNAL_ALARM_TRIGGERED = "zha_armed_triggered" class IasAce(ZigbeeChannel): """IAS Ancillary Control Equipment channel.""" - def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool - ) -> None: + def __init__(self, cluster: zigpy.zcl.Cluster, ch_pool: ChannelPool) -> None: """Initialize IAS Ancillary Control Equipment channel.""" super().__init__(cluster, ch_pool) self.command_map: dict[int, CALLABLE_T] = { diff --git a/homeassistant/components/zha/core/channels/smartenergy.py b/homeassistant/components/zha/core/channels/smartenergy.py index d8f148c3dc5..099571aa69e 100644 --- a/homeassistant/components/zha/core/channels/smartenergy.py +++ b/homeassistant/components/zha/core/channels/smartenergy.py @@ -5,9 +5,10 @@ import enum from functools import partialmethod from typing import TYPE_CHECKING +import zigpy.zcl from zigpy.zcl.clusters import smartenergy -from .. import registries, typing as zha_typing +from .. import registries from ..const import ( REPORT_CONFIG_ASAP, REPORT_CONFIG_DEFAULT, @@ -118,9 +119,7 @@ class Metering(ZigbeeChannel): DEMAND = 0 SUMMATION = 1 - def __init__( - self, cluster: zha_typing.ZigpyClusterType, ch_pool: ChannelPool - ) -> None: + def __init__(self, cluster: zigpy.zcl.Cluster, ch_pool: ChannelPool) -> None: """Initialize Metering.""" super().__init__(cluster, ch_pool) self._format_spec = None diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index 009b28b10d5..588fcac7ca6 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -12,6 +12,7 @@ import time from typing import TYPE_CHECKING, Any from zigpy import types +import zigpy.device import zigpy.exceptions from zigpy.profiles import PROFILES import zigpy.quirks @@ -27,7 +28,7 @@ from homeassistant.helpers.dispatcher import ( ) from homeassistant.helpers.event import async_track_time_interval -from . import channels, typing as zha_typing +from . import channels from .const import ( ATTR_ARGS, ATTR_ATTRIBUTE, @@ -100,7 +101,7 @@ class ZHADevice(LogMixin): def __init__( self, hass: HomeAssistant, - zigpy_device: zha_typing.ZigpyDeviceType, + zigpy_device: zigpy.device.Device, zha_gateway: ZHAGateway, ) -> None: """Initialize the gateway.""" @@ -151,7 +152,7 @@ class ZHADevice(LogMixin): self._ha_device_id = device_id @property - def device(self) -> zha_typing.ZigpyDeviceType: + def device(self) -> zigpy.device.Device: """Return underlying Zigpy device.""" return self._zigpy_device @@ -332,7 +333,7 @@ class ZHADevice(LogMixin): def new( cls, hass: HomeAssistant, - zigpy_dev: zha_typing.ZigpyDeviceType, + zigpy_dev: zigpy.device.Device, gateway: ZHAGateway, restored: bool = False, ): diff --git a/homeassistant/components/zha/core/helpers.py b/homeassistant/components/zha/core/helpers.py index 1c75846ee7e..f387cc99bfe 100644 --- a/homeassistant/components/zha/core/helpers.py +++ b/homeassistant/components/zha/core/helpers.py @@ -21,6 +21,7 @@ import voluptuous as vol import zigpy.exceptions import zigpy.types import zigpy.util +import zigpy.zcl import zigpy.zdo.types as zdo_types from homeassistant.config_entries import ConfigEntry @@ -35,7 +36,6 @@ from .const import ( DATA_ZHA_GATEWAY, ) from .registries import BINDABLE_CLUSTERS -from .typing import ZigpyClusterType if TYPE_CHECKING: from .device import ZHADevice @@ -48,7 +48,7 @@ _T = TypeVar("_T") class BindingPair: """Information for binding.""" - source_cluster: ZigpyClusterType + source_cluster: zigpy.zcl.Cluster target_ieee: zigpy.types.EUI64 target_ep_id: int diff --git a/homeassistant/components/zha/core/typing.py b/homeassistant/components/zha/core/typing.py index 4c513ea7f21..714dc03ef82 100644 --- a/homeassistant/components/zha/core/typing.py +++ b/homeassistant/components/zha/core/typing.py @@ -2,16 +2,5 @@ from collections.abc import Callable from typing import TypeVar -import zigpy.device -import zigpy.endpoint -import zigpy.group -import zigpy.zcl -import zigpy.zdo - # pylint: disable=invalid-name CALLABLE_T = TypeVar("CALLABLE_T", bound=Callable) -ZigpyClusterType = zigpy.zcl.Cluster -ZigpyDeviceType = zigpy.device.Device -ZigpyEndpointType = zigpy.endpoint.Endpoint -ZigpyGroupType = zigpy.group.Group -ZigpyZdoType = zigpy.zdo.ZDO