Fix mypy issues in zha core modules (#74028)

* Fix mypy issues in zha gateway, group and helpers

* Cleanup device

* Apply suggestion

* Raise ValueError

* Use hass.config.path
This commit is contained in:
epenet 2022-06-28 08:50:16 +02:00 committed by GitHub
parent 720768560d
commit fb10853358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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