From 561a78bef3c40f23d898c3e428094198ef13e5e0 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 22 Dec 2015 02:19:55 -0800 Subject: [PATCH] Fix EntityComponent deadlock --- homeassistant/helpers/entity_component.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index ec22181bf5a..4cf44737f90 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -113,12 +113,16 @@ class EntityComponent(object): def _update_entity_states(self, now): """ Update the states of all the entities. """ + with self.lock: + # We copy the entities because new entities might be detected + # during state update causing deadlocks. + entities = list(entity for entity in self.entities.values() + if entity.should_poll) + self.logger.info("Updating %s entities", self.domain) - with self.lock: - for entity in self.entities.values(): - if entity.should_poll: - entity.update_ha_state(True) + for entity in entities: + entity.update_ha_state(True) def _entity_discovered(self, service, info): """ Called when a entity is discovered. """