2018-09-21 19:59:20 +02:00
|
|
|
"""deCONZ cover platform tests."""
|
2019-09-18 12:47:26 +02:00
|
|
|
from copy import deepcopy
|
|
|
|
|
|
|
|
from asynctest import patch
|
2018-09-21 19:59:20 +02:00
|
|
|
|
|
|
|
from homeassistant import config_entries
|
|
|
|
from homeassistant.components import deconz
|
2018-10-31 22:38:04 +01:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
import homeassistant.components.cover as cover
|
2018-09-21 19:59:20 +02:00
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
COVERS = {
|
2018-09-21 19:59:20 +02:00
|
|
|
"1": {
|
2019-09-18 12:47:26 +02:00
|
|
|
"id": "Level controllable cover id",
|
|
|
|
"name": "Level controllable cover",
|
2018-09-21 19:59:20 +02:00
|
|
|
"type": "Level controllable output",
|
2019-08-27 21:06:14 +02:00
|
|
|
"state": {"bri": 255, "on": False, "reachable": True},
|
2018-10-31 22:38:04 +01:00
|
|
|
"modelid": "Not zigbee spec",
|
2019-07-31 12:25:30 -07:00
|
|
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
2018-10-20 15:13:23 +02:00
|
|
|
},
|
|
|
|
"2": {
|
2019-09-18 12:47:26 +02:00
|
|
|
"id": "Window covering device id",
|
|
|
|
"name": "Window covering device",
|
2018-10-20 15:13:23 +02:00
|
|
|
"type": "Window covering device",
|
2019-08-27 21:06:14 +02:00
|
|
|
"state": {"bri": 255, "on": True, "reachable": True},
|
2019-07-31 12:25:30 -07:00
|
|
|
"modelid": "lumi.curtain",
|
2019-09-18 12:47:26 +02:00
|
|
|
"uniqueid": "00:00:00:00:00:00:00:01-00",
|
2019-07-31 12:25:30 -07:00
|
|
|
},
|
2019-09-18 12:47:26 +02:00
|
|
|
"3": {
|
|
|
|
"id": "Unsupported cover id",
|
|
|
|
"name": "Unsupported cover",
|
2018-09-21 19:59:20 +02:00
|
|
|
"type": "Not a cover",
|
2019-09-18 12:47:26 +02:00
|
|
|
"state": {"reachable": True},
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:02-00",
|
|
|
|
},
|
2018-09-21 19:59:20 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
BRIDGEID = "0123456789"
|
2018-09-21 19:59:20 +02:00
|
|
|
|
2018-10-31 22:38:04 +01:00
|
|
|
ENTRY_CONFIG = {
|
|
|
|
deconz.config_flow.CONF_API_KEY: "ABCDEF",
|
2019-09-18 12:47:26 +02:00
|
|
|
deconz.config_flow.CONF_BRIDGEID: BRIDGEID,
|
2018-10-31 22:38:04 +01:00
|
|
|
deconz.config_flow.CONF_HOST: "1.2.3.4",
|
2019-07-31 12:25:30 -07:00
|
|
|
deconz.config_flow.CONF_PORT: 80,
|
2018-10-31 22:38:04 +01:00
|
|
|
}
|
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
DECONZ_CONFIG = {
|
|
|
|
"bridgeid": BRIDGEID,
|
|
|
|
"mac": "00:11:22:33:44:55",
|
|
|
|
"name": "deCONZ mock gateway",
|
|
|
|
"sw_version": "2.05.69",
|
|
|
|
"websocketport": 1234,
|
|
|
|
}
|
2018-10-31 22:38:04 +01:00
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
DECONZ_WEB_REQUEST = {"config": DECONZ_CONFIG}
|
2019-07-31 12:25:30 -07:00
|
|
|
|
2018-10-31 22:38:04 +01:00
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
async def setup_deconz_integration(hass, config, options, get_state_response):
|
|
|
|
"""Create the deCONZ gateway."""
|
2018-09-21 19:59:20 +02:00
|
|
|
config_entry = config_entries.ConfigEntry(
|
2019-09-18 12:47:26 +02:00
|
|
|
version=1,
|
|
|
|
domain=deconz.DOMAIN,
|
|
|
|
title="Mock Title",
|
|
|
|
data=config,
|
|
|
|
source="test",
|
|
|
|
connection_class=config_entries.CONN_CLASS_LOCAL_PUSH,
|
2019-08-18 06:34:11 +02:00
|
|
|
system_options={},
|
2019-09-18 12:47:26 +02:00
|
|
|
options=options,
|
|
|
|
entry_id="1",
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2018-10-31 22:38:04 +01:00
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
with patch(
|
|
|
|
"pydeconz.DeconzSession.async_get_state", return_value=get_state_response
|
|
|
|
), patch("pydeconz.DeconzSession.start", return_value=True):
|
|
|
|
await deconz.async_setup_entry(hass, config_entry)
|
2018-09-21 19:59:20 +02:00
|
|
|
await hass.async_block_till_done()
|
2019-09-18 12:47:26 +02:00
|
|
|
|
|
|
|
hass.config_entries._entries.append(config_entry)
|
|
|
|
|
|
|
|
return hass.data[deconz.DOMAIN][config[deconz.CONF_BRIDGEID]]
|
2018-09-21 19:59:20 +02:00
|
|
|
|
|
|
|
|
2018-10-31 22:38:04 +01: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 12:25:30 -07:00
|
|
|
assert (
|
|
|
|
await async_setup_component(
|
|
|
|
hass, cover.DOMAIN, {"cover": {"platform": deconz.DOMAIN}}
|
|
|
|
)
|
|
|
|
is True
|
|
|
|
)
|
2018-10-31 22:38:04 +01:00
|
|
|
assert deconz.DOMAIN not in hass.data
|
|
|
|
|
|
|
|
|
|
|
|
async def test_no_covers(hass):
|
2018-09-21 19:59:20 +02:00
|
|
|
"""Test that no cover entities are created."""
|
2019-09-18 12:47:26 +02:00
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
gateway = await setup_deconz_integration(
|
|
|
|
hass, ENTRY_CONFIG, options={}, get_state_response=data
|
|
|
|
)
|
|
|
|
assert len(gateway.deconz_ids) == 0
|
2018-09-21 19:59:20 +02:00
|
|
|
assert len(hass.states.async_all()) == 0
|
|
|
|
|
|
|
|
|
|
|
|
async def test_cover(hass):
|
|
|
|
"""Test that all supported cover entities are created."""
|
2019-09-18 12:47:26 +02:00
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
data["lights"] = deepcopy(COVERS)
|
|
|
|
gateway = await setup_deconz_integration(
|
|
|
|
hass, ENTRY_CONFIG, options={}, get_state_response=data
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2019-09-18 12:47:26 +02: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
|
|
|
|
assert len(hass.states.async_all()) == 5
|
2018-10-31 22:38:04 +01:00
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
level_controllable_cover = hass.states.get("cover.level_controllable_cover")
|
|
|
|
assert level_controllable_cover.state == "open"
|
2018-10-31 22:38:04 +01:00
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
level_controllable_cover_device = gateway.api.lights["1"]
|
2018-09-21 19:59:20 +02:00
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
level_controllable_cover_device.async_update({"state": {"on": True}})
|
2018-09-21 19:59:20 +02:00
|
|
|
await hass.async_block_till_done()
|
2018-10-31 22:38:04 +01:00
|
|
|
|
2019-09-18 12:47:26 +02:00
|
|
|
level_controllable_cover = hass.states.get("cover.level_controllable_cover")
|
|
|
|
assert level_controllable_cover.state == "closed"
|
|
|
|
|
|
|
|
with patch.object(
|
|
|
|
level_controllable_cover_device, "_async_set_callback", return_value=True
|
|
|
|
) 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()
|
|
|
|
set_callback.assert_called_with("/lights/1/state", {"on": False})
|
|
|
|
|
|
|
|
with patch.object(
|
|
|
|
level_controllable_cover_device, "_async_set_callback", return_value=True
|
|
|
|
) 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()
|
|
|
|
set_callback.assert_called_with("/lights/1/state", {"on": True, "bri": 255})
|
|
|
|
|
|
|
|
with patch.object(
|
|
|
|
level_controllable_cover_device, "_async_set_callback", return_value=True
|
|
|
|
) 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()
|
|
|
|
set_callback.assert_called_with("/lights/1/state", {"bri_inc": 0})
|