简体中文
简体中文
English
联系我们
注册
登录
layout空间导航

闪电配网

更新时间:2022-03-03 06:45:12

闪电搜索

流程示意

闪电配网

查询支持闪电配网的设备

接口说明

/// 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;

参数说明

参数 说明
homeId 站点 ID

示例代码

Objc:

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

Swift:

let deviceList =  TuyaSmartPegasusActivator.pegasusDeviceList(withHomeID: homeId)

闪电搜索

接口说明

/// 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;

参数说明

参数 说明
devIDs 站点中支持闪电配网的设备
serverTimeout 已配网设备搜索时长,单位为秒
clientTimeout 待配网设备锁定时长,单位为秒
success 成功回调
failure 失败回调

示例代码

Objc:

[self.pegasusActivator startDiscoverWithDevIDs:dArr serverTimeout:120 clientTimeout:120 success:^{
} failure:^(NSError *error) {
    NSLog("无待配网设备返回");
}];

Swift:

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

} failure: { error in

}

搜索设备回调

接口说明

@protocol TuyaSmartPegasusActivatorDelegate <NSObject>

/// Devices found by Pegasus.
/// @param activator Activator instance.
/// @param serverDeviceModel Device in the home that support 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

参数说明

参数 说明
activator 配网使用 TuyaSmartPegasusActivator 实例对象
serverDeviceModel 支持闪电的设备
deviceModel 搜索发现的待配网设备
error 错误消息

示例代码

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?) {

    }

停止搜索

接口说明

/// 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;

参数说明

参数 说明
devIDs 站点中支持闪电配网的设备 ID
success 成功回调
failure 失败回调

示例代码

Objc:

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

Swift:

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

} failure: { error in

}

闪电配网

流程示意

闪电配网

开始配网

接口说明

/// 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;

参数说明

参数 说明
devID 站点中支持闪电配网的设备 ID
UUIDs 待配网设备 ID
token 配网 Token
timeout 超时时间
success 完成回调
failure 失败回调

示例代码

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

}

配网结果回调

接口说明

@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

参数说明

参数 说明
activator 配网使用 TuyaSmartPegasusActivator 实例对象
deviceModel 配网成功设备
error 错误消息

示例代码

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?) {

}

停止配网

接口说明

/// 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;

参数说明

参数 说明
devIDs 站点中支持闪电配网的设备 ID
UUIDs 待配网设备 ID
success 完成回调
failure 失败回调

示例代码

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

}