Pegasus Pairing

Last Updated on : 2024-10-09 02:01:51download

Search devices for Pegasus pairing

Process

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 <TuyaSmartDeviceModel *> *)pegasusDeviceListWithHomeID:(long long)homeID;

Parameters

Parameter Description
homeId The home ID.

Example

Objc:

NSArray <TuyaSmartDeviceModel *> *deviceList = [TuyaSmartPegasusActivator pegasusDeviceListWithHomeID:homeId];

Swift:

let deviceList =  TuyaSmartPegasusActivator.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:(TYSuccessHandler)success
                        failure:(TYFailureError)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 = TuyaSmartPegasusActivator.init()
pegasusActivator.startDiscover(withDevIDs:devids , serverTimeout: 120, clientTimeout: 120) {

} failure: { error in

}

Callback of discovered devices

API description

@protocol TuyaSmartPegasusActivatorDelegate <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:(TuyaSmartPegasusActivator *)activator serverDevice:(TuyaSmartDeviceModel *)serverDeviceModel didFoundDevice:(TuyaSmartDeviceModel *)deviceModel error:(NSError * __nullable)error;

@end

Parameters

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

Example

Objc:

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

Swift:

    func pegasusActivator(_ activator: TuyaSmartPegasusActivator, serverDevice serverDeviceModel: TuyaSmartDeviceModel, didFoundDevice deviceModel: TuyaSmartDeviceModel, 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 TuyaSmartPegasusActivator::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:(TYSuccessHandler)success
                        failure:(TYFailureError)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 = TuyaSmartPegasusActivator.init()
pegasusActivator.stopDiscover(withDevIDs: devIDS) {

} failure: { error in

}

Pair devices

Process

Pegasus Pairing

Start pairing

API description

/// Pairs specified devices by using Pegasus.
///
/// The value of 'token' can be generated in the call of TuyaSmartActivator::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:(TYSuccessHandler)success
                         failure:(TYFailureError)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) {
    TYLogError(error.localizedDescription);
}];

Swift:

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

} failure: { error in

}

Callback of the pairing result

API description

@protocol TuyaSmartPegasusActivatorDelegate <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:(TuyaSmartPegasusActivator *)activator didReceiveDevice:(TuyaSmartDeviceModel *)deviceModel error:(NSError * __nullable)error;

@end

Parameters

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

Example

Objc:

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

}

Swift:

func pegasusActivator(_ activator: TuyaSmartPegasusActivator, didReceiveDevice deviceModel: TuyaSmartDeviceModel, 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:(TYSuccessHandler)success
                          failure:(TYFailureError)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 = TuyaSmartPegasusActivator.init()
pegasusActivator.cancel(withDevIDs: devIDS, uuids: uuids) {

} failure: { error in

}