Fix EntityComponent deadlock
This commit is contained in:
parent
9876a2a081
commit
561a78bef3
1 changed files with 8 additions and 4 deletions
|
@ -113,12 +113,16 @@ class EntityComponent(object):
|
||||||
|
|
||||||
def _update_entity_states(self, now):
|
def _update_entity_states(self, now):
|
||||||
""" Update the states of all the entities. """
|
""" 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)
|
self.logger.info("Updating %s entities", self.domain)
|
||||||
|
|
||||||
with self.lock:
|
for entity in entities:
|
||||||
for entity in self.entities.values():
|
entity.update_ha_state(True)
|
||||||
if entity.should_poll:
|
|
||||||
entity.update_ha_state(True)
|
|
||||||
|
|
||||||
def _entity_discovered(self, service, info):
|
def _entity_discovered(self, service, info):
|
||||||
""" Called when a entity is discovered. """
|
""" Called when a entity is discovered. """
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue