Skip to content

Commit e38b153

Browse files
committed
increase connect default timeout; handle CPython descriptor protocol class arg
1 parent 73a8400 commit e38b153

File tree

7 files changed

+23
-1
lines changed

7 files changed

+23
-1
lines changed

adafruit_ble/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def stop_scan(self):
261261
once empty."""
262262
self._adapter.stop_scan()
263263

264-
def connect(self, advertisement, *, timeout=4):
264+
def connect(self, advertisement, *, timeout=10.0):
265265
"""
266266
Initiates a `BLEConnection` to the peer that advertised the given advertisement.
267267

adafruit_ble/advertising/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def __init__(self, bit_position):
103103
self._bitmask = 1 << bit_position
104104

105105
def __get__(self, obj, cls):
106+
if obj is None:
107+
return self
106108
return (obj.flags & self._bitmask) != 0
107109

108110
def __set__(self, obj, value):

adafruit_ble/advertising/standard.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def _present(self, obj):
155155
return False
156156

157157
def __get__(self, obj, cls):
158+
if obj is None:
159+
return self
158160
if not self._present(obj) and not obj.mutable:
159161
return ()
160162
if not hasattr(obj, "adv_service_lists"):
@@ -315,6 +317,8 @@ def __init__(self, service):
315317
self._prefix = bytes(service.uuid)
316318

317319
def __get__(self, obj, cls):
320+
if obj is None:
321+
return self
318322
# If not present at all and mutable, then we init it, otherwise None.
319323
if self._adt not in obj.data_dict:
320324
if obj.mutable:

adafruit_ble/characteristics/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ def __bind_locally(self, service, initial_value):
151151
)
152152

153153
def __get__(self, service, cls=None):
154+
# CircuitPython doesn't invoke descriptor protocol on obj's class,
155+
# but CPython does. In the CPython case, pretend that it doesn't.
156+
if service is None:
157+
return self
154158
self._ensure_bound(service)
155159
bleio_characteristic = service.bleio_characteristics[self.field_name]
156160
return bleio_characteristic.value
@@ -210,6 +214,8 @@ def bind(self, service):
210214
)
211215

212216
def __get__(self, service, cls=None):
217+
if service is None:
218+
return self
213219
bound_object = self.bind(service)
214220
setattr(service, self.field_name, bound_object)
215221
return bound_object
@@ -253,6 +259,8 @@ def __init__(
253259
)
254260

255261
def __get__(self, obj, cls=None):
262+
if obj is None:
263+
return self
256264
raw_data = super().__get__(obj, cls)
257265
if len(raw_data) < self._expected_size:
258266
return None

adafruit_ble/characteristics/float.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def __init__(
5858
)
5959

6060
def __get__(self, obj, cls=None):
61+
if obj is None:
62+
return self
6163
return super().__get__(obj)[0]
6264

6365
def __set__(self, obj, value):

adafruit_ble/characteristics/int.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def __init__(
6666
)
6767

6868
def __get__(self, obj, cls=None):
69+
if obj is None:
70+
return self
6971
return super().__get__(obj)[0]
7072

7173
def __set__(self, obj, value):

adafruit_ble/characteristics/string.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def __init__(
5757
)
5858

5959
def __get__(self, obj, cls=None):
60+
if obj is None:
61+
return self
6062
return str(super().__get__(obj, cls), "utf-8")
6163

6264
def __set__(self, obj, value):
@@ -76,4 +78,6 @@ def __init__(self, *, uuid=None, read_perm=Attribute.OPEN):
7678
)
7779

7880
def __get__(self, obj, cls=None):
81+
if obj is None:
82+
return self
7983
return str(super().__get__(obj, cls), "utf-8")

0 commit comments

Comments
 (0)