Skip to content

Commit ee23e1b

Browse files
author
Rūdolfs Ošiņš
authored
Merge pull request #20 from rudolfs/master
Add remove all devices method
2 parents 52b0bcc + 6a356e8 commit ee23e1b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

gatt/gatt_linux.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def devices(self):
121121
"""
122122
Returns all known Bluetooth devices.
123123
"""
124+
self.update_devices()
124125
return self._devices.values()
125126

126127
def start_discovery(self, service_uuids=[]):
@@ -208,6 +209,24 @@ def remove_device(self, mac_address):
208209
# TODO: Implement
209210
pass
210211

212+
def remove_all_devices(self, skip_alias=None):
213+
self.update_devices()
214+
215+
keys_to_be_deleted = []
216+
for key, device in self._devices.items():
217+
if skip_alias and device.alias() == skip_alias:
218+
continue
219+
mac_address = device.mac_address.replace(':', '_').upper()
220+
path = '/org/bluez/%s/dev_%s' % (self.adapter_name, mac_address)
221+
self._adapter.RemoveDevice(path)
222+
keys_to_be_deleted.append(key)
223+
224+
for key in keys_to_be_deleted:
225+
del self._devices[key]
226+
227+
self.update_devices()
228+
229+
211230

212231
class Device:
213232
def __init__(self, mac_address, manager, managed=True):

0 commit comments

Comments
 (0)