mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17:07 +00:00
Switch lambda to attrgetter in zha (#99660)
This commit is contained in:
parent
a1359c1ce3
commit
b69cc29a78
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
import collections
|
import collections
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
import dataclasses
|
import dataclasses
|
||||||
|
from operator import attrgetter
|
||||||
from typing import TYPE_CHECKING, TypeVar
|
from typing import TYPE_CHECKING, TypeVar
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
@ -111,6 +112,8 @@ CLIENT_CLUSTER_HANDLER_REGISTRY: DictRegistry[
|
|||||||
] = DictRegistry()
|
] = DictRegistry()
|
||||||
ZIGBEE_CLUSTER_HANDLER_REGISTRY: DictRegistry[type[ClusterHandler]] = DictRegistry()
|
ZIGBEE_CLUSTER_HANDLER_REGISTRY: DictRegistry[type[ClusterHandler]] = DictRegistry()
|
||||||
|
|
||||||
|
WEIGHT_ATTR = attrgetter("weight")
|
||||||
|
|
||||||
|
|
||||||
def set_or_callable(value) -> frozenset[str] | Callable:
|
def set_or_callable(value) -> frozenset[str] | Callable:
|
||||||
"""Convert single str or None to a set. Pass through callables and sets."""
|
"""Convert single str or None to a set. Pass through callables and sets."""
|
||||||
@ -294,7 +297,7 @@ class ZHAEntityRegistry:
|
|||||||
) -> tuple[type[ZhaEntity] | None, list[ClusterHandler]]:
|
) -> tuple[type[ZhaEntity] | None, list[ClusterHandler]]:
|
||||||
"""Match a ZHA ClusterHandler to a ZHA Entity class."""
|
"""Match a ZHA ClusterHandler to a ZHA Entity class."""
|
||||||
matches = self._strict_registry[component]
|
matches = self._strict_registry[component]
|
||||||
for match in sorted(matches, key=lambda x: x.weight, reverse=True):
|
for match in sorted(matches, key=WEIGHT_ATTR, reverse=True):
|
||||||
if match.strict_matched(manufacturer, model, cluster_handlers, quirk_class):
|
if match.strict_matched(manufacturer, model, cluster_handlers, quirk_class):
|
||||||
claimed = match.claim_cluster_handlers(cluster_handlers)
|
claimed = match.claim_cluster_handlers(cluster_handlers)
|
||||||
return self._strict_registry[component][match], claimed
|
return self._strict_registry[component][match], claimed
|
||||||
@ -315,7 +318,7 @@ class ZHAEntityRegistry:
|
|||||||
all_claimed: set[ClusterHandler] = set()
|
all_claimed: set[ClusterHandler] = set()
|
||||||
for component, stop_match_groups in self._multi_entity_registry.items():
|
for component, stop_match_groups in self._multi_entity_registry.items():
|
||||||
for stop_match_grp, matches in stop_match_groups.items():
|
for stop_match_grp, matches in stop_match_groups.items():
|
||||||
sorted_matches = sorted(matches, key=lambda x: x.weight, reverse=True)
|
sorted_matches = sorted(matches, key=WEIGHT_ATTR, reverse=True)
|
||||||
for match in sorted_matches:
|
for match in sorted_matches:
|
||||||
if match.strict_matched(
|
if match.strict_matched(
|
||||||
manufacturer, model, cluster_handlers, quirk_class
|
manufacturer, model, cluster_handlers, quirk_class
|
||||||
@ -349,7 +352,7 @@ class ZHAEntityRegistry:
|
|||||||
stop_match_groups,
|
stop_match_groups,
|
||||||
) in self._config_diagnostic_entity_registry.items():
|
) in self._config_diagnostic_entity_registry.items():
|
||||||
for stop_match_grp, matches in stop_match_groups.items():
|
for stop_match_grp, matches in stop_match_groups.items():
|
||||||
sorted_matches = sorted(matches, key=lambda x: x.weight, reverse=True)
|
sorted_matches = sorted(matches, key=WEIGHT_ATTR, reverse=True)
|
||||||
for match in sorted_matches:
|
for match in sorted_matches:
|
||||||
if match.strict_matched(
|
if match.strict_matched(
|
||||||
manufacturer, model, cluster_handlers, quirk_class
|
manufacturer, model, cluster_handlers, quirk_class
|
||||||
|
Loading…
x
Reference in New Issue
Block a user