From 9a6902d827a0d712d3a5af6c6275cf1289df839d Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Fri, 7 Jun 2024 10:50:05 +0300 Subject: [PATCH] Hold connection lock in Shelly RPC reconnect (#119009) --- homeassistant/components/shelly/coordinator.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/shelly/coordinator.py b/homeassistant/components/shelly/coordinator.py index 2fe3f6a9943..b6ccc1540f1 100644 --- a/homeassistant/components/shelly/coordinator.py +++ b/homeassistant/components/shelly/coordinator.py @@ -586,11 +586,13 @@ class ShellyRpcCoordinator(ShellyCoordinatorBase[RpcDevice]): raise UpdateFailed( f"Sleeping device did not update within {self.sleep_period} seconds interval" ) - if self.device.connected: - return - if not await self._async_device_connect_task(): - raise UpdateFailed("Device reconnect error") + async with self._connection_lock: + if self.device.connected: # Already connected + return + + if not await self._async_device_connect_task(): + raise UpdateFailed("Device reconnect error") async def _async_disconnected(self, reconnect: bool) -> None: """Handle device disconnected."""