2018-09-21 17:59:20 +00:00
|
|
|
"""deCONZ cover platform tests."""
|
2019-09-18 10:47:26 +00:00
|
|
|
from copy import deepcopy
|
|
|
|
|
|
|
|
from asynctest import patch
|
2018-09-21 17:59:20 +00:00
|
|
|
|
|
|
|
from homeassistant.components import deconz
|
2018-10-31 21:38:04 +00:00
|
|
|
import homeassistant.components.cover as cover
|
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
|
|
|
|
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",
|
2019-08-27 19:06:14 +00:00
|
|
|
"state": {"bri": 255, "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",
|
2019-08-27 19:06:14 +00:00
|
|
|
"state": {"bri": 255, "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",
|
|
|
|
},
|
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(
|
|
|
|
hass, cover.DOMAIN, {"cover": {"platform": deconz.DOMAIN}}
|
|
|
|
)
|
|
|
|
is True
|
|
|
|
)
|
2018-10-31 21:38:04 +00:00
|
|
|
assert deconz.DOMAIN not in hass.data
|
|
|
|
|
|
|
|
|
|
|
|
async def test_no_covers(hass):
|
2018-09-21 17:59:20 +00:00
|
|
|
"""Test that no cover entities are created."""
|
2020-01-03 17:11:04 +00:00
|
|
|
gateway = await setup_deconz_integration(hass)
|
2019-09-18 10:47:26 +00:00
|
|
|
assert len(gateway.deconz_ids) == 0
|
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-01-03 17:11:04 +00:00
|
|
|
gateway = await setup_deconz_integration(hass, get_state_response=data)
|
2019-09-18 10:47:26 +00:00
|
|
|
assert "cover.level_controllable_cover" in gateway.deconz_ids
|
|
|
|
assert "cover.window_covering_device" in gateway.deconz_ids
|
|
|
|
assert "cover.unsupported_cover" not in gateway.deconz_ids
|
2020-01-07 16:30:53 +00:00
|
|
|
assert len(hass.states.async_all()) == 3
|
2018-10-31 21:38:04 +00:00
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
level_controllable_cover = hass.states.get("cover.level_controllable_cover")
|
|
|
|
assert level_controllable_cover.state == "open"
|
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},
|
|
|
|
}
|
|
|
|
gateway.api.async_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
|
|
|
|
2019-09-18 10:47:26 +00:00
|
|
|
level_controllable_cover = hass.states.get("cover.level_controllable_cover")
|
|
|
|
assert level_controllable_cover.state == "closed"
|
|
|
|
|
2019-12-08 15:53:34 +00:00
|
|
|
level_controllable_cover_device = gateway.api.lights["1"]
|
|
|
|
|
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(
|
|
|
|
cover.DOMAIN,
|
|
|
|
cover.SERVICE_OPEN_COVER,
|
|
|
|
{"entity_id": "cover.level_controllable_cover"},
|
|
|
|
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
|
|
|
|
|
|
|
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(
|
|
|
|
cover.DOMAIN,
|
|
|
|
cover.SERVICE_CLOSE_COVER,
|
|
|
|
{"entity_id": "cover.level_controllable_cover"},
|
|
|
|
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": True, "bri": 255}
|
|
|
|
)
|
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(
|
|
|
|
cover.DOMAIN,
|
|
|
|
cover.SERVICE_STOP_COVER,
|
|
|
|
{"entity_id": "cover.level_controllable_cover"},
|
|
|
|
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
|
|
|
|
|
|
|
await gateway.async_reset()
|
|
|
|
|
2020-01-07 16:30:53 +00:00
|
|
|
assert len(hass.states.async_all()) == 0
|