Fix device update / entity_id with names (#10029)
* Fix device update * Add tests * add test for disabled warning
This commit is contained in:
1 parent
193188b965
commit
56cbfb5f2a
4 files changed
+94
-52
No files matched your search
@@ -193,6 +193,30 @@ def test_warn_slow_update_with_exception(hass):
|
||||
assert update_call
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_warn_slow_device_update_disabled(hass):
|
||||
"""Disable slow update warning with async_device_update."""
|
||||
update_call = False
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_update():
|
||||
"""Mock async update."""
|
||||
nonlocal update_call
|
||||
update_call = True
|
||||
|
||||
mock_entity = entity.Entity()
|
||||
mock_entity.hass = hass
|
||||
mock_entity.entity_id = 'comp_test.test_entity'
|
||||
mock_entity.async_update = async_update
|
||||
|
||||
with patch.object(hass.loop, 'call_later', MagicMock()) \
|
||||
as mock_call:
|
||||
yield from mock_entity.async_device_update(warning=False)
|
||||
|
||||
assert not mock_call.called
|
||||
assert update_call
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_async_schedule_update_ha_state(hass):
|
||||
"""Warn we log when entity update takes a long time and trow exception."""
|
||||
|
||||
@@ -208,30 +208,6 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
||||
assert 1 == len(self.hass.states.entity_ids())
|
||||
assert not ent.update.called
|
||||
|
||||
def test_adds_entities_with_update_befor_add_true_deadlock_protect(self):
|
||||
"""Test if call update before 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):
|
||||
"""Test for not adding duplicate entities."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
||||
@@ -654,3 +630,24 @@ def test_pararell_updates_sync_platform(hass):
|
||||
handle = list(component._platforms.values())[-1]
|
||||
|
||||
assert handle.parallel_updates is not None
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_raise_error_on_update(hass):
|
||||
"""Test the add entity if they raise an error on update."""
|
||||
updates = []
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
entity1 = EntityTest(name='test_1')
|
||||
entity2 = EntityTest(name='test_2')
|
||||
|
||||
def _raise():
|
||||
"""Helper to raise a exception."""
|
||||
raise AssertionError
|
||||
|
||||
entity1.update = _raise
|
||||
entity2.update = lambda: updates.append(1)
|
||||
|
||||
yield from component.async_add_entities([entity1, entity2], True)
|
||||
|
||||
assert len(updates) == 1
|
||||
assert 1 in updates
|
||||
Reference in new issue
Block a user