Add unique IDs to automation/scenes (#31150)
* Add unique IDs to automation and scenes * Fix typo
This commit is contained in:
1 parent
8fff6462a1
commit
1f0f62de7f
14 files changed
+123
-27
No files matched your search
@@ -1,6 +1,7 @@
|
||||
"""Test Automation config panel."""
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import config
|
||||
@@ -47,7 +48,7 @@ async def test_update_device_config(hass, hass_client):
|
||||
|
||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||
"homeassistant.components.config._write", mock_write
|
||||
):
|
||||
), patch("homeassistant.config.async_hass_config_yaml", return_value={}):
|
||||
resp = await client.post(
|
||||
"/api/config/automation/config/moon",
|
||||
data=json.dumps({"trigger": [], "action": [], "condition": []}),
|
||||
@@ -89,11 +90,12 @@ async def test_bad_formatted_automations(hass, hass_client):
|
||||
|
||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||
"homeassistant.components.config._write", mock_write
|
||||
):
|
||||
), patch("homeassistant.config.async_hass_config_yaml", return_value={}):
|
||||
resp = await client.post(
|
||||
"/api/config/automation/config/moon",
|
||||
data=json.dumps({"trigger": [], "action": [], "condition": []}),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert resp.status == 200
|
||||
result = await resp.json()
|
||||
@@ -107,8 +109,31 @@ async def test_bad_formatted_automations(hass, hass_client):
|
||||
|
||||
async def test_delete_automation(hass, hass_client):
|
||||
"""Test deleting an automation."""
|
||||
ent_reg = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"automation",
|
||||
{
|
||||
"automation": [
|
||||
{
|
||||
"id": "sun",
|
||||
"trigger": {"platform": "event", "event_type": "test_event"},
|
||||
"action": {"service": "test.automation"},
|
||||
},
|
||||
{
|
||||
"id": "moon",
|
||||
"trigger": {"platform": "event", "event_type": "test_event"},
|
||||
"action": {"service": "test.automation"},
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
assert len(ent_reg.entities) == 2
|
||||
|
||||
with patch.object(config, "SECTIONS", ["automation"]):
|
||||
await async_setup_component(hass, "config", {})
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
|
||||
client = await hass_client()
|
||||
|
||||
@@ -126,8 +151,9 @@ async def test_delete_automation(hass, hass_client):
|
||||
|
||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||
"homeassistant.components.config._write", mock_write
|
||||
):
|
||||
), patch("homeassistant.config.async_hass_config_yaml", return_value={}):
|
||||
resp = await client.delete("/api/config/automation/config/sun")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert resp.status == 200
|
||||
result = await resp.json()
|
||||
@@ -135,3 +161,5 @@ async def test_delete_automation(hass, hass_client):
|
||||
|
||||
assert len(written) == 1
|
||||
assert written[0][0]["id"] == "moon"
|
||||
|
||||
assert len(ent_reg.entities) == 1
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Test Customize config panel."""
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import config
|
||||
@@ -53,6 +54,8 @@ async def test_update_entity(hass, hass_client):
|
||||
hass.states.async_set("hello.world", "state", {"a": "b"})
|
||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||
"homeassistant.components.config._write", mock_write
|
||||
), patch(
|
||||
"homeassistant.config.async_hass_config_yaml", return_value={},
|
||||
):
|
||||
resp = await client.post(
|
||||
"/api/config/customize/config/hello.world",
|
||||
@@ -60,6 +63,7 @@ async def test_update_entity(hass, hass_client):
|
||||
{"name": "Beer", "entities": ["light.top", "light.bottom"]}
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert resp.status == 200
|
||||
result = await resp.json()
|
||||
|
||||
@@ -61,6 +61,7 @@ async def test_update_device_config(hass, hass_client):
|
||||
{"name": "Beer", "entities": ["light.top", "light.bottom"]}
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert resp.status == 200
|
||||
result = await resp.json()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Test Automation config panel."""
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import config
|
||||
@@ -29,7 +30,7 @@ async def test_update_scene(hass, hass_client):
|
||||
|
||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||
"homeassistant.components.config._write", mock_write
|
||||
):
|
||||
), patch("homeassistant.config.async_hass_config_yaml", return_value={}):
|
||||
resp = await client.post(
|
||||
"/api/config/scene/config/light_off",
|
||||
data=json.dumps(
|
||||
@@ -86,7 +87,7 @@ async def test_bad_formatted_scene(hass, hass_client):
|
||||
|
||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||
"homeassistant.components.config._write", mock_write
|
||||
):
|
||||
), patch("homeassistant.config.async_hass_config_yaml", return_value={}):
|
||||
resp = await client.post(
|
||||
"/api/config/scene/config/light_off",
|
||||
data=json.dumps(
|
||||
@@ -114,8 +115,23 @@ async def test_bad_formatted_scene(hass, hass_client):
|
||||
|
||||
async def test_delete_scene(hass, hass_client):
|
||||
"""Test deleting a scene."""
|
||||
ent_reg = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"scene",
|
||||
{
|
||||
"scene": [
|
||||
{"id": "light_on", "name": "Light on", "entities": {}},
|
||||
{"id": "light_off", "name": "Light off", "entities": {}},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
assert len(ent_reg.entities) == 2
|
||||
|
||||
with patch.object(config, "SECTIONS", ["scene"]):
|
||||
await async_setup_component(hass, "config", {})
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
|
||||
client = await hass_client()
|
||||
|
||||
@@ -133,8 +149,9 @@ async def test_delete_scene(hass, hass_client):
|
||||
|
||||
with patch("homeassistant.components.config._read", mock_read), patch(
|
||||
"homeassistant.components.config._write", mock_write
|
||||
):
|
||||
), patch("homeassistant.config.async_hass_config_yaml", return_value={}):
|
||||
resp = await client.delete("/api/config/scene/config/light_on")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert resp.status == 200
|
||||
result = await resp.json()
|
||||
@@ -142,3 +159,5 @@ async def test_delete_scene(hass, hass_client):
|
||||
|
||||
assert len(written) == 1
|
||||
assert written[0][0]["id"] == "light_off"
|
||||
|
||||
assert len(ent_reg.entities) == 1
|
||||
@@ -3,7 +3,7 @@ import io
|
||||
import unittest
|
||||
|
||||
from homeassistant.components import light, scene
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.setup import async_setup_component, setup_component
|
||||
from homeassistant.util.yaml import loader as yaml_loader
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
@@ -128,3 +128,11 @@ class TestScene(unittest.TestCase):
|
||||
assert self.light_1.is_on
|
||||
assert self.light_2.is_on
|
||||
assert 100 == self.light_2.last_call("turn_on")[1].get("brightness")
|
||||
|
||||
|
||||
async def test_services_registered(hass):
|
||||
"""Test we register services with empty config."""
|
||||
assert await async_setup_component(hass, "scene", {})
|
||||
assert hass.services.has_service("scene", "reload")
|
||||
assert hass.services.has_service("scene", "turn_on")
|
||||
assert hass.services.has_service("scene", "apply")
|
||||
Reference in new issue
Block a user