Add 1.5 second sleep to motion blinds update (#75494)

This commit is contained in:
starkillerOG 2022-07-27 00:01:49 +02:00 committed by GitHub
parent fb52f5098f
commit 6868865e3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,36 +65,43 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator):
self._wait_for_push = coordinator_info[CONF_WAIT_FOR_PUSH] self._wait_for_push = coordinator_info[CONF_WAIT_FOR_PUSH]
def update_gateway(self): def update_gateway(self):
"""Call all updates using one async_add_executor_job.""" """Fetch data from gateway."""
data = {}
try: try:
self._gateway.Update() self._gateway.Update()
except (timeout, ParseException): except (timeout, ParseException):
# let the error be logged and handled by the motionblinds library # let the error be logged and handled by the motionblinds library
data[KEY_GATEWAY] = {ATTR_AVAILABLE: False} return {ATTR_AVAILABLE: False}
return data
else: else:
data[KEY_GATEWAY] = {ATTR_AVAILABLE: True} return {ATTR_AVAILABLE: True}
for blind in self._gateway.device_list.values(): def update_blind(self, blind):
try: """Fetch data from a blind."""
if self._wait_for_push: try:
blind.Update() if self._wait_for_push:
else: blind.Update()
blind.Update_trigger()
except (timeout, ParseException):
# let the error be logged and handled by the motionblinds library
data[blind.mac] = {ATTR_AVAILABLE: False}
else: else:
data[blind.mac] = {ATTR_AVAILABLE: True} blind.Update_trigger()
except (timeout, ParseException):
return data # 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): async def _async_update_data(self):
"""Fetch the latest data from the gateway and blinds.""" """Fetch the latest data from the gateway and blinds."""
data = {}
async with self.api_lock: 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()) all_available = all(device[ATTR_AVAILABLE] for device in data.values())
if all_available: if all_available: