Update typing 14 (#48078)
This commit is contained in:
parent
7d196abc4a
commit
dcca29ef68
73 changed files with 614 additions and 521 deletions
|
@ -1,6 +1,8 @@
|
|||
"""Mapping registries for Zigbee Home Automation."""
|
||||
from __future__ import annotations
|
||||
|
||||
import collections
|
||||
from typing import Callable, Dict, List, Set, Tuple, Union
|
||||
from typing import Callable, Dict
|
||||
|
||||
import attr
|
||||
import zigpy.profiles.zha
|
||||
|
@ -134,19 +136,19 @@ def set_or_callable(value):
|
|||
class MatchRule:
|
||||
"""Match a ZHA Entity to a channel name or generic id."""
|
||||
|
||||
channel_names: Union[Callable, Set[str], str] = attr.ib(
|
||||
channel_names: Callable | set[str] | str = attr.ib(
|
||||
factory=frozenset, converter=set_or_callable
|
||||
)
|
||||
generic_ids: Union[Callable, Set[str], str] = attr.ib(
|
||||
generic_ids: Callable | set[str] | str = attr.ib(
|
||||
factory=frozenset, converter=set_or_callable
|
||||
)
|
||||
manufacturers: Union[Callable, Set[str], str] = attr.ib(
|
||||
manufacturers: Callable | set[str] | str = attr.ib(
|
||||
factory=frozenset, converter=set_or_callable
|
||||
)
|
||||
models: Union[Callable, Set[str], str] = attr.ib(
|
||||
models: Callable | set[str] | str = attr.ib(
|
||||
factory=frozenset, converter=set_or_callable
|
||||
)
|
||||
aux_channels: Union[Callable, Set[str], str] = attr.ib(
|
||||
aux_channels: Callable | set[str] | str = attr.ib(
|
||||
factory=frozenset, converter=set_or_callable
|
||||
)
|
||||
|
||||
|
@ -176,7 +178,7 @@ class MatchRule:
|
|||
weight += 1 * len(self.aux_channels)
|
||||
return weight
|
||||
|
||||
def claim_channels(self, channel_pool: List[ChannelType]) -> List[ChannelType]:
|
||||
def claim_channels(self, channel_pool: list[ChannelType]) -> list[ChannelType]:
|
||||
"""Return a list of channels this rule matches + aux channels."""
|
||||
claimed = []
|
||||
if isinstance(self.channel_names, frozenset):
|
||||
|
@ -189,15 +191,15 @@ class MatchRule:
|
|||
claimed.extend([ch for ch in channel_pool if ch.name in self.aux_channels])
|
||||
return claimed
|
||||
|
||||
def strict_matched(self, manufacturer: str, model: str, channels: List) -> bool:
|
||||
def strict_matched(self, manufacturer: str, model: str, channels: list) -> bool:
|
||||
"""Return True if this device matches the criteria."""
|
||||
return all(self._matched(manufacturer, model, channels))
|
||||
|
||||
def loose_matched(self, manufacturer: str, model: str, channels: List) -> bool:
|
||||
def loose_matched(self, manufacturer: str, model: str, channels: list) -> bool:
|
||||
"""Return True if this device matches the criteria."""
|
||||
return any(self._matched(manufacturer, model, channels))
|
||||
|
||||
def _matched(self, manufacturer: str, model: str, channels: List) -> list:
|
||||
def _matched(self, manufacturer: str, model: str, channels: list) -> list:
|
||||
"""Return a list of field matches."""
|
||||
if not any(attr.asdict(self).values()):
|
||||
return [False]
|
||||
|
@ -245,9 +247,9 @@ class ZHAEntityRegistry:
|
|||
component: str,
|
||||
manufacturer: str,
|
||||
model: str,
|
||||
channels: List[ChannelType],
|
||||
channels: list[ChannelType],
|
||||
default: CALLABLE_T = None,
|
||||
) -> Tuple[CALLABLE_T, List[ChannelType]]:
|
||||
) -> tuple[CALLABLE_T, list[ChannelType]]:
|
||||
"""Match a ZHA Channels to a ZHA Entity class."""
|
||||
matches = self._strict_registry[component]
|
||||
for match in sorted(matches, key=lambda x: x.weight, reverse=True):
|
||||
|
@ -264,11 +266,11 @@ class ZHAEntityRegistry:
|
|||
def strict_match(
|
||||
self,
|
||||
component: str,
|
||||
channel_names: Union[Callable, Set[str], str] = None,
|
||||
generic_ids: Union[Callable, Set[str], str] = None,
|
||||
manufacturers: Union[Callable, Set[str], str] = None,
|
||||
models: Union[Callable, Set[str], str] = None,
|
||||
aux_channels: Union[Callable, Set[str], str] = None,
|
||||
channel_names: Callable | set[str] | str = None,
|
||||
generic_ids: Callable | set[str] | str = None,
|
||||
manufacturers: Callable | set[str] | str = None,
|
||||
models: Callable | set[str] | str = None,
|
||||
aux_channels: Callable | set[str] | str = None,
|
||||
) -> Callable[[CALLABLE_T], CALLABLE_T]:
|
||||
"""Decorate a strict match rule."""
|
||||
|
||||
|
@ -289,11 +291,11 @@ class ZHAEntityRegistry:
|
|||
def loose_match(
|
||||
self,
|
||||
component: str,
|
||||
channel_names: Union[Callable, Set[str], str] = None,
|
||||
generic_ids: Union[Callable, Set[str], str] = None,
|
||||
manufacturers: Union[Callable, Set[str], str] = None,
|
||||
models: Union[Callable, Set[str], str] = None,
|
||||
aux_channels: Union[Callable, Set[str], str] = None,
|
||||
channel_names: Callable | set[str] | str = None,
|
||||
generic_ids: Callable | set[str] | str = None,
|
||||
manufacturers: Callable | set[str] | str = None,
|
||||
models: Callable | set[str] | str = None,
|
||||
aux_channels: Callable | set[str] | str = None,
|
||||
) -> Callable[[CALLABLE_T], CALLABLE_T]:
|
||||
"""Decorate a loose match rule."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue