Make the rest of ZHA platforms to use ZHA class registry (#30261)
* Refactor ZHA component tests fixtures. * Add tests for ZHA device discovery. * Refactor ZHA registry MatchRule. Allow callables as a matching criteria. Allow sets for model & manufacturer. * Minor ZHA class registry refactoring. Less cluttered strict_matching registrations. * Add entities only if there are any. * Migrate rest of ZHA platforms to ZHA registry. * Pylint fixes.
This commit is contained in:
parent
5ed44297e6
commit
a3061bda60
13 changed files with 2152 additions and 80 deletions
|
@ -1,4 +1,5 @@
|
|||
"""Support for the ZHA platform."""
|
||||
import functools
|
||||
import logging
|
||||
import time
|
||||
|
||||
|
@ -14,9 +15,11 @@ from .core.const import (
|
|||
SIGNAL_ATTR_UPDATED,
|
||||
ZHA_DISCOVERY_NEW,
|
||||
)
|
||||
from .core.registries import ZHA_ENTITIES
|
||||
from .entity import ZhaEntity
|
||||
from .sensor import Battery
|
||||
|
||||
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN)
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -47,11 +50,20 @@ async def _async_setup_entities(
|
|||
"""Set up the ZHA device trackers."""
|
||||
entities = []
|
||||
for discovery_info in discovery_infos:
|
||||
entities.append(ZHADeviceScannerEntity(**discovery_info))
|
||||
zha_dev = discovery_info["zha_device"]
|
||||
channels = discovery_info["channels"]
|
||||
|
||||
async_add_entities(entities, update_before_add=True)
|
||||
entity = ZHA_ENTITIES.get_entity(
|
||||
DOMAIN, zha_dev, channels, ZHADeviceScannerEntity
|
||||
)
|
||||
if entity:
|
||||
entities.append(entity(**discovery_info))
|
||||
|
||||
if entities:
|
||||
async_add_entities(entities, update_before_add=True)
|
||||
|
||||
|
||||
@STRICT_MATCH(channel_names=CHANNEL_POWER_CONFIGURATION)
|
||||
class ZHADeviceScannerEntity(ScannerEntity, ZhaEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue