From 6868865e3ebc303e6e3d76d669f5ba31fad32b14 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Wed, 27 Jul 2022 00:01:49 +0200 Subject: [PATCH] Add 1.5 second sleep to motion blinds update (#75494) --- .../components/motion_blinds/__init__.py | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/motion_blinds/__init__.py b/homeassistant/components/motion_blinds/__init__.py index 184e721aeed..dfbc6ab74a7 100644 --- a/homeassistant/components/motion_blinds/__init__.py +++ b/homeassistant/components/motion_blinds/__init__.py @@ -65,36 +65,43 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator): self._wait_for_push = coordinator_info[CONF_WAIT_FOR_PUSH] def update_gateway(self): - """Call all updates using one async_add_executor_job.""" - data = {} - + """Fetch data from gateway.""" try: self._gateway.Update() except (timeout, ParseException): # let the error be logged and handled by the motionblinds library - data[KEY_GATEWAY] = {ATTR_AVAILABLE: False} - return data + return {ATTR_AVAILABLE: False} else: - data[KEY_GATEWAY] = {ATTR_AVAILABLE: True} + return {ATTR_AVAILABLE: True} - for blind in self._gateway.device_list.values(): - try: - if self._wait_for_push: - blind.Update() - else: - blind.Update_trigger() - except (timeout, ParseException): - # let the error be logged and handled by the motionblinds library - data[blind.mac] = {ATTR_AVAILABLE: False} + def update_blind(self, blind): + """Fetch data from a blind.""" + try: + if self._wait_for_push: + blind.Update() else: - data[blind.mac] = {ATTR_AVAILABLE: True} - - return data + blind.Update_trigger() + except (timeout, ParseException): + # let the error be logged and handled by the motionblinds library + return {ATTR_AVAILABLE: False} + else: + return {ATTR_AVAILABLE: True} async def _async_update_data(self): """Fetch the latest data from the gateway and blinds.""" + data = {} + async with self.api_lock: - data = await self.hass.async_add_executor_job(self.update_gateway) + data[KEY_GATEWAY] = await self.hass.async_add_executor_job( + self.update_gateway + ) + + for blind in self._gateway.device_list.values(): + await asyncio.sleep(1.5) + async with self.api_lock: + data[blind.mac] = await self.hass.async_add_executor_job( + self.update_blind, blind + ) all_available = all(device[ATTR_AVAILABLE] for device in data.values()) if all_available: