Skip to content

Commit b244fe8

Browse files
committed
Reformatted per pre-commit
1 parent b8008ae commit b244fe8

File tree

3 files changed

+68
-20
lines changed

3 files changed

+68
-20
lines changed

adafruit_ble/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ def __init__(self, adapter: Optional[_bleio.Adapter] = None) -> None:
157157
self._connection_cache = {}
158158

159159
def start_advertising(
160-
self, advertisement: Advertisement, scan_response: Optional[ReadableBuffer] = None, interval: float = 0.1, timeout: Optional[int] = None
160+
self,
161+
advertisement: Advertisement,
162+
scan_response: Optional[ReadableBuffer] = None,
163+
interval: float = 0.1,
164+
timeout: Optional[int] = None,
161165
) -> None:
162166
"""
163167
Starts advertising the given advertisement.
@@ -284,7 +288,9 @@ def stop_scan(self) -> None:
284288
once empty."""
285289
self._adapter.stop_scan()
286290

287-
def connect(self, peer: Union[Advertisement, _bleio.Address], *, timeout:float = 4.0) -> BLEConnection:
291+
def connect(
292+
self, peer: Union[Advertisement, _bleio.Address], *, timeout: float = 4.0
293+
) -> BLEConnection:
288294
"""
289295
Initiates a `BLEConnection` to the peer that advertised the given advertisement.
290296

adafruit_ble/advertising/__init__.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def to_bytes_literal(seq: bytes) -> str:
2828
return 'b"' + "".join("\\x{:02x}".format(v) for v in seq) + '"'
2929

3030

31-
def decode_data(data: bytes, *, key_encoding: str = "B") -> Dict[Any, Union[bytes, List[bytes]]]:
31+
def decode_data(
32+
data: bytes, *, key_encoding: str = "B"
33+
) -> Dict[Any, Union[bytes, List[bytes]]]:
3234
"""Helper which decodes length encoded structures into a dictionary with the given key
3335
encoding."""
3436
i = 0
@@ -51,7 +53,9 @@ def decode_data(data: bytes, *, key_encoding: str = "B") -> Dict[Any, Union[byte
5153
return data_dict
5254

5355

54-
def compute_length(data_dict: Dict[Any, Union[bytes, List[bytes]]], *, key_encoding: str = "B") -> int:
56+
def compute_length(
57+
data_dict: Dict[Any, Union[bytes, List[bytes]]], *, key_encoding: str = "B"
58+
) -> int:
5559
"""Computes the length of the encoded data dictionary."""
5660
value_size = 0
5761
for value in data_dict.values():
@@ -63,7 +67,9 @@ def compute_length(data_dict: Dict[Any, Union[bytes, List[bytes]]], *, key_encod
6367
return len(data_dict) + len(data_dict) * struct.calcsize(key_encoding) + value_size
6468

6569

66-
def encode_data(data_dict: Dict[Any, Union[bytes, List[bytes]]], *, key_encoding: str = "B") -> bytes:
70+
def encode_data(
71+
data_dict: Dict[Any, Union[bytes, List[bytes]]], *, key_encoding: str = "B"
72+
) -> bytes:
6773
"""Helper which encodes dictionaries into length encoded structures with the given key
6874
encoding."""
6975
length = compute_length(data_dict, key_encoding=key_encoding)
@@ -92,7 +98,9 @@ class AdvertisingFlag:
9298
def __init__(self, bit_position: int) -> None:
9399
self._bitmask = 1 << bit_position
94100

95-
def __get__(self, obj: Optional["AdvertisingFlags"], cls: Type["AdvertisingFlags"]) -> Union[bool, "AdvertisingFlag"]:
101+
def __get__(
102+
self, obj: Optional["AdvertisingFlags"], cls: Type["AdvertisingFlags"]
103+
) -> Union[bool, "AdvertisingFlag"]:
96104
if obj is None:
97105
return self
98106
return (obj.flags & self._bitmask) != 0
@@ -115,7 +123,9 @@ class AdvertisingFlags(AdvertisingDataField):
115123
"""BR/EDR not supported."""
116124
# BR/EDR flags not included here, since we don't support BR/EDR.
117125

118-
def __init__(self, advertisement: "Advertisement", advertising_data_type: int) -> None:
126+
def __init__(
127+
self, advertisement: "Advertisement", advertising_data_type: int
128+
) -> None:
119129
self._advertisement = advertisement
120130
self._adt = advertising_data_type
121131
self.flags = 0
@@ -146,7 +156,9 @@ class String(AdvertisingDataField):
146156
def __init__(self, *, advertising_data_type: int) -> None:
147157
self._adt = advertising_data_type
148158

149-
def __get__(self, obj: Optional["Advertisement"], cls: Type["Advertisement"]) -> Optional[Union[str, "String"]]:
159+
def __get__(
160+
self, obj: Optional["Advertisement"], cls: Type["Advertisement"]
161+
) -> Optional[Union[str, "String"]]:
150162
if obj is None:
151163
return self
152164
if self._adt not in obj.data_dict:
@@ -164,7 +176,9 @@ def __init__(self, struct_format: str, *, advertising_data_type: int) -> None:
164176
self._format = struct_format
165177
self._adt = advertising_data_type
166178

167-
def __get__(self, obj: Optional["Advertisement"], cls: Type["Advertisement"]) -> Optional[Union[Any, "Struct"]]:
179+
def __get__(
180+
self, obj: Optional["Advertisement"], cls: Type["Advertisement"]
181+
) -> Optional[Union[Any, "Struct"]]:
168182
if obj is None:
169183
return self
170184
if self._adt not in obj.data_dict:
@@ -178,13 +192,17 @@ def __set__(self, obj: "Advertisement", value: Any) -> None:
178192
class LazyObjectField(AdvertisingDataField):
179193
"""Non-data descriptor useful for lazily binding a complex object to an advertisement object."""
180194

181-
def __init__(self, cls: Any, attribute_name: str, *, advertising_data_type: int, **kwargs) -> None:
195+
def __init__(
196+
self, cls: Any, attribute_name: str, *, advertising_data_type: int, **kwargs
197+
) -> None:
182198
self._cls = cls
183199
self._attribute_name = attribute_name
184200
self._adt = advertising_data_type
185201
self._kwargs = kwargs
186202

187-
def __get__(self, obj: Optional["Advertisement"], cls: Type["Advertisement"]) -> Any:
203+
def __get__(
204+
self, obj: Optional["Advertisement"], cls: Type["Advertisement"]
205+
) -> Any:
188206
if obj is None:
189207
return self
190208
# Return None if our object is immutable and the data is not present.

adafruit_ble/advertising/standard.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
from adafruit_ble.services import Service
3333
from _bleio import ScanEntry
3434

35-
UsesServicesAdvertisement = Union["ProvideServicesAdvertisement", "SolicitServicesAdvertisement"]
36-
35+
UsesServicesAdvertisement = Union[
36+
"ProvideServicesAdvertisement", "SolicitServicesAdvertisement"
37+
]
3738

3839

3940
except ImportError:
@@ -46,7 +47,13 @@
4647
class BoundServiceList:
4748
"""Sequence-like object of Service UUID objects. It stores both standard and vendor UUIDs."""
4849

49-
def __init__(self, advertisement: UsesServicesAdvertisement, *, standard_services: List[int], vendor_services: List[int]) -> None:
50+
def __init__(
51+
self,
52+
advertisement: UsesServicesAdvertisement,
53+
*,
54+
standard_services: List[int],
55+
vendor_services: List[int]
56+
) -> None:
5057
self._advertisement = advertisement
5158
self._standard_service_fields = standard_services
5259
self._vendor_service_fields = vendor_services
@@ -140,7 +147,9 @@ def __str__(self) -> str:
140147
class ServiceList(AdvertisingDataField):
141148
"""Descriptor for a list of Service UUIDs that lazily binds a corresponding BoundServiceList."""
142149

143-
def __init__(self, *, standard_services: List[int], vendor_services: List[int]) -> None:
150+
def __init__(
151+
self, *, standard_services: List[int], vendor_services: List[int]
152+
) -> None:
144153
self.standard_services = standard_services
145154
self.vendor_services = vendor_services
146155

@@ -153,7 +162,11 @@ def _present(self, obj: UsesServicesAdvertisement) -> bool:
153162
return True
154163
return False
155164

156-
def __get__(self, obj: Optional[UsesServicesAdvertisement], cls: Type[UsesServicesAdvertisement]) -> Union[UsesServicesAdvertisement, Tuple[()], "ServiceList"]:
165+
def __get__(
166+
self,
167+
obj: Optional[UsesServicesAdvertisement],
168+
cls: Type[UsesServicesAdvertisement],
169+
) -> Union[UsesServicesAdvertisement, Tuple[()], "ServiceList"]:
157170
if obj is None:
158171
return self
159172
if not self._present(obj) and not obj.mutable:
@@ -227,7 +240,12 @@ class ManufacturerData(AdvertisingDataField):
227240
"""
228241

