Skip to content

Switch to native ConnectionError #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ Usage Example

from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble_magic_light import MagicLightService

# 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

def find_connection():
for connection in radio.connections:
Expand Down Expand Up @@ -100,7 +106,7 @@ Usage Example
active_connection = radio.connect(scan)
try:
pixels = active_connection[MagicLightService]
except _bleio.ConnectionError:
except connection_error:
print("disconnected")
continue
break
Expand Down
8 changes: 7 additions & 1 deletion examples/ble_magic_light_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble_magic_light import MagicLightService

# 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


def find_connection():
for connection in radio.connections:
Expand Down Expand Up @@ -43,7 +49,7 @@ def wheel(pos):
active_connection = radio.connect(scan)
try:
pixels = active_connection[MagicLightService]
except _bleio.ConnectionError: # pylint: disable=no-member
except connection_error:
print("disconnected")
continue
break
Expand Down