mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Async speedup add_device callback (#3910)
* Speed up entities processing from add_device callback * fix lint * fix bug
This commit is contained in:
parent
6581dc2381
commit
7484152be1
@ -289,11 +289,9 @@ class EntityPlatform(object):
|
|||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
for entity in new_entities:
|
tasks = [self._async_process_entity(entity) for entity in new_entities]
|
||||||
ret = yield from self.component.async_add_entity(entity, self)
|
|
||||||
if ret:
|
|
||||||
self.platform_entities.append(entity)
|
|
||||||
|
|
||||||
|
yield from asyncio.gather(*tasks, loop=self.component.hass.loop)
|
||||||
yield from self.component.async_update_group()
|
yield from self.component.async_update_group()
|
||||||
|
|
||||||
if self._async_unsub_polling is not None or \
|
if self._async_unsub_polling is not None or \
|
||||||
@ -305,6 +303,13 @@ class EntityPlatform(object):
|
|||||||
self.component.hass, self._update_entity_states,
|
self.component.hass, self._update_entity_states,
|
||||||
second=range(0, 60, self.scan_interval))
|
second=range(0, 60, self.scan_interval))
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def _async_process_entity(self, new_entity):
|
||||||
|
"""Add entities to StateMachine."""
|
||||||
|
ret = yield from self.component.async_add_entity(new_entity, self)
|
||||||
|
if ret:
|
||||||
|
self.platform_entities.append(new_entity)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_reset(self):
|
def async_reset(self):
|
||||||
"""Remove all entities and reset data.
|
"""Remove all entities and reset data.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user