Reload config entry when entity enabled in entity registry, remove entity if disabled. (#26120)

* Reload config entry when disabled_by updated in entity registry

* Add types

* Remove entities that get disabled

* Remove unnecessary domain checks.

* Attach handler in async_setup

* Remove unused var

* Type

* Fix test

* Fix tests
This commit is contained in:
Paulus Schoutsen committed 2019-08-25 22:37:25 -07:00
1 parent 05ed3c44ea
commit 65cf5a6ef5
7 files changed
+219 -12

No files matched your search

+31
View File
@@ -526,3 +526,34 @@ async def test_warn_disabled(hass, caplog):
ent.async_write_ha_state()
assert hass.states.get("hello.world") is None
assert caplog.text == ""
async def test_disabled_in_entity_registry(hass):
"""Test entity is removed if we disable entity registry entry."""
entry = entity_registry.RegistryEntry(
entity_id="hello.world",
unique_id="test-unique-id",
platform="test-platform",
disabled_by="user",
)
registry = mock_registry(hass, {"hello.world": entry})
ent = entity.Entity()
ent.hass = hass
ent.entity_id = "hello.world"
ent.registry_entry = entry
ent.platform = MagicMock(platform_name="test-platform")
await ent.async_internal_added_to_hass()
ent.async_write_ha_state()
assert hass.states.get("hello.world") is None
entry2 = registry.async_update_entity("hello.world", disabled_by=None)
await hass.async_block_till_done()
assert entry2 != entry
assert ent.registry_entry == entry2
entry3 = registry.async_update_entity("hello.world", disabled_by="user")
await hass.async_block_till_done()
assert entry3 != entry2
assert ent.registry_entry == entry3