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:
Alexei Chetroi 2019-12-31 11:09:58 -05:00 committed by David F. Mulcahey
parent 5ed44297e6
commit a3061bda60
13 changed files with 2152 additions and 80 deletions

View file

@ -28,7 +28,7 @@ from .core.const import (
SIGNAL_ATTR_UPDATED,
ZHA_DISCOVERY_NEW,
)
from .core.registries import ZHA_ENTITIES, MatchRule
from .core.registries import ZHA_ENTITIES
from .entity import ZhaEntity
_LOGGER = logging.getLogger(__name__)
@ -85,7 +85,8 @@ async def _async_setup_entities(
if entity:
entities.append(entity(**discovery_info))
async_add_entities(entities, update_before_add=True)
if entities:
async_add_entities(entities, update_before_add=True)
class BinarySensor(ZhaEntity, BinarySensorDevice):
@ -141,28 +142,28 @@ class BinarySensor(ZhaEntity, BinarySensorDevice):
self._state = await self._channel.get_attribute_value(attribute)
@STRICT_MATCH(MatchRule(channel_names={CHANNEL_ACCELEROMETER}))
@STRICT_MATCH(channel_names=CHANNEL_ACCELEROMETER)
class Accelerometer(BinarySensor):
"""ZHA BinarySensor."""
DEVICE_CLASS = DEVICE_CLASS_MOVING
@STRICT_MATCH(MatchRule(channel_names={CHANNEL_OCCUPANCY}))
@STRICT_MATCH(channel_names=CHANNEL_OCCUPANCY)
class Occupancy(BinarySensor):
"""ZHA BinarySensor."""
DEVICE_CLASS = DEVICE_CLASS_OCCUPANCY
@STRICT_MATCH(MatchRule(channel_names={CHANNEL_ON_OFF}))
@STRICT_MATCH(channel_names=CHANNEL_ON_OFF)
class Opening(BinarySensor):
"""ZHA BinarySensor."""
DEVICE_CLASS = DEVICE_CLASS_OPENING
@STRICT_MATCH(MatchRule(channel_names={CHANNEL_ZONE}))
@STRICT_MATCH(channel_names=CHANNEL_ZONE)
class IASZone(BinarySensor):
"""ZHA IAS BinarySensor."""