From 1c329ff708130a0c622314c83d805d1269e6cf29 Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Fri, 5 Jun 2020 17:11:46 -0400 Subject: [PATCH] Process events from ZHA Window Covering Remote (#36489) --- .../components/zha/core/channels/closures.py | 7 ++- tests/components/zha/test_cover.py | 52 ++++++++++++++++++- tests/components/zha/zha_devices_list.py | 2 +- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/zha/core/channels/closures.py b/homeassistant/components/zha/core/channels/closures.py index 826c99fbd3b..5641deffb60 100644 --- a/homeassistant/components/zha/core/channels/closures.py +++ b/homeassistant/components/zha/core/channels/closures.py @@ -7,7 +7,7 @@ from homeassistant.core import callback from .. import registries from ..const import REPORT_CONFIG_IMMEDIATE, SIGNAL_ATTR_UPDATED -from .base import ZigbeeChannel +from .base import ClientChannel, ZigbeeChannel _LOGGER = logging.getLogger(__name__) @@ -50,6 +50,11 @@ class Shade(ZigbeeChannel): """Shade channel.""" +@registries.CLIENT_CHANNELS_REGISTRY.register(closures.WindowCovering.cluster_id) +class WindowCoveringClient(ClientChannel): + """Window client channel.""" + + @registries.ZIGBEE_CHANNEL_REGISTRY.register(closures.WindowCovering.cluster_id) class WindowCovering(ZigbeeChannel): """Window channel.""" diff --git a/tests/components/zha/test_cover.py b/tests/components/zha/test_cover.py index c3404a2bb83..2c497f6880f 100644 --- a/tests/components/zha/test_cover.py +++ b/tests/components/zha/test_cover.py @@ -15,18 +15,24 @@ from homeassistant.components.cover import ( SERVICE_SET_COVER_POSITION, SERVICE_STOP_COVER, ) -from homeassistant.const import STATE_CLOSED, STATE_OPEN, STATE_UNAVAILABLE +from homeassistant.const import ( + ATTR_COMMAND, + STATE_CLOSED, + STATE_OPEN, + STATE_UNAVAILABLE, +) from homeassistant.core import CoreState, State from .common import ( async_enable_traffic, async_test_rejoin, find_entity_id, + make_zcl_header, send_attributes_report, ) from tests.async_mock import AsyncMock, MagicMock, call, patch -from tests.common import mock_coro, mock_restore_cache +from tests.common import async_capture_events, mock_coro, mock_restore_cache @pytest.fixture @@ -43,6 +49,20 @@ def zigpy_cover_device(zigpy_device_mock): return zigpy_device_mock(endpoints) +@pytest.fixture +def zigpy_cover_remote(zigpy_device_mock): + """Zigpy cover remote device.""" + + endpoints = { + 1: { + "device_type": 0x0203, + "in_clusters": [], + "out_clusters": [closures.WindowCovering.cluster_id], + } + } + return zigpy_device_mock(endpoints) + + @pytest.fixture def zigpy_shade_device(zigpy_device_mock): """Zigpy shade device.""" @@ -375,3 +395,31 @@ async def test_keen_vent(hass, zha_device_joined_restored, zigpy_keen_vent): assert cluster_level.request.call_count == 1 assert hass.states.get(entity_id).state == STATE_OPEN assert hass.states.get(entity_id).attributes[ATTR_CURRENT_POSITION] == 100 + + +async def test_cover_remote(hass, zha_device_joined_restored, zigpy_cover_remote): + """Test zha cover remote.""" + + # load up cover domain + await zha_device_joined_restored(zigpy_cover_remote) + + cluster = zigpy_cover_remote.endpoints[1].out_clusters[ + closures.WindowCovering.cluster_id + ] + zha_events = async_capture_events(hass, "zha_event") + + # up command + hdr = make_zcl_header(0, global_command=False) + cluster.handle_message(hdr, []) + await hass.async_block_till_done() + + assert len(zha_events) == 1 + assert zha_events[0].data[ATTR_COMMAND] == "up_open" + + # down command + hdr = make_zcl_header(1, global_command=False) + cluster.handle_message(hdr, []) + await hass.async_block_till_done() + + assert len(zha_events) == 2 + assert zha_events[1].data[ATTR_COMMAND] == "down_close" diff --git a/tests/components/zha/zha_devices_list.py b/tests/components/zha/zha_devices_list.py index 0b1ec9ae2c6..d4ea1377d97 100644 --- a/tests/components/zha/zha_devices_list.py +++ b/tests/components/zha/zha_devices_list.py @@ -813,7 +813,7 @@ DEVICES = [ "entity_id": "sensor.ikea_of_sweden_tradfri_on_off_switch_77665544_power", } }, - "event_channels": ["1:0x0006", "1:0x0008", "1:0x0019"], + "event_channels": ["1:0x0006", "1:0x0008", "1:0x0019", "1:0x0102"], "manufacturer": "IKEA of Sweden", "model": "TRADFRI on/off switch", "node_descriptor": b"\x02@\x80|\x11RR\x00\x00,R\x00\x00",