Skip to content

Commit 425765c

Browse files
authored
Merge pull request #305 from ukBaz/release_prep
Release prep
2 parents c642fc2 + 605252d commit 425765c

19 files changed

+214
-128
lines changed

bluezero/GATT.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def resolve_gatt(self):
4646
self.srv_uuid)
4747

4848
@property
49-
def UUID(self):
49+
def UUID(self): # pylint: disable=invalid-name
5050
"""
5151
Return the value of the Service UUID for this path.
5252
@@ -118,7 +118,7 @@ def resolve_gatt(self):
118118
return False
119119

120120
@property
121-
def UUID(self):
121+
def UUID(self): # pylint: disable=invalid-name
122122
"""
123123
Return the value of the Characteristic UUID for this path.
124124
@@ -152,7 +152,7 @@ def value(self):
152152

153153
@value.setter
154154
def value(self, new_value):
155-
if type(new_value) is not list:
155+
if not isinstance(new_value, list):
156156
new_value = [new_value]
157157
self.write_value(new_value)
158158

@@ -262,7 +262,7 @@ def props_changed_cb(self, iface, changed_props, invalidated_props):
262262
if iface != constants.GATT_CHRC_IFACE:
263263
return
264264

265-
if not len(changed_props):
265+
if not changed_props:
266266
return
267267

268268
value = changed_props.get('Value', None)
@@ -322,7 +322,7 @@ def resolve_gatt(self):
322322
self.dscr_uuid)
323323

324324
@property
325-
def UUID(self):
325+
def UUID(self): # pylint: disable=invalid-name
326326
"""
327327
Return the value of the Descriptor UUID for this path.
328328
@@ -419,7 +419,7 @@ def release(self):
419419
self.profile_methods.Release()
420420

421421
@property
422-
def UUIDs(self):
422+
def UUIDs(self): # pylint: disable=invalid-name
423423
"""
424424
128-bit GATT service UUIDs to auto connect.
425425

bluezero/adapter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
class AdapterError(Exception):
21+
"""Custom exception for missing Bluetooth adapter"""
2122
pass
2223

2324

@@ -26,7 +27,7 @@ def list_adapters():
2627
return [dongle.address for dongle in Adapter.available()]
2728

2829

29-
class Adapter(object):
30+
class Adapter:
3031
"""Bluetooth Adapter Class.
3132
3233
This class instantiates an object that interacts with the physical

bluezero/advertisement.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ def __init__(self, advert_id, ad_type):
8686
}
8787

8888
def start(self):
89+
"""Start GLib event loop"""
8990
self.mainloop.run()
9091

9192
def stop(self):
93+
"""Stop GLib event loop"""
9294
self.mainloop.quit()
9395

9496
def get_path(self):
@@ -98,7 +100,7 @@ def get_path(self):
98100
@dbus.service.method(constants.LE_ADVERTISEMENT_IFACE,
99101
in_signature='',
100102
out_signature='')
101-
def Release(self):
103+
def Release(self): # pylint: disable=invalid-name
102104
"""
103105
This method gets called when the service daemon
104106
removes the Advertisement. A client can use it to do
@@ -110,13 +112,13 @@ def Release(self):
110112
pass
111113

112114
@property
113-
def service_UUIDs(self):
115+
def service_UUIDs(self): # pylint: disable=invalid-name
114116
"""List of UUIDs that represent available services."""
115117
return self.Get(constants.LE_ADVERTISEMENT_IFACE,
116118
'ServiceUUIDs')
117119

118120
@service_UUIDs.setter
119-
def service_UUIDs(self, UUID):
121+
def service_UUIDs(self, UUID): # pylint: disable=invalid-name
120122
self.Set(constants.LE_ADVERTISEMENT_IFACE,
121123
'ServiceUUIDs',
122124
UUID)
@@ -125,7 +127,7 @@ def manufacturer_data(self):
125127
"""Manufacturer Data to be broadcast (Currently not supported)"""
126128
pass
127129

128-
def solicit_UUIDs(self):
130+
def solicit_UUIDs(self): # pylint: disable=invalid-name
129131
"""Manufacturer Data to be broadcast (Currently not supported)"""
130132
pass
131133

@@ -137,10 +139,10 @@ def service_data(self):
137139

138140
@service_data.setter
139141
def service_data(self, data):
140-
for UUID in data:
142+
for uuid in data:
141143
self.Set(constants.LE_ADVERTISEMENT_IFACE,
142144
'ServiceData',
143-
{UUID: dbus.Array(data[UUID], signature='y')})
145+
{uuid: dbus.Array(data[uuid], signature='y')})
144146

145147
@property
146148
def include_tx_power(self):
@@ -174,7 +176,7 @@ def appearance(self, appearance):
174176
@dbus.service.method(constants.DBUS_PROP_IFACE,
175177
in_signature='s',
176178
out_signature='a{sv}')
177-
def GetAll(self, interface_name):
179+
def GetAll(self, interface_name): # pylint: disable=invalid-name
178180
"""Return the advertisement properties.
179181
180182
This method is registered with the D-Bus at
@@ -219,7 +221,8 @@ def GetAll(self, interface_name):
219221

220222
@dbus.service.method(dbus.PROPERTIES_IFACE,
221223
in_signature='ss', out_signature='v')
222-
def Get(self, interface_name, property_name):
224+
def Get(self, interface_name, # pylint: disable=invalid-name
225+
property_name):
223226
"""DBus API for getting a property value"""
224227

225228
if interface_name != constants.LE_ADVERTISEMENT_IFACE:
@@ -234,7 +237,8 @@ def Get(self, interface_name, property_name):
234237

235238
@dbus.service.method(dbus.PROPERTIES_IFACE,
236239
in_signature='ssv', out_signature='')
237-
def Set(self, interface_name, property_name, value, *args, **kwargs):
240+
def Set(self, interface_name, property_name, value,
241+
*args, **kwargs): # pylint: disable=invalid-name
238242
"""Standard D-Bus API for setting a property value"""
239243

240244
try:

bluezero/async_tools.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Collection of functions to work with the GLib Event Loop
3+
"""
14
# Main eventloop import
25
import dbus
36
import dbus.mainloop.glib
@@ -9,20 +12,23 @@
912

1013

1114
def add_timer_ms(time, callback, data=None):
15+
"""Call given callback every x milliseconds"""
1216
if data:
1317
GLib.timeout_add(time, callback, data)
1418
else:
1519
GLib.timeout_add(time, callback)
1620

1721

1822
def add_timer_seconds(time, callback, data=None):
23+
"""Call given callback every x seconds"""
1924
if data:
2025
GLib.timeout_add_seconds(time, callback, data)
2126
else:
2227
GLib.timeout_add_seconds(time, callback)
2328

2429

2530
class EventLoop:
31+
"""Facade class to help with using GLib event loop"""
2632
# def generic_error_cb(self, error):
2733
# """Generic Error Callback function."""
2834
# logger.error('D-Bus call failed: ' + str(error))
@@ -36,10 +42,13 @@ def __init__(self):
3642
self.mainloop = GLib.MainLoop()
3743

3844
def run(self):
45+
"""Run event loop"""
3946
self.mainloop.run()
4047

4148
def quit(self):
49+
"""Stop event loop"""
4250
self.mainloop.quit()
4351

4452
def is_running(self):
53+
"""Check if event loop is running"""
4554
self.mainloop.is_running()

bluezero/broadcaster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def include_tx_power(self, show_power=None):
5353
:return:
5454
"""
5555
if show_power is None:
56-
self.broadcaster.include_tx_power
56+
return self.broadcaster.include_tx_power
5757
else:
5858
self.broadcaster.include_tx_power = show_power
5959

bluezero/central.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, device_addr, adapter_addr=None):
2929
@staticmethod
3030
def available(adapter_address=None):
3131
"""Generator for getting a list of devices"""
32-
return device.Device.available()
32+
return device.Device.available(adapter_address)
3333

3434
def add_characteristic(self, srv_uuid, chrc_uuid):
3535
"""
@@ -56,14 +56,15 @@ def load_gatt(self):
5656
available = chrc.resolve_gatt()
5757
if available:
5858
logger.info('Service: %s and characteristic: %s added',
59-
(chrc.srv_uuid, chrc.chrc_uuid))
59+
chrc.srv_uuid, chrc.chrc_uuid)
6060
else:
6161
logger.warning('Service: %s and characteristic: %s not '
6262
'available on device: %s', chrc.srv_uuid,
6363
chrc.chrc_uuid, chrc.device_addr)
6464

