Remove entity registry entries when script is removed (#71193)

This commit is contained in:
Erik Montnemery
2022-05-02 13:15:19 +02:00
committed by GitHub
parent 738701a2d6
commit 546ba8169d
4 changed files with 33 additions and 6 deletions

View File

@@ -6,21 +6,34 @@ import pytest
from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
from homeassistant.helpers import entity_registry as er
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture(autouse=True)
async def setup_script(hass, stub_blueprint_populate): # noqa: F811
async def setup_script(hass, script_config, stub_blueprint_populate): # noqa: F811
"""Set up script integration."""
assert await async_setup_component(hass, "script", {})
assert await async_setup_component(hass, "script", {"script": script_config})
@pytest.mark.parametrize(
"script_config",
(
{
"one": {"alias": "Light on", "sequence": []},
"two": {"alias": "Light off", "sequence": []},
},
),
)
async def test_delete_script(hass, hass_client):
"""Test deleting a script."""
with patch.object(config, "SECTIONS", ["script"]):
await async_setup_component(hass, "config", {})
ent_reg = er.async_get(hass)
assert len(ent_reg.entities) == 2
client = await hass_client()
orig_data = {"one": {}, "two": {}}
@@ -46,3 +59,5 @@ async def test_delete_script(hass, hass_client):
assert len(written) == 1
assert written[0] == {"one": {}}
assert len(ent_reg.entities) == 1