Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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))
if defs.GATT_SERVICE_INTERFACE in interfaces:
service = interfaces.get(defs.GATT_SERVICE_INTERFACE)
self.services.add_service(
BleakGATTServiceBlueZDBus(service, object_path)
)
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))
self.services.add_characteristic(
BleakGATTCharacteristicBlueZDBus(char, object_path, _service[0].uuid)
)
self._char_path_to_uuid[object_path] = char.get("UUID")
for desc, object_path in _descs:
_characteristic = list(
filter(
lambda x: x.path == desc["Characteristic"],
self.services.characteristics.values(),
)
)
def format_GATT_object(object_path, interfaces):
if defs.GATT_SERVICE_INTERFACE in interfaces:
props = interfaces.get(defs.GATT_SERVICE_INTERFACE)
_type = "{0} Service".format("Primary" if props.get("Primary") else "Secondary")
elif defs.GATT_CHARACTERISTIC_INTERFACE in interfaces:
props = interfaces.get(defs.GATT_CHARACTERISTIC_INTERFACE)
_type = "Characteristic"
elif defs.GATT_DESCRIPTOR_INTERFACE in interfaces:
props = interfaces.get(defs.GATT_DESCRIPTOR_INTERFACE)
_type = "Descriptor"
else:
return None
_uuid = props.get("UUID")
return "\n{0}\n\t{1}\n\t{2}\n\t{3}".format(
_type, object_path, _uuid, uuidstr_to_str(_uuid)
)
def format_GATT_object(object_path, interfaces):
if defs.GATT_SERVICE_INTERFACE in interfaces:
props = interfaces.get(defs.GATT_SERVICE_INTERFACE)
_type = "{0} Service".format("Primary" if props.get("Primary") else "Secondary")
elif defs.GATT_CHARACTERISTIC_INTERFACE in interfaces:
props = interfaces.get(defs.GATT_CHARACTERISTIC_INTERFACE)
_type = "Characteristic"
elif defs.GATT_DESCRIPTOR_INTERFACE in interfaces:
props = interfaces.get(defs.GATT_DESCRIPTOR_INTERFACE)
_type = "Descriptor"
else:
return None
_uuid = props.get("UUID")
return "\n{0}\n\t{1}\n\t{2}\n\t{3}".format(
_type, object_path, _uuid, uuidstr_to_str(_uuid)
)
# 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))
if defs.GATT_SERVICE_INTERFACE in interfaces:
service = interfaces.get(defs.GATT_SERVICE_INTERFACE)
self.services.add_service(
BleakGATTServiceBlueZDBus(service, object_path)
)
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))
self.services.add_characteristic(
BleakGATTCharacteristicBlueZDBus(char, object_path, _service[0].uuid)
)
self._char_path_to_uuid[object_path] = char.get("UUID")
for desc, object_path in _descs:
_characteristic = list(
filter(
lambda x: x.path == desc["Characteristic"],
self.services.characteristics.values(),
)