Improve scene.create service (#28533)

* Improve scene.create service

* Typo

* Improve coverage

* Add from_yaml attribute

* from_service instead of from_yaml
This commit is contained in:
Santobert 2019-11-05 06:15:58 +01:00 committed by Paulus Schoutsen
parent fb0e20543e
commit ef20f0985a
2 changed files with 42 additions and 12 deletions

View file

@ -55,8 +55,13 @@ async def test_apply_service(hass):
async def test_create_service(hass, caplog):
"""Test the create service."""
assert await async_setup_component(hass, "scene", {})
assert await async_setup_component(
hass,
"scene",
{"scene": {"name": "hallo_2", "entities": {"light.kitchen": "on"}}},
)
assert hass.states.get("scene.hallo") is None
assert hass.states.get("scene.hallo_2") is not None
assert await hass.services.async_call(
"scene",
@ -67,8 +72,8 @@ async def test_create_service(hass, caplog):
},
blocking=True,
)
await hass.async_block_till_done()
scene = hass.states.get("scene.hallo")
assert scene is not None
assert scene.domain == "scene"
@ -81,12 +86,34 @@ async def test_create_service(hass, caplog):
"create",
{
"scene_id": "hallo",
"entities": {"light.kitchen_light": {"state": "on", "brightness": 100}},
},
blocking=True,
)
await hass.async_block_till_done()
scene = hass.states.get("scene.hallo")
assert scene is not None
assert scene.domain == "scene"
assert scene.name == "hallo"
assert scene.state == "scening"
assert scene.attributes.get("entity_id") == ["light.kitchen_light"]
assert await hass.services.async_call(
"scene",
"create",
{
"scene_id": "hallo_2",
"entities": {"light.bed_light": {"state": "on", "brightness": 50}},
},
blocking=True,
)
await hass.async_block_till_done()
assert "The scene scene.hallo already exists" in caplog.text
assert hass.states.get("scene.hallo") is not None
assert hass.states.get("scene.hallo_2") is None
assert "The scene scene.hallo_2 already exists" in caplog.text
scene = hass.states.get("scene.hallo_2")
assert scene is not None
assert scene.domain == "scene"
assert scene.name == "hallo_2"
assert scene.state == "scening"
assert scene.attributes.get("entity_id") == ["light.kitchen"]