2018-09-21 17:59:20 +00:00
|
|
|
"""deCONZ cover platform tests."""
|
2020-10-17 16:20:06 +00:00
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
from copy import deepcopy
|
|
|
|
|
2020-10-17 16:20:06 +00:00
|
|
|
from homeassistant.components.cover import (
|
|
|
|
DOMAIN as COVER_DOMAIN,
|
|
|
|
SERVICE_CLOSE_COVER,
|
|
|
|
SERVICE_OPEN_COVER,
|
|
|
|
SERVICE_STOP_COVER,
|
|
|
|
)
|
|
|
|
from homeassistant.components.deconz.const import DOMAIN as DECONZ_DOMAIN
|
2020-10-06 21:25:57 +00:00
|
|
|
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
|
2020-10-17 16:20:06 +00:00
|
|
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_CLOSED, STATE_OPEN
|
2019-12-09 11:25:35 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2018-09-21 17:59:20 +00:00
|
|
|
|
2020-01-03 17:11:04 +00:00
|
|
|
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
2019-09-19 21:44:09 +00:00
|
|
|
|
2020-04-30 20:29:50 +00:00
|
|
|
from tests.async_mock import patch
|
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
COVERS = {
|
2018-09-21 17:59:20 +00:00
|
|
|
"1": {
|
2019-09-18 10:47:26 +00:00
|
|
|
"id": "Level controllable cover id",
|
|
|
|
"name": "Level controllable cover",
|
2018-09-21 17:59:20 +00:00
|
|
|
"type": "Level controllable output",
|
2020-03-16 14:44:59 +00:00
|
|
|
"state": {"bri": 254, "on": False, "reachable": True},
|
2018-10-31 21:38:04 +00:00
|
|
|
"modelid": "Not zigbee spec",
|
2019-07-31 19:25:30 +00:00
|
|
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
2018-10-20 13:13:23 +00:00
|
|
|
},
|
|
|
|
"2": {
|
2019-09-18 10:47:26 +00:00
|
|
|
"id": "Window covering device id",
|
|
|
|
"name": "Window covering device",
|
2018-10-20 13:13:23 +00:00
|
|
|
"type": "Window covering device",
|
2020-03-16 14:44:59 +00:00
|
|
|
"state": {"bri": 254, "on": True, "reachable": True},
|
2019-07-31 19:25:30 +00:00
|
|
|
"modelid": "lumi.curtain",
|
2019-09-18 10:47:26 +00:00
|
|
|
"uniqueid": "00:00:00:00:00:00:00:01-00",
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
2019-09-18 10:47:26 +00:00
|
|
|
"3": {
|
|
|
|
"id": "Unsupported cover id",
|
|
|
|
"name": "Unsupported cover",
|
2018-09-21 17:59:20 +00:00
|
|
|
"type": "Not a cover",
|
2019-09-18 10:47:26 +00:00
|
|
|
"state": {"reachable": True},
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:02-00",
|
|
|
|
},
|
2020-03-16 14:44:59 +00:00
|
|
|
"4": {
|
|
|
|
"id": "deconz old brightness cover id",
|
|
|
|
"name": "deconz old brightness cover",
|
|
|
|
"type": "Level controllable output",
|
|
|
|
"state": {"bri": 255, "on": False, "reachable": True},
|
|
|
|
"modelid": "Not zigbee spec",
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:03-00",
|
|
|
|
},
|
2020-05-17 07:57:24 +00:00
|
|
|
"5": {
|
|
|
|
"id": "Window covering controller id",
|
|
|
|
"name": "Window covering controller",
|
|
|
|
"type": "Window covering controller",
|
|
|
|
"state": {"bri": 254, "on": True, "reachable": True},
|
|
|
|
"modelid": "Motor controller",
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:04-00",
|
|
|
|
},
|
2018-09-21 17:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-31 21:38:04 +00:00
|
|
|
async def test_platform_manually_configured(hass):
|
|
|
|
"""Test that we do not discover anything or try to set up a gateway."""
|
2019-07-31 19:25:30 +00:00
|
|
|
assert (
|
|
|
|
await async_setup_component(
|
2020-10-17 16:20:06 +00:00
|
|
|
hass, COVER_DOMAIN, {"cover": {"platform": DECONZ_DOMAIN}}
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
|
|
|
is True
|
|
|
|
)
|
2020-10-17 16:20:06 +00:00
|
|
|
assert DECONZ_DOMAIN not in hass.data
|
2018-10-31 21:38:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_no_covers(hass):
|
2018-09-21 17:59:20 +00:00
|
|
|
"""Test that no cover entities are created."""
|
2020-10-02 09:20:33 +00:00
|
|
|
await setup_deconz_integration(hass)
|
2018-09-21 17:59:20 +00:00
|
|
|
assert len(hass.states.async_all()) == 0
|
|
|
|
|
|
|
|
|
|
|
|
async def test_cover(hass):
|
|
|
|
"""Test that all supported cover entities are created."""
|
2019-09-18 10:47:26 +00:00
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
data["lights"] = deepcopy(COVERS)
|
2020-10-06 21:25:57 +00:00
|
|
|
config_entry = await setup_deconz_integration(hass, get_state_response=data)
|
|
|
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
2020-10-02 09:20:33 +00:00
|
|
|
|
2020-05-17 07:57:24 +00:00
|
|
|
assert len(hass.states.async_all()) == 5
|
2020-10-17 16:20:06 +00:00
|
|
|
assert hass.states.get("cover.level_controllable_cover").state == STATE_OPEN
|
|
|
|
assert hass.states.get("cover.window_covering_device").state == STATE_CLOSED
|
2020-10-02 09:20:33 +00:00
|
|
|
assert hass.states.get("cover.unsupported_cover") is None
|
2020-10-17 16:20:06 +00:00
|
|
|
assert hass.states.get("cover.deconz_old_brightness_cover").state == STATE_OPEN
|
|
|
|
assert hass.states.get("cover.window_covering_controller").state == STATE_CLOSED
|
2018-10-31 21:38:04 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Event signals cover is closed
|
2018-10-31 21:38:04 +00:00
|
|
|
|
2019-12-08 15:53:34 +00:00
|
|
|
state_changed_event = {
|
|
|
|
"t": "event",
|
|
|
|
"e": "changed",
|
|
|
|
"r": "lights",
|
|
|
|
"id": "1",
|
|
|
|
"state": {"on": True},
|
|
|
|
}
|
2020-02-02 18:07:20 +00:00
|
|
|
gateway.api.event_handler(state_changed_event)
|
2018-09-21 17:59:20 +00:00
|
|
|
await hass.async_block_till_done()
|
2018-10-31 21:38:04 +00:00
|
|
|
|
2020-10-17 16:20:06 +00:00
|
|
|
assert hass.states.get("cover.level_controllable_cover").state == STATE_CLOSED
|
2020-10-02 09:20:33 +00:00
|
|
|
|
|
|
|
# Verify service calls
|
2019-09-18 10:47:26 +00:00
|
|
|
|
2019-12-08 15:53:34 +00:00
|
|
|
level_controllable_cover_device = gateway.api.lights["1"]
|
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Service open cover
|
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
with patch.object(
|
2019-12-08 15:53:34 +00:00
|
|
|
level_controllable_cover_device, "_request", return_value=True
|
2019-09-18 10:47:26 +00:00
|
|
|
) as set_callback:
|
|
|
|
await hass.services.async_call(
|
2020-10-17 16:20:06 +00:00
|
|
|
COVER_DOMAIN,
|
|
|
|
SERVICE_OPEN_COVER,
|
|
|
|
{ATTR_ENTITY_ID: "cover.level_controllable_cover"},
|
2019-09-18 10:47:26 +00:00
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
2019-12-08 15:53:34 +00:00
|
|
|
set_callback.assert_called_with("put", "/lights/1/state", json={"on": False})
|
2019-09-18 10:47:26 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Service close cover
|
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
with patch.object(
|
2019-12-08 15:53:34 +00:00
|
|
|
level_controllable_cover_device, "_request", return_value=True
|
2019-09-18 10:47:26 +00:00
|
|
|
) as set_callback:
|
|
|
|
await hass.services.async_call(
|
2020-10-17 16:20:06 +00:00
|
|
|
COVER_DOMAIN,
|
|
|
|
SERVICE_CLOSE_COVER,
|
|
|
|
{ATTR_ENTITY_ID: "cover.level_controllable_cover"},
|
2019-09-18 10:47:26 +00:00
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
2019-12-08 15:53:34 +00:00
|
|
|
set_callback.assert_called_with(
|
2020-03-16 14:44:59 +00:00
|
|
|
"put", "/lights/1/state", json={"on": True, "bri": 254}
|
2019-12-08 15:53:34 +00:00
|
|
|
)
|
2019-09-18 10:47:26 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Service stop cover movement
|
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
with patch.object(
|
2019-12-08 15:53:34 +00:00
|
|
|
level_controllable_cover_device, "_request", return_value=True
|
2019-09-18 10:47:26 +00:00
|
|
|
) as set_callback:
|
|
|
|
await hass.services.async_call(
|
2020-10-17 16:20:06 +00:00
|
|
|
COVER_DOMAIN,
|
|
|
|
SERVICE_STOP_COVER,
|
|
|
|
{ATTR_ENTITY_ID: "cover.level_controllable_cover"},
|
2019-09-18 10:47:26 +00:00
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
2019-12-08 15:53:34 +00:00
|
|
|
set_callback.assert_called_with("put", "/lights/1/state", json={"bri_inc": 0})
|
2019-09-19 21:44:09 +00:00
|
|
|
|
2020-04-06 10:51:48 +00:00
|
|
|
# Test that a reported cover position of 255 (deconz-rest-api < 2.05.73) is interpreted correctly.
|
2020-10-17 16:20:06 +00:00
|
|
|
assert hass.states.get("cover.deconz_old_brightness_cover").state == STATE_OPEN
|
2020-03-16 14:44:59 +00:00
|
|
|
|
|
|
|
state_changed_event = {
|
|
|
|
"t": "event",
|
|
|
|
"e": "changed",
|
|
|
|
"r": "lights",
|
|
|
|
"id": "4",
|
|
|
|
"state": {"on": True},
|
|
|
|
}
|
|
|
|
gateway.api.event_handler(state_changed_event)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
deconz_old_brightness_cover = hass.states.get("cover.deconz_old_brightness_cover")
|
2020-10-17 16:20:06 +00:00
|
|
|
assert deconz_old_brightness_cover.state == STATE_CLOSED
|
2020-03-16 14:44:59 +00:00
|
|
|
assert deconz_old_brightness_cover.attributes["current_position"] == 0
|
|
|
|
|
2020-10-06 21:25:57 +00:00
|
|
|
await hass.config_entries.async_unload(config_entry.entry_id)
|
2019-09-19 21:44:09 +00:00
|
|
|
|
2020-01-07 16:30:53 +00:00
|
|
|
assert len(hass.states.async_all()) == 0
|