Skip to content

自动化SDK:QuecAutomateKit

功能概述

SDK支持用户配置一定的规则, 使设备在指定条件下执行指定的动作

objc
#import <QuecAutomateKit/QuecAutomateKit.h>
/// 初始化
[QuecAutomateService sharedInstance]

SDK集成方式

注意

自动化SDK运行依赖核心库QuecIotSdk, 请先按照快速集成文档集成核心库

objc
pod 'QuecAutomateKit', '~> 0.3.0'

自动化管理

获取自动化列表

接口说明

获取自动化列表, 通过分页请求

objc
- (void)getAutomationListWithPageNumber:(NSInteger)pageNumber
                               pageSize:(NSInteger)pageSize
                                success:(QuecAutomationModelsSuccessBlock)success
                                failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
pageNumber页码号
pageSize分页大小
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
[QuecAutomateService.sharedInstance getAutomationListWithPageNumber:1 pageSize:10 success:^(NSArray<QuecAutomateModel *> * _Nonnull models, NSUInteger total) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

QuecAutomateModel属性定义

字段类型描述
automationIdlong long自动化ID
fidString家庭ID,开启家居模式必填,否则不填
conditionTypeQuecAutomateConditionRuleType触发类型。
QuecAutomateConditionRuleAny = 1 //1: 满足任意
QuecAutomateConditionRuleAll //2: 满足所有
nameString自动化名称
nameTypeint自动化名称生成方式。1:系统生成,2:用户填写
statusboolean启停状态。true:启用,false:停用
preconditionQuecAutomationPreconditionModel自动化生效时间
conditionsNSArray<QuecAutomationConditionModel *> *自动化触发条件
actionsNSArray<QuecAutomationActionModel *> *自动化执行动作

QuecAutomationPreconditionModel属性定义

字段类型描述
effectDateTypeQuecAutomateEffectDateType生效日期类型。
QuecAutomateEffectDateTypeEveryday = 0, /// 每天
QuecAutomateEffectDateTypeWeekly, /// 每周的
QuecAutomateEffectDateTypeMonthly, /// 每月
QuecAutomateEffectDateTypeNamedDate /// 指定日期
effectTimeTypeQuecAutomateEffectTimeType生效时间类型。
QuecAutomateEffectTimeTypeDaytime = 0, /// 白天
QuecAutomateEffectTimeTypeNight, /// 夜晚
QuecAutomateEffectTimeTypeWholeDay, /// 全天
QuecAutomateEffectTimeTypeSpecificTimePeriod /// 特定时间段
startTimeNSString开始时间。生效时间类型为全天和指定时间段时必填,符合HH:mm格式
endTimeNSString结束时间。生效时间类型为全天和指定时间段时必填,符合HH:mm格式
effectDateNSString生效日期。生效日期类型为每天时不填。每周:1,2,3,...7表示周一到周日,周月:1-31号,指定日期:符合MM-dd/MM-dd格式,例:12-19/12-2
regionNameNSString地区名称
locationNSString经纬度
timeZoneNSString时区

QuecAutomationConditionModel属性定义

字段类型描述
typeint触发类型。1: 满足任意,2: 满足所有
iconString图标
nameString条件名称
timerQuecAutomationTimeModel自动化触发条件时间
productKeyString设备的productKey
deviceKeyString设备的deviceKey
propertyQuecAutoProductTSLModel设备属性
sortint条件排序从1开始依次递增

QuecAutomationTimeModel属性定义

字段类型描述
typeint定时类型 0:仅一次 ,1:每天 ,2:自定义
timeString定时时间 23:00 24小时制
dayOfWeekString定时自定义时间段, 格式为 "1,3,4",以 "," 分隔
timeZoneString时区id 例如: GMT+08:00

QuecAutomationPropertyModel属性定义

字段类型描述
identifierint物模型id
codeString物模型id,由于 id 是 Objective-C 的关键字,所以使用 identifier
nameString物模型名称
compareString作为条件的时候有比较符号, 属性值比较运算符:> >= < <= == != REPORT COUNT,其中REPORT为上报的数据
unitString单位
dataTypeString数据类型
valueString属性值
subNameString条件名称

QuecAutomationActionModel属性定义

字段类型描述
typeint执行的动作类型 1-延迟执行后面一个动作 2-修改设备属性 3-修改群组属性 3-修改群组属性 4-执行场景
iconString图标
nameString名称
productKeyString设备的productKey
deviceKeyString设备的deviceKey
sceneIdString场景id
delayTimeNSNumber延迟时间 单位秒
sortint动作排序从1开始递增
propertyQuecAutomationPropertyModel设备属性

创建自动化

接口说明

创建一条自动化规则可以拆分为4个部分

  1. 基础信息
    1. 名称
  2. 生效时间
    1. 时间段
      1. 特定时间段(0:00 ~ 23:59:59)
      2. 全天
      3. 白天/夜晚
    2. 日期
      1. 每一天
      2. 每周的第几天
      3. 每月的第几天
      4. 指定的开始日期和结束日期
  3. 触发条件
    1. 条件选择
      1. 满足任意条件
      2. 满足所有条件
    2. 条件类型 (可有多个)
      1. 指定设备的联动条件
      2. 定时
        1. 一天中的时间点
        2. 一周中哪几天
  4. 执行动作 (可有多个)
    1. 执行设备联动配置
    2. 执行指定的场景
    3. 添加延时

需将4个部分的信息都填入后, 方可创建一条可用的规则

objc
- (void)addAutomationWithModel:(QuecAutomateModel *)model
                       success:(QuecVoidBlock)success
                       failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
model自动化信息
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
QuecAutomationPreconditionModel *precondition = [[QuecAutomationPreconditionModel alloc] init];
precondition.effectDate = @"";
precondition.effectDateType = QuecAutomateEffectDateTypeEveryday;
precondition.effectTimeType = QuecAutomateEffectTimeTypeWholeDay;
precondition.location = @"";
precondition.timeZone = @"GMT+08:00";

QuecAutomationTimeModel *time = QuecAutomationTimeModel.new;
time.type = 0;
time.time = @"14:10";
time.dayOfWeek = @"";
time.timeZone = @"GMT+8:00";
QuecAutomationConditionModel *condition = [[QuecAutomationConditionModel alloc] initWithType:1
                                                                                        icon:@""
                                                                                        name:@""
                                                                                        timer:time
                                                                                    productKey:@""
                                                                                    deviceKey:@""
                                                                                    property:nil
                                                                                        sort:1];
QuecAutomationActionModel *action = [[QuecAutomationActionModel alloc] initWithType:4
                                                                                icon:@"https://xxxxx.png"
                                                                                name:@"sence name"
                                                                            productKey:@""
                                                                            deviceKey:@""
                                                                            sceneId:@"Scene Id"
                                                                            delayTime:@(0)
                                                                            property:nil
                                                                                sort:1];

QuecAutomateModel *automateModel = [[QuecAutomateModel alloc] initWithFid:@"your fid"
                                                            conditionType:QuecAutomateConditionRuleAny
                                                                        name:@"自动化名称"
                                                                    nameType:1
                                                            preconditions:precondition
                                                                conditions:@[condition]
                                                                    actions:@[action]];

[QuecAutomateService.sharedInstance addAutomationWithModel:automateModel
                                                    success:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

编辑自动化

接口说明

编辑已有的自动化规则

objc
- (void)editAutomationWithModel:(QuecAutomateModel *)model
                        success:(QuecVoidBlock)success
                        failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
model自动化信息
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
QuecAutomateModel *automate = QuecAutomateModel.new; /// 云端返回的自动化模型
automate.name = @"new name";
[QuecAutomateService.sharedInstance editAutomationWithModel:automate
                                                    success:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

删除自动化

删除指定的自动化规则

接口说明

objc
- (void)deleteAutomationWithAutomationId:(long long)automationId
                                 success:(QuecVoidBlock)success
                                 failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
automationId自动化id
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
[QuecAutomateService.sharedInstance deleteAutomationWithAutomationId:10010 success:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

查询设备可作为自动化条件和触发动作的物模型

接口说明

objc
- (void)getAutomationTSLWithProductKey:(NSString *)productKey
                                  type:(NSInteger)type
                               success:(QuecAutomationPropertySuccessBlock)success
                               failure:(QuecErrorBlock)failure;
)

参数说明

参数是否必传说明
productKey设备的productKey
type查询类型:0:全部,1:条件,2:动作
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
[QuecAutomateService.sharedInstance getAutomationTSLWithProductKey:@"pk" type:0 success:^(NSArray<QuecProductTSLPropertyModel *> * _Nonnull conditions, NSArray<QuecProductTSLPropertyModel *> * _Nonnull actions) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

QuecProductTSLPropertyModel属性定义同设备SDK

获取自动化详情

接口说明

获取自动化详情

objc
- (void)getAutomationInfoWithAutomationId:(long long)automationId
                                  success:(void(^)(QuecAutomateModel *model))success
                                  failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
automationId自动化id
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
[QuecAutomateService.sharedInstance getAutomationInfoWithAutomationId:10009 success:^(QuecAutomateModel * _Nonnull model) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

开启关闭自动化

接口说明

可使自动化规则启动或者暂停

objc
- (void)updateAutomationSwitchStatusWithAutomationId:(long long)automationId
                                              status:(BOOL)status
                                             success:(QuecVoidBlock)success
                                             failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
automationId自动化id
status启停状态,启用:true,停用:false
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
[QuecAutomateService.sharedInstance updateAutomationSwitchStatusWithAutomationId:10011 status:YES success:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

自动化测试

测试自动化

接口说明

可测试配置的自动化的动作是否可以执行

objc
- (void)testAutomationInfoWithActions:(NSArray<QuecAutomationActionModel *> *)actions
                                timeout:(long)timeout
                              success:(void(^)(long long testResultId))success
                              failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
actions自动化任务
timeout超时时间, 单位秒
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
QuecAutomationActionModel *action = [[QuecAutomationActionModel alloc] initWithType:4
                                                                                   icon:@"https://xxxxx.png"
                                                                                   name:@"sence name"
                                                                             productKey:@""
                                                                              deviceKey:@""
                                                                                sceneId:@"Scene Id"
                                                                              delayTime:@(0)
                                                                               property:nil
                                                                                   sort:1];
    [QuecAutomateService.sharedInstance testAutomationInfoWithActions:@[action]
                                                              timeout:30
                                                              success:^(long long testResultId) {
        /// Next Action
    } failure:^(NSError *error) {
        NSLog(@"check error: %@", error);
    }];

获取自动化测试的结果

接口说明

在执行了自动化测试后, 可以通过结果id来查询自动化执行的结果

objc
- (void)getTestAutomationResultWithId:(long long)testResultId
                              success:(QuecAutomationResultSuccessBlock)success
                              failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
testResultId结果id
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
[QuecAutomateService.sharedInstance getTestAutomationResultWithId:10002 success:^(QuecAutomationResultModel * _Nullable resultModel) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

QuecAutomationResultModel属性定义

字段类型描述
resultNSInteger自动化执行结果 0-全部成功 1-部分成功 2-全部失败
successCountNSInteger成功数量
failCountNSInteger失败数量
overallFailMsgNSString错误信息
timeoutStatusBOOL超时状态
failActionListNSArray<QuecAutomationResultItemModel *> *失败的动作列表

QuecAutomationResultItemModel属性定义

字段类型描述
actionNameNSString动作名称
iconNSString动作图标
failMsgNSString失败原因

自动化日志

获取自动化日志列表

接口说明

自动化执行之后, 可以查询其执行的记录

objc
- (void)getAutomationLogListWithLastLogId:(long long)lastLogId
                                    limit:(NSInteger)limit
                                  success:(void(^)(NSArray<QuecAutomationLogItemModel *> *list))success
                                  failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
lastLogId最后一条日志id
limit获取几条
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
[QuecAutomateService.sharedInstance getAutomationLogListWithLastLogId:99
                                                                limit:10
                                                                success:^(NSArray<QuecAutomationLogItemModel *> * _Nonnull list) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

QuecAutomationLogItemModel属性定义

字段类型描述
automationIdlong自动化id
logIdlong日志id
nameString自动化任务名称
iconString自动化图标
resultint执行结果 0.成功:所有都执行成功即视为成 1.失败:所有都失败即视为失败 2.部分成功
timelong执行时间(时间戳)
logDetailsNSArray<QuecAutomationLogItemActionModel *> *日志详情

QuecAutomationLogItemActionModel属性定义

字段类型描述
actionNameString动作名称
typeint类型 2设备 3群组 4场景
resultboolean执行结果:true成功 false失败
executeTimelong执行时间
actionQuecAutomationPropertyModel物模型属性
actionIconNSString执行动作图标,设备/群组/群组

获取日志详情

接口说明

获取自动化日志详情

objc
- (void)getAutomationLogDetailWithLogId:(long long)logId
                                success:(void(^)(QuecAutomationLogItemModel *detailInfo))success
                                failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
logId日志id
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
[QuecAutomateService.sharedInstance getAutomationLogDetailWithLogId:100
                                                                success:^(QuecAutomationLogItemModel * _Nonnull detailInfo) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

清除自动化日志

接口说明

清除自动化日志, 会删掉所有的日志

objc
- (void)clearAutomationLogsWithSuccess:(QuecVoidBlock)success failure:(QuecErrorBlock)failure;

参数说明

参数是否必传说明
success接口请求成功回调
failure接口请求失败回调

示例代码

objc
[QuecAutomateService.sharedInstance clearAutomationLogsWithSuccess:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];