Pegasus Pairing

Last Updated on : 2024-05-15 08:21:06download

Search devices for Pegasus pairing

Get devices that support Pegasus pairing

API description

/// Returns the devices that support Pegasus.
/// @param homeID The home ID.
/// @return A list of devices that support Pegasus.
+ (NSArray <ThingSmartDeviceModel *> *)pegasusDeviceListWithHomeID:(long long)homeID;

Parameters

Parameter Description
homeId The home ID.

Example

Objc:

NSArray <ThingSmartDeviceModel *> *deviceList = [ThingSmartPegasusActivator pegasusDeviceListWithHomeID:homeId];

Swift:

let deviceList =  ThingSmartPegasusActivator.pegasusDeviceList(withHomeID: homeId)

Search devices for Pegasus pairing

API description

/// Start Pegasus Activator discover pending device.
/// @param devIDs Device ID list
/// @param serverTimeout Configured devices, search timeout for devices to be configured.
/// @param clientTimeout Pending devices, pending devices is searched for and not added to the family timeout.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)startDiscoverWithDevIDs:(NSArray<NSString *> *)devIDs
                  serverTimeout:(NSTimeInterval)serverTimeout
                  clientTimeout:(NSTimeInterval)clientTimeout
                        success:(ThingSuccessHandler)success
                        failure:(ThingFailureError)failure;

Parameters

Parameter Description
devIDs The list of devices that support Pegasus pairing.
serverTimeout The timeout value for the server to search for devices to be paired. Unit: seconds.
clientTimeout The timeout value for the client. Unit: seconds.
success The success callback.
failure The failure callback.

Example

Objc:

[self.pegasusActivator startDiscoverWithDevIDs:dArr serverTimeout:120 clientTimeout:120 success:^{
} failure:^(NSError *error) {
    NSLog("The callback that is executed when no clients are found.");
}];

Swift:

let pegasusActivator = ThingSmartPegasusActivator.init()
pegasusActivator.startDiscover(withDevIDs:devids , serverTimeout: 120, clientTimeout: 120) {

} failure: { error in

}

Callback of discovered devices

API description

@protocol ThingSmartPegasusActivatorDelegate <NSObject>

/// Devices found by Pegasus.
/// @param activator Activator instance.
/// @param serverDeviceModel Device in the home that supports pegasus.
/// @param deviceModel The device is found, but there is no device ID at this time.
/// @param error Error message.
- (void)pegasusActivator:(ThingSmartPegasusActivator *)activator serverDevice:(ThingSmartDeviceModel *)serverDeviceModel didFoundDevice:(ThingSmartDeviceModel *)deviceModel error:(NSError * __nullable)error;

@end

Parameters

Parameter Description
activator The object of ThingSmartPegasusActivator for pairing.
serverDeviceModel The list of devices that support Pegasus pairing.
deviceModel The discovered client.
error The error message.

Example

Objc:

- (void)pegasusActivator:(ThingSmartPegasusActivator *)activator serverDevice:(ThingSmartDeviceModel *)serverDeviceModel didFoundDevice:(ThingSmartDeviceModel *)deviceModel error:(NSError * __nullable)error {
    NSLog(@"⚡️⚡️⚡️ pegasus did found, server:%@ client:%@ error:%@",serverDeviceModel.devId, deviceModel.uuid, error);
}

Swift:

    func pegasusActivator(_ activator: ThingSmartPegasusActivator, serverDevice serverDeviceModel: ThingSmartDeviceModel, didFoundDevice deviceModel: ThingSmartDeviceModel, error: Error?) {

    }

Stop searching

API description

/// Stops pairing devices by Pegasus after devices are paired.
///
/// The value of 'devIDs' is generated in the call of ThingSmartPegasusActivator::pegasusDeviceListWithHomeID:.
///
/// @param devIDs A list of devices that support Pegasus.
/// @param success Called when the task is finished.
/// @param failure Called when the task is interrupted by an error.
- (void)stopDiscoverWithDevIDs:(NSArray<NSString *> *)devIDs
                        success:(ThingSuccessHandler)success
                        failure:(ThingFailureError)failure;

Parameters

