From f4625fd561d6c53be4e8f4ebf330f15ad5d62733 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Fri, 29 Mar 2019 02:38:58 -0600 Subject: [PATCH] Speed up status updating in SimpliSafe (#22506) * Speed up status updating in SimpliSafe * Linting * Member comments --- .../components/simplisafe/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index e6b9aba643d..359591856a7 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -1,4 +1,5 @@ """Support for SimpliSafe alarm systems.""" +import asyncio import logging from datetime import timedelta @@ -107,17 +108,18 @@ async def async_setup_entry(hass, config_entry): async def refresh(event_time): """Refresh data from the SimpliSafe account.""" - for system in systems: - _LOGGER.debug('Updating system data: %s', system.system_id) - - try: - await system.update() - except SimplipyError as err: + tasks = [system.update() for system in systems] + results = await asyncio.gather(*tasks, return_exceptions=True) + for system, result in zip(systems, results): + if isinstance(result, SimplipyError): _LOGGER.error( - 'There was error updating "%s": %s', system.address, err) + 'There was error updating "%s": %s', system.address, + result) continue - async_dispatcher_send(hass, TOPIC_UPDATE.format(system.system_id)) + _LOGGER.debug('Updated status of "%s"', system.address) + async_dispatcher_send( + hass, TOPIC_UPDATE.format(system.system_id)) if system.api.refresh_token_dirty: _async_save_refresh_token(