From b880a05e4533a63222e19b7bc9520e9b1620f4b2 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 24 Jun 2022 16:35:38 +0200 Subject: [PATCH] Fix type hints in zha remaining channels (#73778) * Fix hvac channel type hints * Fix security channel type hints * Fix homeautomation channel type hints * Fix type hints in zha base channel * Adjust select entity * Remove unused arg --- .../components/zha/core/channels/__init__.py | 2 +- .../components/zha/core/channels/base.py | 9 +++++---- .../zha/core/channels/homeautomation.py | 6 +++++- .../components/zha/core/channels/hvac.py | 1 + .../components/zha/core/channels/security.py | 17 ++++------------- homeassistant/components/zha/select.py | 1 + mypy.ini | 12 ------------ script/hassfest/mypy_config.py | 4 ---- 8 files changed, 17 insertions(+), 35 deletions(-) diff --git a/homeassistant/components/zha/core/channels/__init__.py b/homeassistant/components/zha/core/channels/__init__.py index 33143821f9c..2da7462f3eb 100644 --- a/homeassistant/components/zha/core/channels/__init__.py +++ b/homeassistant/components/zha/core/channels/__init__.py @@ -370,7 +370,7 @@ class ChannelPool: return [self.all_channels[chan_id] for chan_id in (available - claimed)] @callback - def zha_send_event(self, event_data: dict[str, str | int]) -> None: + def zha_send_event(self, event_data: dict[str, Any]) -> None: """Relay events to hass.""" self._channels.zha_send_event( { diff --git a/homeassistant/components/zha/core/channels/base.py b/homeassistant/components/zha/core/channels/base.py index de943ebac16..ae5980cd630 100644 --- a/homeassistant/components/zha/core/channels/base.py +++ b/homeassistant/components/zha/core/channels/base.py @@ -137,7 +137,7 @@ class ZigbeeChannel(LogMixin): self.value_attribute = attr self._status = ChannelStatus.CREATED self._cluster.add_listener(self) - self.data_cache = {} + self.data_cache: dict[str, Enum] = {} @property def id(self) -> str: @@ -278,7 +278,7 @@ class ZigbeeChannel(LogMixin): ) def _configure_reporting_status( - self, attrs: dict[int | str, tuple], res: list | tuple + self, attrs: dict[int | str, tuple[int, int, float | int]], res: list | tuple ) -> None: """Parse configure reporting result.""" if isinstance(res, (Exception, ConfigureReportingResponseRecord)): @@ -304,10 +304,10 @@ class ZigbeeChannel(LogMixin): for r in res if r.status != Status.SUCCESS ] - attrs = {self.cluster.attributes.get(r, [r])[0] for r in attrs} + attributes = {self.cluster.attributes.get(r, [r])[0] for r in attrs} self.debug( "Successfully configured reporting for '%s' on '%s' cluster", - attrs - set(failed), + attributes - set(failed), self.name, ) self.debug( @@ -393,6 +393,7 @@ class ZigbeeChannel(LogMixin): def zha_send_event(self, command: str, arg: list | dict | CommandSchema) -> None: """Relay events to hass.""" + args: list | dict if isinstance(arg, CommandSchema): args = [a for a in arg if a is not None] params = arg.as_dict() diff --git a/homeassistant/components/zha/core/channels/homeautomation.py b/homeassistant/components/zha/core/channels/homeautomation.py index 52036706f19..69295ef6f81 100644 --- a/homeassistant/components/zha/core/channels/homeautomation.py +++ b/homeassistant/components/zha/core/channels/homeautomation.py @@ -158,7 +158,11 @@ class ElectricalMeasurementChannel(ZigbeeChannel): return None meas_type = self.MeasurementType(meas_type) - return ", ".join(m.name for m in self.MeasurementType if m in meas_type) + return ", ".join( + m.name + for m in self.MeasurementType + if m in meas_type and m.name is not None + ) @registries.ZIGBEE_CHANNEL_REGISTRY.register( diff --git a/homeassistant/components/zha/core/channels/hvac.py b/homeassistant/components/zha/core/channels/hvac.py index 53f18a0fd0f..4b4909299b1 100644 --- a/homeassistant/components/zha/core/channels/hvac.py +++ b/homeassistant/components/zha/core/channels/hvac.py @@ -293,6 +293,7 @@ class ThermostatChannel(ZigbeeChannel): return bool(self.occupancy) except ZigbeeException as ex: self.debug("Couldn't read 'occupancy' attribute: %s", ex) + return None async def write_attributes(self, data, **kwargs): """Write attributes helper.""" diff --git a/homeassistant/components/zha/core/channels/security.py b/homeassistant/components/zha/core/channels/security.py index 789e792e149..41e65019415 100644 --- a/homeassistant/components/zha/core/channels/security.py +++ b/homeassistant/components/zha/core/channels/security.py @@ -199,26 +199,17 @@ class IasAce(ZigbeeChannel): def _emergency(self) -> None: """Handle the IAS ACE emergency command.""" - self._set_alarm( - AceCluster.AlarmStatus.Emergency, - IAS_ACE_EMERGENCY, - ) + self._set_alarm(AceCluster.AlarmStatus.Emergency) def _fire(self) -> None: """Handle the IAS ACE fire command.""" - self._set_alarm( - AceCluster.AlarmStatus.Fire, - IAS_ACE_FIRE, - ) + self._set_alarm(AceCluster.AlarmStatus.Fire) def _panic(self) -> None: """Handle the IAS ACE panic command.""" - self._set_alarm( - AceCluster.AlarmStatus.Emergency_Panic, - IAS_ACE_PANIC, - ) + self._set_alarm(AceCluster.AlarmStatus.Emergency_Panic) - def _set_alarm(self, status: AceCluster.PanelStatus, event: str) -> None: + def _set_alarm(self, status: AceCluster.AlarmStatus) -> None: """Set the specified alarm status.""" self.alarm_status = status self.armed_state = AceCluster.PanelStatus.In_Alarm diff --git a/homeassistant/components/zha/select.py b/homeassistant/components/zha/select.py index 83bbcdca580..6d202ccceb2 100644 --- a/homeassistant/components/zha/select.py +++ b/homeassistant/components/zha/select.py @@ -64,6 +64,7 @@ class ZHAEnumSelectEntity(ZhaEntity, SelectEntity): """Representation of a ZHA select entity.""" _attr_entity_category = EntityCategory.CONFIG + _attr_name: str _enum: type[Enum] def __init__( diff --git a/mypy.ini b/mypy.ini index 8dca7403eff..e2e91ef921c 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2996,18 +2996,6 @@ ignore_errors = true [mypy-homeassistant.components.xiaomi_miio.switch] ignore_errors = true -[mypy-homeassistant.components.zha.core.channels.base] -ignore_errors = true - -[mypy-homeassistant.components.zha.core.channels.homeautomation] -ignore_errors = true - -[mypy-homeassistant.components.zha.core.channels.hvac] -ignore_errors = true - -[mypy-homeassistant.components.zha.core.channels.security] -ignore_errors = true - [mypy-homeassistant.components.zha.core.device] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index f319ccb5235..49cf3b7b65a 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -144,10 +144,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.xiaomi_miio.light", "homeassistant.components.xiaomi_miio.sensor", "homeassistant.components.xiaomi_miio.switch", - "homeassistant.components.zha.core.channels.base", - "homeassistant.components.zha.core.channels.homeautomation", - "homeassistant.components.zha.core.channels.hvac", - "homeassistant.components.zha.core.channels.security", "homeassistant.components.zha.core.device", "homeassistant.components.zha.core.discovery", "homeassistant.components.zha.core.gateway",