Mark entities as unavailable when they are removed but are still registered (#45528)

* Mark entities as unavailable when they are removed but are still registered

* Add sync_entity_lifecycle to collection helper

* Remove debug print

* Lint

* Fix tests

* Fix tests

* Update zha

* Update zone

* Fix tests

* Update hyperion

* Update rfxtrx

* Fix tests

* Pass force_remove=True from integrations

Co-authored-by: Erik <erik@montnemery.com>
This commit is contained in:
Paulus Schoutsen 2021-02-08 10:45:46 +01:00 committed by GitHub
parent aa005af266
commit 9e07910ab0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
73 changed files with 439 additions and 222 deletions

View file

@ -4,6 +4,7 @@ from unittest.mock import patch
from homeassistant import config_entries
from homeassistant.components.hassio.handler import HassioAPIError
from homeassistant.components.ozw import DOMAIN, PLATFORMS, const
from homeassistant.const import ATTR_RESTORED, STATE_UNAVAILABLE
from .common import setup_ozw
@ -76,14 +77,21 @@ async def test_unload_entry(hass, generic_data, switch_msg, caplog):
await hass.config_entries.async_unload(entry.entry_id)
assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED
assert len(hass.states.async_entity_ids("switch")) == 0
entities = hass.states.async_entity_ids("switch")
assert len(entities) == 1
for entity in entities:
assert hass.states.get(entity).state == STATE_UNAVAILABLE
assert hass.states.get(entity).attributes.get(ATTR_RESTORED)
# Send a message for a switch from the broker to check that
# all entity topic subscribers are unsubscribed.
receive_message(switch_msg)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids("switch")) == 0
assert len(hass.states.async_entity_ids("switch")) == 1
for entity in entities:
assert hass.states.get(entity).state == STATE_UNAVAILABLE
assert hass.states.get(entity).attributes.get(ATTR_RESTORED)
# Load the integration again and check that there are no errors when
# adding the entities.