diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index 588fcac7ca6..e83c0afbceb 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -276,7 +276,7 @@ class ZHADevice(LogMixin): @property def skip_configuration(self) -> bool: """Return true if the device should not issue configuration related commands.""" - return self._zigpy_device.skip_configuration or self.is_coordinator + return self._zigpy_device.skip_configuration or bool(self.is_coordinator) @property def gateway(self): @@ -819,7 +819,7 @@ class ZHADevice(LogMixin): fmt = f"{log_msg[1]} completed: %s" zdo.debug(fmt, *(log_msg[2] + (outcome,))) - def log(self, level: int, msg: str, *args: Any, **kwargs: dict) -> None: + def log(self, level: int, msg: str, *args: Any, **kwargs: Any) -> None: """Log a message.""" msg = f"[%s](%s): {msg}" args = (self.nwk, self.model) + args diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index 02b2b21c835..b9465d5e2aa 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -8,7 +8,6 @@ from datetime import timedelta from enum import Enum import itertools import logging -import os import time import traceback from typing import TYPE_CHECKING, Any, NamedTuple, Union @@ -163,7 +162,7 @@ class ZHAGateway: app_config = self._config.get(CONF_ZIGPY, {}) database = self._config.get( CONF_DATABASE, - os.path.join(self._hass.config.config_dir, DEFAULT_DATABASE_NAME), + self._hass.config.path(DEFAULT_DATABASE_NAME), ) app_config[CONF_DATABASE] = database app_config[CONF_DEVICE] = self.config_entry.data[CONF_DEVICE] @@ -333,7 +332,7 @@ class ZHAGateway: def group_removed(self, zigpy_group: zigpy.group.Group) -> None: """Handle zigpy group removed event.""" self._send_group_gateway_message(zigpy_group, ZHA_GW_MSG_GROUP_REMOVED) - zha_group = self._groups.pop(zigpy_group.group_id, None) + zha_group = self._groups.pop(zigpy_group.group_id) zha_group.info("group_removed") self._cleanup_group_entity_registry_entries(zigpy_group) @@ -428,6 +427,7 @@ class ZHAGateway: ] # then we get all group entity entries tied to the coordinator + assert self.coordinator_zha_device all_group_entity_entries = er.async_entries_for_device( self.ha_entity_registry, self.coordinator_zha_device.device_id, diff --git a/homeassistant/components/zha/core/group.py b/homeassistant/components/zha/core/group.py index 1392041c4d4..7f1c9f09998 100644 --- a/homeassistant/components/zha/core/group.py +++ b/homeassistant/components/zha/core/group.py @@ -78,7 +78,7 @@ class ZHAGroupMember(LogMixin): return member_info @property - def associated_entities(self) -> list[GroupEntityReference]: + def associated_entities(self) -> list[dict[str, Any]]: """Return the list of entities that were derived from this endpoint.""" ha_entity_registry = self.device.gateway.ha_entity_registry zha_device_registry = self.device.gateway.device_registry @@ -150,9 +150,7 @@ class ZHAGroup(LogMixin): def members(self) -> list[ZHAGroupMember]: """Return the ZHA devices that are members of this group.""" return [ - ZHAGroupMember( - self, self._zha_gateway.devices.get(member_ieee), endpoint_id - ) + ZHAGroupMember(self, self._zha_gateway.devices[member_ieee], endpoint_id) for (member_ieee, endpoint_id) in self._zigpy_group.members.keys() if member_ieee in self._zha_gateway.devices ] diff --git a/homeassistant/components/zha/core/helpers.py b/homeassistant/components/zha/core/helpers.py index f387cc99bfe..390ef290dc2 100644 --- a/homeassistant/components/zha/core/helpers.py +++ b/homeassistant/components/zha/core/helpers.py @@ -169,6 +169,8 @@ def async_get_zha_device(hass: HomeAssistant, device_id: str) -> ZHADevice: """Get a ZHA device for the given device registry id.""" device_registry = dr.async_get(hass) registry_device = device_registry.async_get(device_id) + if not registry_device: + raise ValueError(f"Device id `{device_id}` not found in registry.") zha_gateway: ZHAGateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] ieee_address = list(list(registry_device.identifiers)[0])[1] ieee = zigpy.types.EUI64.convert(ieee_address) diff --git a/mypy.ini b/mypy.ini index e2e91ef921c..b5c56d71ff9 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2996,21 +2996,9 @@ ignore_errors = true [mypy-homeassistant.components.xiaomi_miio.switch] ignore_errors = true -[mypy-homeassistant.components.zha.core.device] -ignore_errors = true - [mypy-homeassistant.components.zha.core.discovery] ignore_errors = true -[mypy-homeassistant.components.zha.core.gateway] -ignore_errors = true - -[mypy-homeassistant.components.zha.core.group] -ignore_errors = true - -[mypy-homeassistant.components.zha.core.helpers] -ignore_errors = true - [mypy-homeassistant.components.zha.core.registries] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 49cf3b7b65a..453eade7b2d 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -144,11 +144,7 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.xiaomi_miio.light", "homeassistant.components.xiaomi_miio.sensor", "homeassistant.components.xiaomi_miio.switch", - "homeassistant.components.zha.core.device", "homeassistant.components.zha.core.discovery", - "homeassistant.components.zha.core.gateway", - "homeassistant.components.zha.core.group", - "homeassistant.components.zha.core.helpers", "homeassistant.components.zha.core.registries", "homeassistant.components.zha.core.store", ]