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,7 +4,11 @@ from dynalite_devices_lib.light import DynaliteChannelLightDevice
import pytest
from homeassistant.components.light import SUPPORT_BRIGHTNESS
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_SUPPORTED_FEATURES
from homeassistant.const import (
ATTR_FRIENDLY_NAME,
ATTR_SUPPORTED_FEATURES,
STATE_UNAVAILABLE,
)
from .common import (
ATTR_METHOD,
@ -40,11 +44,21 @@ async def test_light_setup(hass, mock_device):
)
async def test_remove_entity(hass, mock_device):
"""Test when an entity is removed from HA."""
async def test_unload_config_entry(hass, mock_device):
"""Test when a config entry is unloaded from HA."""
await create_entity_from_device(hass, mock_device)
assert hass.states.get("light.name")
entry_id = await get_entry_id_from_hass(hass)
assert await hass.config_entries.async_unload(entry_id)
await hass.async_block_till_done()
assert hass.states.get("light.name").state == STATE_UNAVAILABLE
async def test_remove_config_entry(hass, mock_device):
"""Test when a config entry is removed from HA."""
await create_entity_from_device(hass, mock_device)
assert hass.states.get("light.name")
entry_id = await get_entry_id_from_hass(hass)
assert await hass.config_entries.async_remove(entry_id)
await hass.async_block_till_done()
assert not hass.states.get("light.name")