Skip to content

Commit 01df132

Browse files
committed
Add optional managed parameter to device c’tor
Sometimes we might want to create a `Device` instance without it being managed by the device managed. This is for example, if we simply want to get a few attributes of a device if all we have is the MAC address. In that case, we create a Device instance, read the attributes and then forget about the instance. Particularly of interest for sub classes of `DeviceManager` who want to decide on certain device properties if they then create a subclass instance of that `Device` or not.
1 parent 76ca20a commit 01df132

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gatt/gatt_linux.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def remove_device(self, mac_address):
210210

211211

212212
class Device:
213-
def __init__(self, mac_address, manager):
213+
def __init__(self, mac_address, manager, managed=True):
214214
"""
215215
Represents a BLE GATT device.
216216
@@ -219,6 +219,10 @@ def __init__(self, mac_address, manager):
219219
220220
:param mac_address: MAC address of this device
221221
:manager: `DeviceManager` that shall manage this device
222+
:managed: If False, the created device will not be managed by the device manager
223+
Particularly of interest for sub classes of `DeviceManager` who want
224+
to decide on certain device properties if they then create a subclass
225+
instance of that `Device` or not.
222226
"""
223227

224228
self.mac_address = mac_address
@@ -236,7 +240,8 @@ def __init__(self, mac_address, manager):
236240
self._properties_signal = None
237241
self._connect_retry_attempt = None
238242

239-
manager._manage_device(self)
243+
if managed:
244+
manager._manage_device(self)
240245

241246
def advertised(self):
242247
"""

0 commit comments

Comments
 (0)