From 4a5a0399846f18043a9fb75c685f4509a6c4adc2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 11 Aug 2022 15:10:59 -1000 Subject: [PATCH] Use async_timeout instead of asyncio.wait_for in switchbot (#76630) --- homeassistant/components/switchbot/coordinator.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/switchbot/coordinator.py b/homeassistant/components/switchbot/coordinator.py index ad9aff8c53b..e4e7c25dc70 100644 --- a/homeassistant/components/switchbot/coordinator.py +++ b/homeassistant/components/switchbot/coordinator.py @@ -2,9 +2,11 @@ from __future__ import annotations import asyncio +import contextlib import logging from typing import TYPE_CHECKING, Any +import async_timeout import switchbot from homeassistant.components import bluetooth @@ -71,8 +73,8 @@ class SwitchbotDataUpdateCoordinator(PassiveBluetoothDataUpdateCoordinator): async def async_wait_ready(self) -> bool: """Wait for the device to be ready.""" - try: - await asyncio.wait_for(self._ready_event.wait(), timeout=55) - except asyncio.TimeoutError: - return False - return True + with contextlib.suppress(asyncio.TimeoutError): + async with async_timeout.timeout(55): + await self._ready_event.wait() + return True + return False