mirror of
https://github.com/home-assistant/core.git
synced 2026-09-03 12:02:16 +01:00
Report the original error when removing an entity fails (#180481)
This commit is contained in:
@@ -1466,7 +1466,7 @@ class Entity(
|
||||
except BaseException as ex:
|
||||
self.__remove_future.set_exception(ex)
|
||||
raise
|
||||
finally:
|
||||
else:
|
||||
self.__remove_future.set_result(None)
|
||||
|
||||
@final
|
||||
|
||||
@@ -614,6 +614,25 @@ async def test_async_remove_runs_callbacks(hass: HomeAssistant) -> None:
|
||||
assert ent._platform_state == entity.EntityPlatformState.REMOVED
|
||||
|
||||
|
||||
async def test_async_remove_reports_the_original_error(hass: HomeAssistant) -> None:
|
||||
"""Test a failing removal surfaces its own exception."""
|
||||
|
||||
class MockEntityFailingRemoval(entity.Entity):
|
||||
"""Entity that cannot be removed cleanly."""
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Fail while being removed."""
|
||||
raise ValueError("Boom")
|
||||
|
||||
platform = MockEntityPlatform(hass, domain="test")
|
||||
ent = MockEntityFailingRemoval()
|
||||
ent.entity_id = "test.test"
|
||||
await platform.async_add_entities([ent])
|
||||
|
||||
with pytest.raises(ValueError, match="Boom"):
|
||||
await ent.async_remove()
|
||||
|
||||
|
||||
async def test_async_remove_ignores_in_flight_polling(hass: HomeAssistant) -> None:
|
||||
"""Test in flight polling is ignored after removing."""
|
||||
result = []
|
||||
|
||||
Reference in New Issue
Block a user