Use async_timeout instead of asyncio.wait_for in switchbot (#76630)
parent
14e6c84104
commit
4a5a039984
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue