Skip to content

Commit

Permalink
Process events from ZHA Window Covering Remote (home-assistant#36489)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adminiuga authored Jun 5, 2020
1 parent e807274 commit 1c329ff
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
7 changes: 6 additions & 1 deletion homeassistant/components/zha/core/channels/closures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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__)

Expand Down Expand Up @@ -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."""
Expand Down
52 changes: 50 additions & 2 deletions tests/components/zha/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@
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
Expand All @@ -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."""
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tests/components/zha/zha_devices_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@
"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",
Expand Down

0 comments on commit 1c329ff

Please sign in to comment.