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:
parent
a4eeaac24c
commit
f704a8e90e
7 changed files with 219 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue