mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Fix GDACS integration to remove stale entities from entity registry (#33283)
* remove entities from entity registry * added test for removing entities from entity registry
This commit is contained in:
parent
558cccc68c
commit
a38db1f677
@ -11,6 +11,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_registry import async_get_registry
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from .const import DEFAULT_ICON, DOMAIN, FEED
|
||||
@ -107,6 +108,9 @@ class GdacsEvent(GeolocationEvent):
|
||||
"""Call when entity will be removed from hass."""
|
||||
self._remove_signal_delete()
|
||||
self._remove_signal_update()
|
||||
# Remove from entity registry.
|
||||
entity_registry = await async_get_registry(self.hass)
|
||||
entity_registry.async_remove(self.entity_id)
|
||||
|
||||
@callback
|
||||
def _delete_callback(self):
|
||||
|
@ -29,6 +29,7 @@ from homeassistant.const import (
|
||||
CONF_RADIUS,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
)
|
||||
from homeassistant.helpers.entity_registry import async_get_registry
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
@ -97,6 +98,8 @@ async def test_setup(hass):
|
||||
all_states = hass.states.async_all()
|
||||
# 3 geolocation and 1 sensor entities
|
||||
assert len(all_states) == 4
|
||||
entity_registry = await async_get_registry(hass)
|
||||
assert len(entity_registry.entities) == 4
|
||||
|
||||
state = hass.states.get("geo_location.drought_name_1")
|
||||
assert state is not None
|
||||
@ -184,6 +187,7 @@ async def test_setup(hass):
|
||||
|
||||
all_states = hass.states.async_all()
|
||||
assert len(all_states) == 1
|
||||
assert len(entity_registry.entities) == 1
|
||||
|
||||
|
||||
async def test_setup_imperial(hass):
|
||||
|
Loading…
x
Reference in New Issue
Block a user