add another timeout check on read_data
This commit is contained in:
1 parent
3a35f93791
commit
9c63de343a
1 file changed
+15
-1
+15
-1
@@ -38,6 +38,7 @@ SCAN_TIMEOUT = 10.0 # seconds to scan for each MAC
|
|||||||
CONNECT_TIMEOUT = 20.0
|
CONNECT_TIMEOUT = 20.0
|
||||||
READ_TIMEOUT = 5.0
|
READ_TIMEOUT = 5.0
|
||||||
SERVICE_DISCOVERY_TIMEOUT = 10.0
|
SERVICE_DISCOVERY_TIMEOUT = 10.0
|
||||||
|
DISCOVER_TIMEOUT = SCAN_TIMEOUT + 5.0 # Timeout for discovering device
|
||||||
|
|
||||||
# --------------------------------------------------------------------------- #
|
# --------------------------------------------------------------------------- #
|
||||||
# Logging
|
# Logging
|
||||||
@@ -138,10 +139,23 @@ def scan_macs():
|
|||||||
# Core async read functions (unchanged from the refactored version)
|
# Core async read functions (unchanged from the refactored version)
|
||||||
# --------------------------------------------------------------------------- #
|
# --------------------------------------------------------------------------- #
|
||||||
async def read_data(mac: str) -> Optional[SensorReading]:
|
async def read_data(mac: str) -> Optional[SensorReading]:
|
||||||
address = await _discover_device(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:
|
if not address:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
#address = await _discover_device(mac)
|
||||||
|
#if not address:
|
||||||
|
# return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with BleakClient(address, timeout=CONNECT_TIMEOUT) as client:
|
async with BleakClient(address, timeout=CONNECT_TIMEOUT) as client:
|
||||||
# <--- NEW BLOCK ----------------------------------------------
|
# <--- NEW BLOCK ----------------------------------------------
|
||||||
|
|||||||
Reference in new issue
Block a user