From 30094acec7b1a3afb571d91e5f64f9dbb2e75a3e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 26 Feb 2024 10:47:08 -1000 Subject: [PATCH] Fix dict changing size during iteration in deconz (#111523) --- homeassistant/components/deconz/gateway.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index a982d110f1f..a9286cca112 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -301,7 +301,10 @@ class DeconzGateway: entity_registry = er.async_get(self.hass) - for entity_id, deconz_id in self.deconz_ids.items(): + # Copy the ids since calling async_remove will modify the dict + # and will cause a runtime error because the dict size changes + # during iteration + for entity_id, deconz_id in self.deconz_ids.copy().items(): if deconz_id in deconz_ids and entity_registry.async_is_registered( entity_id ):