From 287fca093fea4f7f24cda9a66d1fbeb03dcd1fee Mon Sep 17 00:00:00 2001 From: Maciej <38075949+maciej-or@users.noreply.github.com> Date: Fri, 29 Nov 2024 19:29:06 +0100 Subject: [PATCH] migration fix (#269) --- custom_components/hikvision_next/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/hikvision_next/__init__.py b/custom_components/hikvision_next/__init__.py index 33e404d..bb7f916 100644 --- a/custom_components/hikvision_next/__init__.py +++ b/custom_components/hikvision_next/__init__.py @@ -136,7 +136,9 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry): entity_registry = er.async_get(hass) for key in old_keys: entity_id = f"sensor.{slugify(config_entry.unique_id)}_alarm_server_{key}" - entity_registry.async_remove(entity_id) + entity = entity_registry.async_get(entity_id) + if entity: + entity_registry.async_remove(entity_id) hass.config_entries.async_update_entry( config_entry,