Parameter Description
devIDs The list of devices that support Pegasus pairing.
success The success callback.
failure The failure callback.

Example

Objc:

[self.pegasusActivator stopDiscoverWithDevIDs:dArr success:^{
} failure:^(NSError *error) {
}];

Swift:

let pegasusActivator = ThingSmartPegasusActivator.init()
pegasusActivator.stopDiscover(withDevIDs: devIDS) {

} failure: { error in

}

Pair devices

Start pairing

API description

/// Pairs specified devices by using Pegasus.
///
/// The value of 'token' can be generated in the call of ThingSmartActivator::getTokenWithHomeId:success:failure:.
///
/// @param devIDs A list of devices that support Pegasus.
/// @param UUIDs A list of UUIDs of devices to be paired.
/// @param token The pairing token.
/// @param timeout The timeout value. Unit: seconds. Default value: 100.
/// @param success Called when the task is finished.
/// @param failure Called when the task is interrupted by an error.
- (void)startActivatorWithDevIDs:(NSArray<NSString *> *)devIDs
                           UUIDs:(NSArray<NSString *> *)UUIDs
                           token:(NSString *)token
                         timeout:(NSTimeInterval)timeout
                         success:(ThingSuccessHandler)success
                         failure:(ThingFailureError)failure;

Parameters

Parameter Description
devID The list of devices that support Pegasus pairing.
UUIDs The list of client IDs.
token The pairing token.
timeout The timeout value.
success The success callback.
failure The failure callback.

Example

Objc:

[self.pegasusActivator startActivatorWithDevIDs:dArr UUIDs:mArr.copy token:result timeout:120 success:^{
} failure:^(NSError *error) {
    ThingLogError(error.localizedDescription);
}];

Swift:

let pegasusActivator = ThingSmartPegasusActivator.init()
pegasusActivator.start(withDevIDs: devIDS, uuids: uuids, token: token, timeout: 120) {

} failure: { error in

}

Callback of the pairing result

API description

@protocol ThingSmartPegasusActivatorDelegate <NSObject>

/// Returns the devices that are found by Pegasus.
/// @param activator The activator instance.
/// @param deviceModel The device that is found by Pegasus.
/// @param error An error occurs while processing the request.
- (void)pegasusActivator:(ThingSmartPegasusActivator *)activator didReceiveDevice:(ThingSmartDeviceModel *)deviceModel error:(NSError * __nullable)error;

@end

Parameters

Parameter Description
activator The object of ThingSmartPegasusActivator for pairing.
deviceModel The paired device.
error The error message.

Example

Objc:

- (void)pegasusActivator:(ThingSmartPegasusActivator *)activator didReceiveDevice:(ThingSmartDeviceModel *)deviceModel error:(NSError * __nullable)error {
        NSLog(@"⚡️⚡️⚡️ pegasus did receive, client-uuid:%@ devID:%@ error:%@",deviceModel.uuid,deviceModel.devId,error);

}

Swift:

func pegasusActivator(_ activator: ThingSmartPegasusActivator, didReceiveDevice deviceModel: ThingSmartDeviceModel, error: Error?) {

}

Stop pairing

API description

/// Cancels the Pegasus-based pairing of devices.
/// @param devIDs A list of devices that support Pegasus.
/// @param UUIDs A list of UUIDs of devices to be paired.
/// @param success Called when the task is finished.
/// @param failure Called when the task is interrupted by an error.
- (void)cancelActivatorWithDevIDs:(NSArray<NSString *> *)devIDs
                            UUIDs:(NSArray<NSString *> *)UUIDs
                          success:(ThingSuccessHandler)success
                          failure:(ThingFailureError)failure;

Parameters

Parameter Description
devIDs The list of devices that support Pegasus pairing.
UUIDs The list of client IDs.
success The success callback.
failure The failure callback.

Example

Objc:

[self.pegasusActivator cancelActivatorWithDevIDs:dArr UUIDs:mArr.copy success:^{
} failure:^(NSError *error) {
}];

Swift:

let pegasusActivator = ThingSmartPegasusActivator.init()
pegasusActivator.cancel(withDevIDs: devIDS, uuids: uuids) {

} failure: { error in

}