mirror of
https://github.com/home-assistant/core.git
synced 2025-11-12 20:40:18 +00:00
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:
@@ -3,6 +3,7 @@ from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
from homeassistant.components.homekit_controller.const import KNOWN_DEVICES
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
|
||||
from tests.components.homekit_controller.common import setup_test_component
|
||||
|
||||
@@ -209,8 +210,8 @@ async def test_light_becomes_unavailable_but_recovers(hass, utcnow):
|
||||
assert state.attributes["color_temp"] == 400
|
||||
|
||||
|
||||
async def test_light_unloaded(hass, utcnow):
|
||||
"""Test entity and HKDevice are correctly unloaded."""
|
||||
async def test_light_unloaded_removed(hass, utcnow):
|
||||
"""Test entity and HKDevice are correctly unloaded and removed."""
|
||||
helper = await setup_test_component(hass, create_lightbulb_service_with_color_temp)
|
||||
|
||||
# Initial state is that the light is off
|
||||
@@ -220,9 +221,15 @@ async def test_light_unloaded(hass, utcnow):
|
||||
unload_result = await helper.config_entry.async_unload(hass)
|
||||
assert unload_result is True
|
||||
|
||||
# Make sure entity is unloaded
|
||||
assert hass.states.get(helper.entity_id) is None
|
||||
# Make sure entity is set to unavailable state
|
||||
assert hass.states.get(helper.entity_id).state == STATE_UNAVAILABLE
|
||||
|
||||
# Make sure HKDevice is no longer set to poll this accessory
|
||||
conn = hass.data[KNOWN_DEVICES]["00:00:00:00:00:00"]
|
||||
assert not conn.pollable_characteristics
|
||||
|
||||
await helper.config_entry.async_remove(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Make sure entity is removed
|
||||
assert hass.states.get(helper.entity_id).state == STATE_UNAVAILABLE
|
||||
|
||||
Reference in New Issue
Block a user