From 3d6cfc001861217b6d97066557847035ce14f835 Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 11 Jun 2025 21:05:57 +0200 Subject: [PATCH] Don't clear entity_sources when removing an entity which is in the registry --- homeassistant/helpers/entity.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index ad029633f8e..3fad826303d 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -1424,6 +1424,10 @@ class Entity( self.registry_entry.write_unavailable_state(self.hass) else: self.hass.states.async_remove(self.entity_id, context=self._context) + # The check for self.platform guards against integrations not using an + # EntityComponent and can be removed in HA Core 2024.1 + if self.platform: + del entity_sources(self.hass)[self.entity_id] async def async_added_to_hass(self) -> None: """Run when entity about to be added to hass. @@ -1482,10 +1486,6 @@ class Entity( Not to be extended by integrations. """ - # The check for self.platform guards against integrations not using an - # EntityComponent and can be removed in HA Core 2024.1 - if self.platform: - del entity_sources(self.hass)[self.entity_id] @callback def _async_registry_updated(