1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add unique IDs to automation/scenes (#31150)

* Add unique IDs to automation and scenes

* Fix typo
This commit is contained in:
Paulus Schoutsen
2020-01-26 23:01:35 -08:00
committed by GitHub
parent 8fff6462a1
commit 1f0f62de7f
14 changed files with 123 additions and 27 deletions

View File

@@ -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