2018-10-31 21:38:04 +00:00
|
|
|
"""deCONZ scene platform tests."""
|
2020-10-17 16:20:06 +00:00
|
|
|
|
2019-09-19 21:44:09 +00:00
|
|
|
from copy import deepcopy
|
|
|
|
|
2020-10-17 16:20:06 +00:00
|
|
|
from homeassistant.components.deconz 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.components.scene import DOMAIN as SCENE_DOMAIN, SERVICE_TURN_ON
|
|
|
|
from homeassistant.const import ATTR_ENTITY_ID
|
2019-12-09 11:25:35 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2018-04-23 16:00:16 +00:00
|
|
|
|
2020-01-03 17:11:04 +00:00
|
|
|
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
2018-04-23 16:00:16 +00:00
|
|
|
|
2020-04-30 20:29:50 +00:00
|
|
|
from tests.async_mock import patch
|
|
|
|
|
2019-09-19 21:44:09 +00:00
|
|
|
GROUPS = {
|
2018-04-23 16:00:16 +00:00
|
|
|
"1": {
|
2019-09-19 21:44:09 +00:00
|
|
|
"id": "Light group id",
|
|
|
|
"name": "Light group",
|
|
|
|
"type": "LightGroup",
|
|
|
|
"state": {"all_on": False, "any_on": True},
|
2018-04-23 16:00:16 +00:00
|
|
|
"action": {},
|
2019-09-19 21:44:09 +00:00
|
|
|
"scenes": [{"id": "1", "name": "Scene"}],
|
2019-02-18 16:43:22 +00:00
|
|
|
"lights": [],
|
2018-04-23 16:00:16 +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, SCENE_DOMAIN, {"scene": {"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
|
|
|
|
|
|
|
|
2018-04-23 16:00:16 +00:00
|
|
|
async def test_no_scenes(hass):
|
2018-10-31 21:38:04 +00:00
|
|
|
"""Test that scenes can be loaded without scenes being available."""
|
2020-10-02 09:20:33 +00:00
|
|
|
await setup_deconz_integration(hass)
|
2018-04-23 16:00:16 +00:00
|
|
|
assert len(hass.states.async_all()) == 0
|
|
|
|
|
|
|
|
|
|
|
|
async def test_scenes(hass):
|
2018-10-31 21:38:04 +00:00
|
|
|
"""Test that scenes works."""
|
2019-09-19 21:44:09 +00:00
|
|
|
data = deepcopy(DECONZ_WEB_REQUEST)
|
|
|
|
data["groups"] = deepcopy(GROUPS)
|
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)
|
2019-09-19 21:44:09 +00:00
|
|
|
|
2018-04-23 16:00:16 +00:00
|
|
|
assert len(hass.states.async_all()) == 1
|
2020-10-02 09:20:33 +00:00
|
|
|
assert hass.states.get("scene.light_group_scene")
|
2018-10-31 21:38:04 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Verify service calls
|
2018-10-31 21:38:04 +00:00
|
|
|
|
2019-09-19 21:44:09 +00:00
|
|
|
group_scene = gateway.api.groups["1"].scenes["1"]
|
2018-10-31 21:38:04 +00:00
|
|
|
|
2020-10-02 09:20:33 +00:00
|
|
|
# Service turn on scene
|
|
|
|
|
2019-12-08 15:53:34 +00:00
|
|
|
with patch.object(group_scene, "_request", return_value=True) as set_callback:
|
2019-09-19 21:44:09 +00:00
|
|
|
await hass.services.async_call(
|
2020-10-17 16:20:06 +00:00
|
|
|
SCENE_DOMAIN,
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
{ATTR_ENTITY_ID: "scene.light_group_scene"},
|
|
|
|
blocking=True,
|
2019-09-19 21:44:09 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
2019-12-08 15:53:34 +00:00
|
|
|
set_callback.assert_called_with("put", "/groups/1/scenes/1/recall", json={})
|
2018-10-31 21:38:04 +00:00
|
|
|
|
2020-10-06 21:25:57 +00:00
|
|
|
await hass.config_entries.async_unload(config_entry.entry_id)
|
2018-10-31 21:38:04 +00:00
|
|
|
|
|
|
|
assert len(hass.states.async_all()) == 0
|