Hotfix deadlock on platform setup (#4354)
* Hotfix deadlock on platform setup * fix wrong import
This commit is contained in:
parent
e73634e6c7
commit
71a305ea45
2 changed files with 30 additions and 1 deletions
|
@ -294,8 +294,12 @@ class EntityPlatform(object):
|
||||||
|
|
||||||
def add_entities(self, new_entities, update_before_add=False):
|
def add_entities(self, new_entities, update_before_add=False):
|
||||||
"""Add entities for a single platform."""
|
"""Add entities for a single platform."""
|
||||||
|
if update_before_add:
|
||||||
|
for entity in new_entities:
|
||||||
|
entity.update()
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.async_add_entities(list(new_entities), update_before_add),
|
self.async_add_entities(list(new_entities), False),
|
||||||
self.component.hass.loop
|
self.component.hass.loop
|
||||||
).result()
|
).result()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""The tests for the Entity component helper."""
|
"""The tests for the Entity component helper."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
import asyncio
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import logging
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -153,6 +154,30 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
||||||
assert 1 == len(self.hass.states.entity_ids())
|
assert 1 == len(self.hass.states.entity_ids())
|
||||||
assert not ent.update.called
|
assert not ent.update.called
|
||||||
|
|
||||||
|
def test_adds_entities_with_update_befor_add_true_deadlock_protect(self):
|
||||||
|
"""Test if call update befor add to state machine.
|
||||||
|
|
||||||
|
It need to run update inside executor and never call
|
||||||
|
async_add_entities with True
|
||||||
|
"""
|
||||||
|
call = []
|
||||||
|
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def async_add_entities_fake(entities, update_befor_add):
|
||||||
|
"""Fake add_entities_call."""
|
||||||
|
call.append(update_befor_add)
|
||||||
|
component._platforms['core'].async_add_entities = \
|
||||||
|
async_add_entities_fake
|
||||||
|
|
||||||
|
ent = EntityTest()
|
||||||
|
ent.update = Mock(spec_set=True)
|
||||||
|
component.add_entities([ent], True)
|
||||||
|
|
||||||
|
assert ent.update.called
|
||||||
|
assert len(call) == 1
|
||||||
|
assert not call[0]
|
||||||
|
|
||||||
def test_not_adding_duplicate_entities(self):
|
def test_not_adding_duplicate_entities(self):
|
||||||
"""Test for not adding duplicate entities."""
|
"""Test for not adding duplicate entities."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue