Fix device update / entity_id with names (#10029)
* Fix device update * Add tests * add test for disabled warning
This commit is contained in:
parent
193188b965
commit
56cbfb5f2a
4 changed files with 94 additions and 52 deletions
|
@ -210,6 +210,15 @@ class EntityComponent(object):
|
|||
|
||||
entity.hass = self.hass
|
||||
|
||||
# Update properties before we generate the entity_id
|
||||
if update_before_add:
|
||||
try:
|
||||
yield from entity.async_device_update(warning=False)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
self.logger.exception("Error on device update!")
|
||||
return False
|
||||
|
||||
# Write entity_id to entity
|
||||
if getattr(entity, 'entity_id', None) is None:
|
||||
object_id = entity.name or DEVICE_DEFAULT_NAME
|
||||
|
||||
|
@ -234,7 +243,7 @@ class EntityComponent(object):
|
|||
if hasattr(entity, 'async_added_to_hass'):
|
||||
yield from entity.async_added_to_hass()
|
||||
|
||||
yield from entity.async_update_ha_state(update_before_add)
|
||||
yield from entity.async_update_ha_state()
|
||||
|
||||
return True
|
||||
|
||||
|
@ -361,12 +370,14 @@ class EntityPlatform(object):
|
|||
|
||||
def add_entities(self, new_entities, update_before_add=False):
|
||||
"""Add entities for a single platform."""
|
||||
# That avoid deadlocks
|
||||
if update_before_add:
|
||||
for entity in new_entities:
|
||||
entity.update()
|
||||
self.component.logger.warning(
|
||||
"Call 'add_entities' with update_before_add=True "
|
||||
"only inside tests or you can run into a deadlock!")
|
||||
|
||||
run_coroutine_threadsafe(
|
||||
self.async_add_entities(list(new_entities), False),
|
||||
self.async_add_entities(list(new_entities), update_before_add),
|
||||
self.component.hass.loop).result()
|
||||
|
||||
@asyncio.coroutine
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue