Skip to content

Commit

Permalink
Remove zha from mypy ignore list (home-assistant#73603)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Jun 28, 2022
1 parent 4b5c0be commit 8bed2e6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 43 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/zha/core/channels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def is_mains_powered(self) -> bool | None:
return self._channels.zha_device.is_mains_powered

@property
def manufacturer(self) -> str | None:
def manufacturer(self) -> str:
"""Return device manufacturer."""
return self._channels.zha_device.manufacturer

Expand All @@ -236,7 +236,7 @@ def hass(self) -> HomeAssistant:
return self._channels.zha_device.hass

@property
def model(self) -> str | None:
def model(self) -> str:
"""Return device model."""
return self._channels.zha_device.model

Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/zha/core/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from typing import TYPE_CHECKING

from homeassistant import const as ha_const
from homeassistant.const import CONF_TYPE, Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
Expand Down Expand Up @@ -86,9 +86,7 @@ def discover_by_device_type(self, channel_pool: ChannelPool) -> None:

unique_id = channel_pool.unique_id

component: str | None = self._device_configs.get(unique_id, {}).get(
ha_const.CONF_TYPE
)
component: str | None = self._device_configs.get(unique_id, {}).get(CONF_TYPE)
if component is None:
ep_profile_id = channel_pool.endpoint.profile_id
ep_device_type = channel_pool.endpoint.device_type
Expand Down Expand Up @@ -136,7 +134,7 @@ def discover_by_cluster_id(self, channel_pool: ChannelPool) -> None:

@staticmethod
def probe_single_cluster(
component: str,
component: Platform | None,
channel: base.ZigbeeChannel,
ep_channels: ChannelPool,
) -> None:
Expand Down
61 changes: 33 additions & 28 deletions homeassistant/components/zha/core/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
ZIGBEE_CHANNEL_REGISTRY: DictRegistry[type[ZigbeeChannel]] = DictRegistry()


def set_or_callable(value):
def set_or_callable(value) -> frozenset[str] | Callable:
"""Convert single str or None to a set. Pass through callables and sets."""
if value is None:
return frozenset()
Expand All @@ -121,22 +121,26 @@ def set_or_callable(value):
return frozenset([str(value)])


def _get_empty_frozenset() -> frozenset[str]:
return frozenset()


@attr.s(frozen=True)
class MatchRule:
"""Match a ZHA Entity to a channel name or generic id."""

channel_names: set[str] | str = attr.ib(
channel_names: frozenset[str] = attr.ib(
factory=frozenset, converter=set_or_callable
)
generic_ids: set[str] | str = attr.ib(factory=frozenset, converter=set_or_callable)
manufacturers: Callable | set[str] | str = attr.ib(
factory=frozenset, converter=set_or_callable
generic_ids: frozenset[str] = attr.ib(factory=frozenset, converter=set_or_callable)
manufacturers: frozenset[str] | Callable = attr.ib(
factory=_get_empty_frozenset, converter=set_or_callable
)
models: Callable | set[str] | str = attr.ib(
factory=frozenset, converter=set_or_callable
models: frozenset[str] | Callable = attr.ib(
factory=_get_empty_frozenset, converter=set_or_callable
)
aux_channels: Callable | set[str] | str = attr.ib(
factory=frozenset, converter=set_or_callable
aux_channels: frozenset[str] | Callable = attr.ib(
factory=_get_empty_frozenset, converter=set_or_callable
)

@property
Expand All @@ -162,7 +166,8 @@ def weight(self) -> int:

weight += 10 * len(self.channel_names)
weight += 5 * len(self.generic_ids)
weight += 1 * len(self.aux_channels)
if isinstance(self.aux_channels, frozenset):
weight += 1 * len(self.aux_channels)
return weight

def claim_channels(self, channel_pool: list[ZigbeeChannel]) -> list[ZigbeeChannel]:
Expand Down Expand Up @@ -321,11 +326,11 @@ def get_group_entity(self, component: str) -> type[ZhaGroupEntity] | None:
def strict_match(
self,
component: str,
channel_names: set[str] | str = None,
generic_ids: set[str] | str = None,
manufacturers: Callable | set[str] | str = None,
models: Callable | set[str] | str = None,
aux_channels: Callable | set[str] | str = None,
channel_names: set[str] | str | None = None,
generic_ids: set[str] | str | None = None,
manufacturers: Callable | set[str] | str | None = None,
models: Callable | set[str] | str | None = None,
aux_channels: Callable | set[str] | str | None = None,
) -> Callable[[_ZhaEntityT], _ZhaEntityT]:
"""Decorate a strict match rule."""

Expand All @@ -346,11 +351,11 @@ def decorator(zha_ent: _ZhaEntityT) -> _ZhaEntityT:
def multipass_match(
self,
component: str,
channel_names: set[str] | str = None,
generic_ids: set[str] | str = None,
manufacturers: Callable | set[str] | str = None,
models: Callable | set[str] | str = None,
aux_channels: Callable | set[str] | str = None,
channel_names: set[str] | str | None = None,
generic_ids: set[str] | str | None = None,
manufacturers: Callable | set[str] | str | None = None,
models: Callable | set[str] | str | None = None,
aux_channels: Callable | set[str] | str | None = None,
stop_on_match_group: int | str | None = None,
) -> Callable[[_ZhaEntityT], _ZhaEntityT]:
"""Decorate a loose match rule."""
Expand Down Expand Up @@ -379,11 +384,11 @@ def decorator(zha_entity: _ZhaEntityT) -> _ZhaEntityT:
def config_diagnostic_match(
self,
component: str,
channel_names: set[str] | str = None,
generic_ids: set[str] | str = None,
manufacturers: Callable | set[str] | str = None,
models: Callable | set[str] | str = None,
aux_channels: Callable | set[str] | str = None,
channel_names: set[str] | str | None = None,
generic_ids: set[str] | str | None = None,
manufacturers: Callable | set[str] | str | None = None,
models: Callable | set[str] | str | None = None,
aux_channels: Callable | set[str] | str | None = None,
stop_on_match_group: int | str | None = None,
) -> Callable[[_ZhaEntityT], _ZhaEntityT]:
"""Decorate a loose match rule."""
Expand Down Expand Up @@ -432,9 +437,9 @@ def prevent_entity_creation(self, platform: Platform, ieee: EUI64, key: str):

def clean_up(self) -> None:
"""Clean up post discovery."""
self.single_device_matches: dict[
Platform, dict[EUI64, list[str]]
] = collections.defaultdict(lambda: collections.defaultdict(list))
self.single_device_matches = collections.defaultdict(
lambda: collections.defaultdict(list)
)


ZHA_ENTITIES = ZHAEntityRegistry()
6 changes: 0 additions & 6 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2995,9 +2995,3 @@ ignore_errors = true

[mypy-homeassistant.components.xiaomi_miio.switch]
ignore_errors = true

[mypy-homeassistant.components.zha.core.discovery]
ignore_errors = true

[mypy-homeassistant.components.zha.core.registries]
ignore_errors = true
2 changes: 0 additions & 2 deletions script/hassfest/mypy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@
"homeassistant.components.xiaomi_miio.light",
"homeassistant.components.xiaomi_miio.sensor",
"homeassistant.components.xiaomi_miio.switch",
"homeassistant.components.zha.core.discovery",
"homeassistant.components.zha.core.registries",
]

# Component modules which should set no_implicit_reexport = true.
Expand Down

0 comments on commit 8bed2e6

Please sign in to comment.