Skip to content

Commit

Permalink
Merge pull request #5 from tannewt/connectionerror
Browse files Browse the repository at this point in the history
Backwards compatible ConnectionError
  • Loading branch information
dhalbert authored Oct 13, 2020
2 parents 3917670 + 7e6cf06 commit 08decc2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions examples/ble_berrymed_pulse_oximeter_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from adafruit_ble.services.standard.device_info import DeviceInfoService
from adafruit_ble_berrymed_pulse_oximeter import BerryMedPulseOximeterService

# CircuitPython <6 uses its own ConnectionError type. So, is it if available. Otherwise,
# the built in ConnectionError is used.
connection_error = ConnectionError
if hasattr(_bleio, "ConnectionError"):
connection_error = _bleio.ConnectionError

# PyLint can't find BLERadio for some reason so special case it here.
ble = adafruit_ble.BLERadio() # pylint: disable=no-member

Expand Down Expand Up @@ -56,9 +62,9 @@
pulse_ox_service = pulse_ox_connection[BerryMedPulseOximeterService]
while pulse_ox_connection.connected:
print(pulse_ox_service.values)
except _bleio.ConnectionError: # pylint: disable=no-member
except connection_error:
try:
pulse_ox_connection.disconnect()
except _bleio.ConnectionError: # pylint: disable=no-member
except connection_error:
pass
pulse_ox_connection = None

0 comments on commit 08decc2

Please sign in to comment.