Switch lambda to attrgetter in zha (#99660)
This commit is contained in:
parent
a1359c1ce3
commit
b69cc29a78
1 changed files with 6 additions and 3 deletions
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
import collections
|
||||
from collections.abc import Callable
|
||||
import dataclasses
|
||||
from operator import attrgetter
|
||||
from typing import TYPE_CHECKING, TypeVar
|
||||
|
||||
import attr
|
||||
|
@ -111,6 +112,8 @@ CLIENT_CLUSTER_HANDLER_REGISTRY: DictRegistry[
|
|||
] = DictRegistry()
|
||||
ZIGBEE_CLUSTER_HANDLER_REGISTRY: DictRegistry[type[ClusterHandler]] = DictRegistry()
|
||||
|
||||
WEIGHT_ATTR = attrgetter("weight")
|
||||
|
||||
|
||||
def set_or_callable(value) -> frozenset[str] | Callable:
|
||||
"""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]]:
|
||||
"""Match a ZHA ClusterHandler to a ZHA Entity class."""
|
||||
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):
|
||||
claimed = match.claim_cluster_handlers(cluster_handlers)
|
||||
return self._strict_registry[component][match], claimed
|
||||
|
@ -315,7 +318,7 @@ class ZHAEntityRegistry:
|
|||
all_claimed: set[ClusterHandler] = set()
|
||||
for component, stop_match_groups in self._multi_entity_registry.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:
|
||||
if match.strict_matched(
|
||||
manufacturer, model, cluster_handlers, quirk_class
|
||||
|
@ -349,7 +352,7 @@ class ZHAEntityRegistry:
|
|||
stop_match_groups,
|
||||
) in self._config_diagnostic_entity_registry.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:
|
||||
if match.strict_matched(
|
||||
manufacturer, model, cluster_handlers, quirk_class
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue