Skip to content

Commit 2174f23

Browse files
authored
Use faster async_timeout in place of asyncio.wait_for (#59)
1 parent 008fe88 commit 2174f23

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name = 'PySwitchbot',
55
packages = ['switchbot'],
6-
install_requires=['bleak', 'bleak-retry-connector>=1.1.1'],
6+
install_requires=['async_timeout>=4.0.1', 'bleak', 'bleak-retry-connector>=1.1.1'],
77
version = '0.17.1',
88
description = 'A library to communicate with Switchbot',
99
author='Daniel Hjelseth Hoyer',

switchbot/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Any
99
from uuid import UUID
1010

11+
import async_timeout
1112
import bleak
1213
from bleak.backends.device import BLEDevice
1314
from bleak.backends.scanner import AdvertisementData
@@ -400,7 +401,8 @@ def _notification_handler(sender: int, data: bytearray) -> None:
400401
_LOGGER.debug("%s: Sending command, %s", self.name, key)
401402
await client.write_gatt_char(_sb_uuid(comms_type="tx"), command, False)
402403

403-
notify_msg = await asyncio.wait_for(future, timeout=5)
404+
async with async_timeout.timeout(5):
405+
notify_msg = await future
404406
_LOGGER.info("%s: Notification received: %s", self.name, notify_msg)
405407

406408
_LOGGER.debug("%s: UnSubscribe to notifications", self.name)

0 commit comments

Comments
 (0)