diff --git a/api/ble.py b/api/ble.py index af6c771..05d819b 100644 --- a/api/ble.py +++ b/api/ble.py @@ -182,18 +182,18 @@ def _is_match(mac: str, name: str) -> bool: #################################################### async def read_data(mac: str) -> Optional[SensorReading]: -# try: -# address = await asyncio.wait_for( -# _discover_device(mac), -# timeout=DISCOVER_TIMEOUT, -# ) -# except asyncio.TimeoutError: -# log.warning("Device discovery timed out for %s after %.1fs", mac, DISCOVER_TIMEOUT) -# return None -# -# if not address: -# return None - address = mac + try: + address = await asyncio.wait_for( + _discover_device(mac), + timeout=DISCOVER_TIMEOUT, + ) + except asyncio.TimeoutError: + log.warning("Device discovery timed out for %s after %.1fs", mac, DISCOVER_TIMEOUT) + return None + + if not address: + return None + try: async with BleakClient(address, timeout=CONNECT_TIMEOUT) as client: # NEW BLOCK ----------------------------------------------