229242
def __init__(
230-
self, obj: UsesServicesAdvertisement, *, advertising_data_type: int = 0xFF, company_id: int, key_encoding: str = "B"
243+
self,
244+
obj: UsesServicesAdvertisement,
245+
*,
246+
advertising_data_type: int = 0xFF,
247+
company_id: int,
248+
key_encoding: str = "B"
231249
) -> None:
232250
self._obj = obj
233251
self._company_id = company_id
@@ -264,7 +282,9 @@ def __str__(self) -> str:
264282
class ManufacturerDataField:
265283
"""A single piece of data within the manufacturer specific data. The format can be repeated."""
266284

267-
def __init__(self, key: int, value_format: str, field_names: Optional[Iterable[str]] = None) -> None:
285+
def __init__(
286+
self, key: int, value_format: str, field_names: Optional[Iterable[str]] = None
287+
) -> None:
268288
self._key = key
269289
self._format = value_format
270290
# TODO: Support format strings that use numbers to repeat a given type. For now, we strip
@@ -282,7 +302,9 @@ def __init__(self, key: int, value_format: str, field_names: Optional[Iterable[s
282302
# Mostly, this is to raise a ValueError if field_names has invalid entries
283303
self.mdf_tuple = namedtuple("mdf_tuple", self.field_names)
284304

285-
def __get__(self, obj: Optional[Advertisement], cls: Type[Advertisement])-> Optional[Union["ManufacturerDataField", Tuple, namedtuple]]:
305+
def __get__(
306+
self, obj: Optional[Advertisement], cls: Type[Advertisement]
307+
) -> Optional[Union["ManufacturerDataField", Tuple, namedtuple]]:
286308
if obj is None:
287309
return self
288310
if self._key not in obj.manufacturer_data.data:
@@ -341,7 +363,9 @@ def __init__(self, service: Characteristic) -> None:
341363

342364
def __get__(
343365
self, obj: Optional[Service], cls: Type[Service]
344-
) -> Optional[Union["ServiceData", memoryview]]: # pylint: disable=too-many-return-statements,too-many-branches
366+
) -> Optional[
367+
Union["ServiceData", memoryview]
368+
]: # pylint: disable=too-many-return-statements,too-many-branches
345369
if obj is None:
346370
return self
347371
# If not present at all and mutable, then we init it, otherwise None.

0 commit comments

Comments
 (0)