Refactored DBus backend services resolver somewhat
Merge
@@ -176,8 +176,11 @@ class BleakClientBlueZDBus(BaseBleakClient):
self._bus, self.loop, self._device_path + "/service"
)
- # no guarantee service listed before charachteristics in objs
- # need multiple iterations
+ # There is no guarantee that services are listed before characteristics
+ # Managed Objects dict.
+ # Need multiple iterations to construct the Service Collection
+
+ _chars, _descs = [], []
for object_path, interfaces in objs.items():
logger.debug(utils.format_GATT_object(object_path, interfaces))
@@ -186,11 +189,14 @@ class BleakClientBlueZDBus(BaseBleakClient):
self.services.add_service(
BleakGATTServiceBlueZDBus(service, object_path)
)
-
- for object_path, interfaces in objs.items():
- logger.debug(utils.format_GATT_object(object_path, interfaces))
- if defs.GATT_CHARACTERISTIC_INTERFACE in interfaces:
+ elif defs.GATT_CHARACTERISTIC_INTERFACE in interfaces:
char = interfaces.get(defs.GATT_CHARACTERISTIC_INTERFACE)
+ _chars.append([char, object_path])
+ elif defs.GATT_DESCRIPTOR_INTERFACE in interfaces:
+ desc = interfaces.get(defs.GATT_DESCRIPTOR_INTERFACE)
+ _descs.append([desc, object_path])
+
+ for char, object_path in _chars:
_service = list(
filter(lambda x: x.path == char["Service"], self.services)
)
@@ -201,10 +207,7 @@ class BleakClientBlueZDBus(BaseBleakClient):
)
self._char_path_to_uuid[object_path] = char.get("UUID")
- for object_path, interfaces in objs.items():
- logger.debug(utils.format_GATT_object(object_path, interfaces))
- if defs.GATT_DESCRIPTOR_INTERFACE in interfaces:
- desc = interfaces.get(defs.GATT_DESCRIPTOR_INTERFACE)
+ for desc, object_path in _descs:
_characteristic = list(
filter(
lambda x: x.path == desc["Characteristic"],
