Refactor ZHA Zigbee channel registry. (#25716)

* Update test to catch regression.

* Refactor ZHA Core channels.

Use channel decorator for Zigbee channel registry.

* Update tests.

* Pylint
This commit is contained in:
Alexei Chetroi authored and Aaron Bach committed 2019-08-05 15:40:29 -06:00
1 parent 8241193fa8
commit 8dbac9176e
17 files changed
+738 -174

No files matched your search

-4
View File
@@ -6,9 +6,6 @@ from homeassistant.components.zha.core.const import DOMAIN, DATA_ZHA, COMPONENTS
from homeassistant.helpers.device_registry import async_get_registry as get_dev_reg
from homeassistant.components.zha.core.gateway import ZHAGateway
from homeassistant.components.zha.core.registries import establish_device_mappings
from homeassistant.components.zha.core.channels.registry import (
populate_channel_registry,
)
from .common import async_setup_entry
from homeassistant.components.zha.core.store import async_get_registry
@@ -29,7 +26,6 @@ async def zha_gateway_fixture(hass, config_entry):
Create a ZHAGateway object that can be used to interact with as if we
had a real zigbee network running.
"""
populate_channel_registry()
establish_device_mappings()
for component in COMPONENTS:
hass.data[DATA_ZHA][component] = hass.data[DATA_ZHA].get(component, {})
+22 -3
View File
@@ -1,9 +1,9 @@
"""Test ZHA Core channels."""
import homeassistant.components.zha.core.channels
import pytest
import zigpy.types as t
import homeassistant.components.zha.core.channels as channels
import homeassistant.components.zha.core.channels.registry as channel_reg
import homeassistant.components.zha.core.device as zha_device
from .common import make_device
@@ -33,6 +33,15 @@ def nwk():
(0x0007, 1, {}),
(0x0008, 1, {"current_level"}),
(0x0009, 1, {}),
(0x000C, 1, {"present_value"}),
(0x000D, 1, {"present_value"}),
(0x000E, 1, {"present_value"}),
(0x000D, 1, {"present_value"}),
(0x0010, 1, {"present_value"}),
(0x0011, 1, {"present_value"}),
(0x0012, 1, {"present_value"}),
(0x0013, 1, {"present_value"}),
(0x0014, 1, {"present_value"}),
(0x0015, 1, {}),
(0x0016, 1, {}),
(0x0019, 1, {}),
@@ -44,8 +53,10 @@ def nwk():
(0x0202, 1, {"fan_mode"}),
(0x0300, 1, {"current_x", "current_y", "color_temperature"}),
(0x0400, 1, {"measured_value"}),
(0x0401, 1, {"level_status"}),
(0x0402, 1, {"measured_value"}),
(0x0403, 1, {"measured_value"}),
(0x0404, 1, {"measured_value"}),
(0x0405, 1, {"measured_value"}),
(0x0406, 1, {"occupancy"}),
(0x0702, 1, {"instantaneous_demand"}),
@@ -66,7 +77,7 @@ async def test_in_channel_config(cluster_id, bind_count, attrs, zha_gateway, has
zha_dev = zha_device.ZHADevice(hass, zigpy_dev, zha_gateway)
cluster = zigpy_dev.endpoints[1].in_clusters[cluster_id]
channel_class = channel_reg.ZIGBEE_CHANNEL_REGISTRY.get(
channel_class = channels.ZIGBEE_CHANNEL_REGISTRY.get(
cluster_id, channels.AttributeListeningChannel
)
channel = channel_class(cluster, zha_dev)
@@ -125,7 +136,7 @@ async def test_out_channel_config(cluster_id, bind_count, zha_gateway, hass):
cluster = zigpy_dev.endpoints[1].out_clusters[cluster_id]
cluster.bind_only = True
channel_class = channel_reg.ZIGBEE_CHANNEL_REGISTRY.get(
channel_class = homeassistant.components.zha.core.channels.ZIGBEE_CHANNEL_REGISTRY.get(
cluster_id, channels.AttributeListeningChannel
)
channel = channel_class(cluster, zha_dev)
@@ -134,3 +145,11 @@ async def test_out_channel_config(cluster_id, bind_count, zha_gateway, hass):
assert cluster.bind.call_count == bind_count
assert cluster.configure_reporting.call_count == 0
def test_channel_registry():
"""Test ZIGBEE Channel Registry."""
for cluster_id, channel in channels.ZIGBEE_CHANNEL_REGISTRY.items():
assert isinstance(cluster_id, int)
assert 0 <= cluster_id <= 0xFFFF
assert issubclass(channel, channels.ZigbeeChannel)