6565
@property
6666
def services_available(self):
67+
"""Get a list of Service UUIDs available on this device"""
6768
return self.rmt_device.services_available
6869

6970
@property
@@ -97,7 +98,9 @@ def disconnect(self):
9798
self.rmt_device.disconnect()
9899

99100
def run(self):
101+
"""Start event loop"""
100102
self.dongle.run()
101103

102104
def quit(self):
105+
"""Stop event loop"""
103106
self.dongle.quit()

bluezero/dbus_tools.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
def bluez_version():
1818
"""
1919
get the version of the BlueZ daemon being used on the system
20+
2021
:return: String of BlueZ version
2122
"""
22-
p = subprocess.Popen(['bluetoothctl', '-v'], stdout=subprocess.PIPE)
23-
ver = p.communicate()
24-
return str(ver[0].decode().rstrip())
23+
cmd = ['bluetoothctl', '-v']
24+
cmd_output = subprocess.run(cmd, capture_output=True, check=True)
25+
version = cmd_output.stdout.decode('utf-8').split()
26+
return version[1]
2527

2628

2729
def bluez_experimental_mode():
@@ -92,13 +94,22 @@ def get_managed_objects():
9294

9395

9496
def get_mac_addr_from_dbus_path(path):
97+
"""
98+
[Deprecated] Function to get the address of a remote device from
99+
a given D-Bus path. Path must include device part
100+
(e.g. dev_XX_XX_XX_XX_XX_XX)
101+
"""
95102
logger.warning('get_mac_addr_from_dbus_path has been deprecated and has'
96103
'been replaced with get_device_address_from_dbus_path')
97104
return get_device_address_from_dbus_path(path)
98105

99106

100107
def get_device_address_from_dbus_path(path):
101-
"""Return the mac address from a dev_XX_XX_XX_XX_XX_XX dbus path"""
108+
"""
109+
[Deprecated] Function to get the address of a remote device from
110+
a given D-Bus path. Path must include device part
111+
(e.g. dev_XX_XX_XX_XX_XX_XX)
112+
"""
102113
for path_elem in path.split('/'):
103114
if path_elem.startswith('dev_'):
104115
return path_elem.replace("dev_", '').replace("_", ":")
@@ -323,6 +334,12 @@ def get_props(adapter=None,
323334

324335

325336
def get_services(path_obj):
337+
"""
338+
Return a list of GATT Service UUIDs for a given Bluetooth device D-Bus path
339+
340+
:param path_obj: D-Bus path for remote Bluetooth device
341+
:return: List of GATT Service UUIDs
342+
"""
326343
found_services = []
327344
valid_structure = re.match(r'/org/bluez/hci\d+/dev(_([0-9A-Fa-f]){2}){6}',
328345
path_obj)
@@ -378,8 +395,10 @@ def get(dbus_prop_obj, dbus_iface, prop_name, default=None):
378395

379396

380397
def str_to_dbusarray(word):
398+
"""Helper function to represent Python string as D-Dbus Byte array"""
381399
return dbus.Array([dbus.Byte(ord(letter)) for letter in word], 'y')
382400

383401

384402
def bytes_to_dbusarray(bytesarray):
403+
"""Helper function to represent Python bytearray as D-Bus Byte array"""
385404
return dbus.Array([dbus.Byte(elem) for elem in bytesarray], 'y')

bluezero/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
logger = tools.create_module_logger(__name__)
1717

1818

19-
class Device(object):
19+
class Device:
2020
"""Remote Bluetooth Device Class.
2121
2222
This class instantiates an object that interacts with a remote
@@ -207,7 +207,7 @@ def modalias(self):
207207
constants.DEVICE_INTERFACE, 'Modalias')
208208

209209
@property
210-
def RSSI(self):
210+
def RSSI(self): # pylint: disable=invalid-name
211211
"""
212212
Received Signal Strength Indicator of the remote device.
213213

0 commit comments

Comments
 (0)