Skip to content

Commit

Permalink
Adding a retry effort in device scan
Browse files Browse the repository at this point in the history
c3V6a2Vy#4
Adding a retry loop to allow resetting the BLE adapter so it can perform another scan
  • Loading branch information
wsidl authored Sep 3, 2019
1 parent 4c598d2 commit 0bf96a1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pyanova/pyanova.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,14 @@ def discover(self, list_all = False, dev_mac_pattern=DEFAULT_DEV_MAC_PATTERN, ti
e.g: [{'name': 'ffs', 'address': '01:02:03:04:05:10'}, {'name': 'rlx', 'address': '01:02:03:04:05:21'}]
"""
devices = self._adapter.scan(run_as_root=True, timeout=timeout)
retries = 0
while retries < 5:
try:
devices = self._adapter.scan(run_as_root=True, timeout=timeout)
except pygatt.exceptions.BLEError:
self._logger.info('Resetting BLE Adapter, retrying scan')
self._adapter.reset()
retries += 1
if list_all:
return devices
return list(filter(lambda dev: dev_mac_pattern.match(dev['address']), devices))
Expand Down Expand Up @@ -326,4 +333,4 @@ def set_unit(self, unit, handle=DEVICE_NOTIFICATION_CHAR_HANDLE, timeout=DEFAULT
errmsg = 'Expected unit to be either \'c\' or \'f\', found: %s'%unit
self._logger.error(errmsg)
raise ValueError(errmsg)
return self._write_strcmd(SET_TEMP_UNIT%unit, handle, timeout)
return self._write_strcmd(SET_TEMP_UNIT%unit, handle, timeout)

0 comments on commit 0bf96a1

Please sign in to comment.