Dont create coroutine until acting on it (#27907)

pull/27912/head
Paulus Schoutsen 2019-10-18 20:58:43 -07:00 committed by GitHub
parent 37b23e9205
commit 6303117354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 16 deletions

View File

@ -49,23 +49,23 @@ def async_enable_report_state(hass: HomeAssistant, google_config: AbstractConfig
{"devices": {"states": {changed_entity: entity_data}}}
)
async_call_later(
hass, INITIAL_REPORT_DELAY, _async_report_all_states(hass, google_config)
)
async def inital_report(_now):
"""Report initially all states."""
entities = {}
for entity in async_get_entities(hass, google_config):
if not entity.should_expose():
continue
try:
entities[entity.entity_id] = entity.query_serialize()
except SmartHomeError:
continue
await google_config.async_report_state({"devices": {"states": entities}})
async_call_later(hass, INITIAL_REPORT_DELAY, inital_report)
return hass.helpers.event.async_track_state_change(
MATCH_ALL, async_entity_state_listener
)
async def _async_report_all_states(hass: HomeAssistant, google_config: AbstractConfig):
"""Report all states."""
entities = {}
for entity in async_get_entities(hass, google_config):
if not entity.should_expose():
continue
entities[entity.entity_id] = entity.query_serialize()
await google_config.async_report_state({"devices": {"states": entities}})