Use async_timeout instead of asyncio.wait_for in switchbot (#76630)

pull/76647/head
J. Nick Koston 2022-08-11 15:10:59 -10:00 committed by GitHub
parent 14e6c84104
commit 4a5a039984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -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