From 63031173548e70f320fffc5d4ef3fb8b8cbc35c8 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 18 Oct 2019 20:58:43 -0700 Subject: [PATCH] Dont create coroutine until acting on it (#27907) --- .../google_assistant/report_state.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/google_assistant/report_state.py b/homeassistant/components/google_assistant/report_state.py index b842a552714..aacb90e9d2b 100644 --- a/homeassistant/components/google_assistant/report_state.py +++ b/homeassistant/components/google_assistant/report_state.py @@ -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}})