Skip to content

Commit

Permalink
Merge pull request #1 from teufelaudio/Scan-for-peripherals-takes-opt…
Browse files Browse the repository at this point in the history
…ional-UUID

ScanForPeripherals take optional UUIDs
  • Loading branch information
luizmb authored May 28, 2021
2 parents 2e821cd + 05100d1 commit ff65967
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ extension CoreBluetoothCentralManager: CentralManager {
func scanForPeripherals() -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
_scanForPeripherals(withServices: nil, options: nil)
}
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?) -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
_scanForPeripherals(withServices: serviceUUIDs, options: nil)
}
func scanForPeripherals(options: [String : Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
_scanForPeripherals(withServices: nil, options: options)
}
func scanForPeripherals(withServices serviceUUIDs: [CBUUID], options: [String : Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String : Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
_scanForPeripherals(withServices: serviceUUIDs, options: options)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/CombineBluetooth/Models/CentralManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public protocol CentralManager: BluetoothManager {
var isScanning: AnyPublisher<Bool, Never> { get }
var peripheralConnection: AnyPublisher<PeripheralConnectionEvent, Never> { get }
func scanForPeripherals() -> AnyPublisher<AdvertisingPeripheral, BluetoothError>
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError>
func scanForPeripherals(withServices serviceUUIDs: [CBUUID], options: [String: Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError>
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?) -> AnyPublisher<AdvertisingPeripheral, BluetoothError>
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String: Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError>
func scanForPeripherals(options: [String: Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError>
func retrievePeripherals(withIdentifiers identifiers: [UUID]) -> [BluetoothPeripheral]
func retrieveConnectedPeripherals(withServices serviceUUIDs: [CBUUID]) -> [BluetoothPeripheral]
Expand Down
68 changes: 34 additions & 34 deletions Sources/CombineBluetoothMocks/AutoMockable.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ open class BluetoothPeripheralMock: BluetoothPeripheral {
open var readRSSICalled: Bool {
return readRSSICallsCount > 0
}
open var readRSSIReturnValue: Promise<NSNumber, BluetoothError>!
open var readRSSIClosure: (() -> Promise<NSNumber, BluetoothError>)?
open var readRSSIReturnValue: AnyPublisher<NSNumber, BluetoothError>!
open var readRSSIClosure: (() -> AnyPublisher<NSNumber, BluetoothError>)?

open func readRSSI() -> Promise<NSNumber, BluetoothError> {
open func readRSSI() -> AnyPublisher<NSNumber, BluetoothError> {
readRSSICallsCount += 1
return readRSSIClosure.map({ $0() }) ?? readRSSIReturnValue
}
Expand Down Expand Up @@ -207,10 +207,10 @@ open class BluetoothPeripheralMock: BluetoothPeripheral {
return readCharacteristicValueCallsCount > 0
}
open var readCharacteristicValueReceivedCharacteristic: BluetoothCharacteristic?
open var readCharacteristicValueReturnValue: Promise<BluetoothCharacteristic, BluetoothError>!
open var readCharacteristicValueClosure: ((BluetoothCharacteristic) -> Promise<BluetoothCharacteristic, BluetoothError>)?
open var readCharacteristicValueReturnValue: AnyPublisher<BluetoothCharacteristic, BluetoothError>!
open var readCharacteristicValueClosure: ((BluetoothCharacteristic) -> AnyPublisher<BluetoothCharacteristic, BluetoothError>)?

open func readCharacteristicValue(_ characteristic: BluetoothCharacteristic) -> Promise<BluetoothCharacteristic, BluetoothError> {
open func readCharacteristicValue(_ characteristic: BluetoothCharacteristic) -> AnyPublisher<BluetoothCharacteristic, BluetoothError> {
readCharacteristicValueCallsCount += 1
readCharacteristicValueReceivedCharacteristic = characteristic
return readCharacteristicValueClosure.map({ $0(characteristic) }) ?? readCharacteristicValueReturnValue
Expand Down Expand Up @@ -239,10 +239,10 @@ open class BluetoothPeripheralMock: BluetoothPeripheral {
return writeValueForTypeCallsCount > 0
}
open var writeValueForTypeReceivedArguments: (data: Data, characteristic: BluetoothCharacteristic, type: CBCharacteristicWriteType)?
open var writeValueForTypeReturnValue: Promise<BluetoothCharacteristic, BluetoothError>!
open var writeValueForTypeClosure: ((Data, BluetoothCharacteristic, CBCharacteristicWriteType) -> Promise<BluetoothCharacteristic, BluetoothError>)?
open var writeValueForTypeReturnValue: AnyPublisher<BluetoothCharacteristic, BluetoothError>!
open var writeValueForTypeClosure: ((Data, BluetoothCharacteristic, CBCharacteristicWriteType) -> AnyPublisher<BluetoothCharacteristic, BluetoothError>)?

open func writeValue(_ data: Data, for characteristic: BluetoothCharacteristic, type: CBCharacteristicWriteType) -> Promise<BluetoothCharacteristic, BluetoothError> {
open func writeValue(_ data: Data, for characteristic: BluetoothCharacteristic, type: CBCharacteristicWriteType) -> AnyPublisher<BluetoothCharacteristic, BluetoothError> {
writeValueForTypeCallsCount += 1
writeValueForTypeReceivedArguments = (data: data, characteristic: characteristic, type: type)
return writeValueForTypeClosure.map({ $0(data, characteristic, type) }) ?? writeValueForTypeReturnValue
Expand Down Expand Up @@ -287,10 +287,10 @@ open class BluetoothPeripheralMock: BluetoothPeripheral {
return readDescriptorValueCallsCount > 0
}
open var readDescriptorValueReceivedDescriptor: BluetoothDescriptor?
open var readDescriptorValueReturnValue: Promise<BluetoothDescriptor, BluetoothError>!
open var readDescriptorValueClosure: ((BluetoothDescriptor) -> Promise<BluetoothDescriptor, BluetoothError>)?
open var readDescriptorValueReturnValue: AnyPublisher<BluetoothDescriptor, BluetoothError>!
open var readDescriptorValueClosure: ((BluetoothDescriptor) -> AnyPublisher<BluetoothDescriptor, BluetoothError>)?

open func readDescriptorValue(_ descriptor: BluetoothDescriptor) -> Promise<BluetoothDescriptor, BluetoothError> {
open func readDescriptorValue(_ descriptor: BluetoothDescriptor) -> AnyPublisher<BluetoothDescriptor, BluetoothError> {
readDescriptorValueCallsCount += 1
readDescriptorValueReceivedDescriptor = descriptor
return readDescriptorValueClosure.map({ $0(descriptor) }) ?? readDescriptorValueReturnValue
Expand All @@ -303,10 +303,10 @@ open class BluetoothPeripheralMock: BluetoothPeripheral {
return writeValueForCallsCount > 0
}
open var writeValueForReceivedArguments: (data: Data, descriptor: BluetoothDescriptor)?
open var writeValueForReturnValue: Promise<BluetoothDescriptor, BluetoothError>!
open var writeValueForClosure: ((Data, BluetoothDescriptor) -> Promise<BluetoothDescriptor, BluetoothError>)?
open var writeValueForReturnValue: AnyPublisher<BluetoothDescriptor, BluetoothError>!
open var writeValueForClosure: ((Data, BluetoothDescriptor) -> AnyPublisher<BluetoothDescriptor, BluetoothError>)?

open func writeValue(_ data: Data, for descriptor: BluetoothDescriptor) -> Promise<BluetoothDescriptor, BluetoothError> {
open func writeValue(_ data: Data, for descriptor: BluetoothDescriptor) -> AnyPublisher<BluetoothDescriptor, BluetoothError> {
writeValueForCallsCount += 1
writeValueForReceivedArguments = (data: data, descriptor: descriptor)
return writeValueForClosure.map({ $0(data, descriptor) }) ?? writeValueForReturnValue
Expand All @@ -319,10 +319,10 @@ open class BluetoothPeripheralMock: BluetoothPeripheral {
return openL2CAPChannelPSMCallsCount > 0
}
open var openL2CAPChannelPSMReceivedPSM: CBL2CAPPSM?
open var openL2CAPChannelPSMReturnValue: Promise<L2CAPChannel, BluetoothError>!
open var openL2CAPChannelPSMClosure: ((CBL2CAPPSM) -> Promise<L2CAPChannel, BluetoothError>)?
open var openL2CAPChannelPSMReturnValue: AnyPublisher<L2CAPChannel, BluetoothError>!
open var openL2CAPChannelPSMClosure: ((CBL2CAPPSM) -> AnyPublisher<L2CAPChannel, BluetoothError>)?

open func openL2CAPChannel(PSM: CBL2CAPPSM) -> Promise<L2CAPChannel, BluetoothError> {
open func openL2CAPChannel(PSM: CBL2CAPPSM) -> AnyPublisher<L2CAPChannel, BluetoothError> {
openL2CAPChannelPSMCallsCount += 1
openL2CAPChannelPSMReceivedPSM = PSM
return openL2CAPChannelPSMClosure.map({ $0(PSM) }) ?? openL2CAPChannelPSMReturnValue
Expand All @@ -335,11 +335,11 @@ open class BluetoothServiceMock: BluetoothService {
set(value) { underlyingId = value }
}
open var underlyingId: CBUUID!
open var peripheral: BluetoothPeripheral {
open var peripheral: UUID {
get { return underlyingPeripheral }
set(value) { underlyingPeripheral = value }
}
open var underlyingPeripheral: BluetoothPeripheral!
open var underlyingPeripheral: UUID!
open var isPrimary: Bool {
get { return underlyingIsPrimary }
set(value) { underlyingIsPrimary = value }
Expand Down Expand Up @@ -391,9 +391,9 @@ open class CentralManagerMock: CentralManager {
}
open var scanForPeripheralsWithServicesReceivedServiceUUIDs: [CBUUID]?
open var scanForPeripheralsWithServicesReturnValue: AnyPublisher<AdvertisingPeripheral, BluetoothError>!
open var scanForPeripheralsWithServicesClosure: (([CBUUID]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError>)?
open var scanForPeripheralsWithServicesClosure: (([CBUUID]?) -> AnyPublisher<AdvertisingPeripheral, BluetoothError>)?

open func scanForPeripherals(withServices serviceUUIDs: [CBUUID]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
open func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?) -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
scanForPeripheralsWithServicesCallsCount += 1
scanForPeripheralsWithServicesReceivedServiceUUIDs = serviceUUIDs
return scanForPeripheralsWithServicesClosure.map({ $0(serviceUUIDs) }) ?? scanForPeripheralsWithServicesReturnValue
Expand All @@ -405,11 +405,11 @@ open class CentralManagerMock: CentralManager {
open var scanForPeripheralsWithServicesOptionsCalled: Bool {
return scanForPeripheralsWithServicesOptionsCallsCount > 0
}
open var scanForPeripheralsWithServicesOptionsReceivedArguments: (serviceUUIDs: [CBUUID], options: [String: Any])?
open var scanForPeripheralsWithServicesOptionsReceivedArguments: (serviceUUIDs: [CBUUID]?, options: [String: Any])?
open var scanForPeripheralsWithServicesOptionsReturnValue: AnyPublisher<AdvertisingPeripheral, BluetoothError>!
open var scanForPeripheralsWithServicesOptionsClosure: (([CBUUID], [String: Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError>)?
open var scanForPeripheralsWithServicesOptionsClosure: (([CBUUID]?, [String: Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError>)?

open func scanForPeripherals(withServices serviceUUIDs: [CBUUID], options: [String: Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
open func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String: Any]) -> AnyPublisher<AdvertisingPeripheral, BluetoothError> {
scanForPeripheralsWithServicesOptionsCallsCount += 1
scanForPeripheralsWithServicesOptionsReceivedArguments = (serviceUUIDs: serviceUUIDs, options: options)
return scanForPeripheralsWithServicesOptionsClosure.map({ $0(serviceUUIDs, options) }) ?? scanForPeripheralsWithServicesOptionsReturnValue
Expand Down Expand Up @@ -592,10 +592,10 @@ open class PeripheralManagerMock: PeripheralManager {
return addCallsCount > 0
}
open var addReceivedService: BluetoothService?
open var addReturnValue: Promise<BluetoothService, BluetoothError>!
open var addClosure: ((BluetoothService) -> Promise<BluetoothService, BluetoothError>)?
open var addReturnValue: AnyPublisher<BluetoothService, BluetoothError>!
open var addClosure: ((BluetoothService) -> AnyPublisher<BluetoothService, BluetoothError>)?

open func add(_ service: BluetoothService) -> Promise<BluetoothService, BluetoothError> {
open func add(_ service: BluetoothService) -> AnyPublisher<BluetoothService, BluetoothError> {
addCallsCount += 1
addReceivedService = service
return addClosure.map({ $0(service) }) ?? addReturnValue
Expand Down Expand Up @@ -669,10 +669,10 @@ open class PeripheralManagerMock: PeripheralManager {
return publishL2CAPChannelWithEncryptionCallsCount > 0
}
open var publishL2CAPChannelWithEncryptionReceivedEncryptionRequired: Bool?
open var publishL2CAPChannelWithEncryptionReturnValue: Promise<CBL2CAPPSM, BluetoothError>!
open var publishL2CAPChannelWithEncryptionClosure: ((Bool) -> Promise<CBL2CAPPSM, BluetoothError>)?
open var publishL2CAPChannelWithEncryptionReturnValue: AnyPublisher<CBL2CAPPSM, BluetoothError>!
open var publishL2CAPChannelWithEncryptionClosure: ((Bool) -> AnyPublisher<CBL2CAPPSM, BluetoothError>)?

open func publishL2CAPChannel(withEncryption encryptionRequired: Bool) -> Promise<CBL2CAPPSM, BluetoothError> {
open func publishL2CAPChannel(withEncryption encryptionRequired: Bool) -> AnyPublisher<CBL2CAPPSM, BluetoothError> {
publishL2CAPChannelWithEncryptionCallsCount += 1
publishL2CAPChannelWithEncryptionReceivedEncryptionRequired = encryptionRequired
return publishL2CAPChannelWithEncryptionClosure.map({ $0(encryptionRequired) }) ?? publishL2CAPChannelWithEncryptionReturnValue
Expand All @@ -685,10 +685,10 @@ open class PeripheralManagerMock: PeripheralManager {
return unpublishL2CAPChannelCallsCount > 0
}
open var unpublishL2CAPChannelReceivedPSM: CBL2CAPPSM?
open var unpublishL2CAPChannelReturnValue: Promise<CBL2CAPPSM, BluetoothError>!
open var unpublishL2CAPChannelClosure: ((CBL2CAPPSM) -> Promise<CBL2CAPPSM, BluetoothError>)?
open var unpublishL2CAPChannelReturnValue: AnyPublisher<CBL2CAPPSM, BluetoothError>!
open var unpublishL2CAPChannelClosure: ((CBL2CAPPSM) -> AnyPublisher<CBL2CAPPSM, BluetoothError>)?

open func unpublishL2CAPChannel(_ PSM: CBL2CAPPSM) -> Promise<CBL2CAPPSM, BluetoothError> {
open func unpublishL2CAPChannel(_ PSM: CBL2CAPPSM) -> AnyPublisher<CBL2CAPPSM, BluetoothError> {
unpublishL2CAPChannelCallsCount += 1
unpublishL2CAPChannelReceivedPSM = PSM
return unpublishL2CAPChannelClosure.map({ $0(PSM) }) ?? unpublishL2CAPChannelReturnValue
Expand Down

0 comments on commit ff65967

Please sign in to comment.