findDescriptor method

FaketoothDescriptor? findDescriptor({
  1. required String peripheral,
  2. required String uuid,
})

Finds a descriptor based on the peripheral identifier and descriptor UUID.

Implementation

FaketoothDescriptor? findDescriptor({required String peripheral, required String uuid}) {
  if (_simulatedPeripherals?.isNotEmpty == false) {
    return null;
  }

  for (FaketoothPeripheral p in _simulatedPeripherals!) {
    if (p.identifier.toLowerCase() != peripheral.toLowerCase()) {
      continue;
    }
    for (FaketoothService s in p.services!) {
      for (FaketoothCharacteristic c in s.characteristics!) {
        for (FaketoothDescriptor d in c.descriptors!) {
          if (d.uuid.toLowerCase() == uuid.toLowerCase()) {
            return d;
          }
        }
      }
    }
  }

  return null;
}