房间标签管理

更新时间:2024-08-23 09:48:00下载pdf

支持给房间关联分组标签,例如,给客厅和厨房这两个房间关联 一楼 标签,给主卧和次卧这两个房间关联 二楼 标签。理论上,可以给一个房间关联多个标签。房间的标签是可选项,如果房间没有关联标签,那么该房间属于未分组房间。

房间标签管理对应家庭业务包下的 ThingSmartRoomBiz 类,提供以下接口来实现对房间标签的操作。

ThingSmartRoomBiz 提供了比 ThingSmartRoom 更多的功能。如果您仍在使用 ThingSmartRoom,请参考 此链接

获取标签列表

接口说明

- (void)getRoomTagListWithHomeId:(long long)homeId
                         success:(void (^__nullable)(NSArray<ThingSmartRoomTagDataModel *> * roomTagList))success
                         failure:(ThingFailureError __nullable)failure;

参数说明

参数 说明
homeId 家庭 ID
success 成功回调,返回标签模型列表
failure 失败回调

调用示例

- (void)getRoomTagListWithHomeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] getRoomTagListWithHomeId:homeId success:^(NSArray<ThingSmartRoomTagDataModel *> * _Nonnull roomTagList) {
        //
    } failure:^(NSError * _Nonnull error) {
        //
    }];
}

标签模型-ThingSmartRoomTagDataModel

@interface ThingSmartRoomTagDataModel : NSObject
/// Tag id
@property (nonatomic, assign) NSInteger roomTagId;
/// Tag name
@property (nonatomic, copy) NSString *name;
/// Tag sorting sequence number
@property (nonatomic, assign) NSInteger displayOrder;
/// Tag belong homeId
@property (nonatomic, copy) NSString *groupId;
@end

新建房间标签

新建房间标签,注意标签名不能重复。

接口说明

- (void)createRoomTagWithName:(NSString *)name
                       homeId:(long long)homeId
                      success:(void (^ __nullable)(long long roomTagID))success
                      failure:(ThingFailureError __nullable)failure;

参数说明

参数 说明
name 标签名称
homeId 家庭 ID
success 成功回调
failure 失败回调

调用示例

- (void)createRoomTagListWithHomeId:(long long)homeId name:(NSString *)name {
    [[ThingSmartRoomBiz sharedInstance] createRoomTagWithName:name homeId:homeId success:^(long long roomTagID) {
        //
    } failure:^(NSError * _Nonnull error) {
        //
    }];
}

删除房间标签

删除房间标签仅清理该标签,并不会删除标签下的房间,成功时调用 success 回调。

接口说明

- (void)deleteRoomTagWithRoomTagId:(long long)roomTagId
                           success:(ThingSuccessHandler __nullable)success
                           failure:(ThingFailureError __nullable)failure;

参数说明

参数 说明
roomTagId 标签 ID
success 成功回调
failure 失败回调

调用示例

- (void)deleteRoomTagWithRoomTagId:(long long)roomTagId {
    [[ThingSmartRoomBiz sharedInstance] deleteRoomTagWithRoomTagId:roomTagId success:^{
        //
    } failure:^(NSError * _Nonnull error) {
        //
    }];
}

修改房间标签

更新标签名称,成功时调用 success 回调。

接口说明

- (void)updateRoomTagNameWithRoomTagId:(long long)roomTagId
                                  name:(NSString *)name
                               success:(ThingSuccessHandler __nullable)success
                               failure:(ThingFailureError __nullable)failure;

参数说明

参数 说明
roomTagId 标签 ID
name 标签名称
success 成功回调
failure 失败回调

调用示例

- (void)updateRoomTagNameWithRoomTagId:(long long)roomTagId name:(NSString *)name {
    [[ThingSmartRoomBiz sharedInstance] updateRoomTagNameWithRoomTagId:roomTagId name:name success:^{
        //
    } failure:^(NSError * _Nonnull error) {
        //
    }];
}

排序房间标签

接口说明

- (void)sortRoomTagWithRoomTagIds:(NSArray<NSString *> *)roomTagIds
                           homeId:(long long)homeId
                          success:(ThingSuccessHandler __nullable)success
                          failure:(ThingFailureError __nullable)failure;

参数说明

参数 说明
roomTagIds 排序后的标签 ID 列表
homeId 家庭 ID
success 成功回调
failure 失败回调

调用示例

- (void)updateRoomTagNameWithRoomTagIds:(NSArray<NSString *> *)roomTagIds homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] sortRoomTagWithRoomTagIds:roomTagIds homeId:homeId success:^{
        //
    } failure:^(NSError * _Nonnull error) {
        //
    }];
}

获取房间归属标签

本接口返回家庭下所有房间的标签详情。房间可以没有标签,也可以有多个标签。成功时调用 success 回调。

接口说明

- (void)getRoomListDataModelWithHomeId:(long long)homeId
                               success:(void (^__nullable)(ThingSmartRoomListDataModel * dataModel))success
                               failure:(ThingFailureError __nullable)failure;

参数说明

参数 说明
homeId 家庭 ID
success 成功回调,返回房间标签详情模型 ThingSmartRoomListDataModel
failure 失败回调

调用示例

- (void)getRoomListDataModelWithHomeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] getRoomListDataModelWithHomeId:homeId success:^(ThingSmartRoomListDataModel * _Nonnull dataModel) {
        //
    } failure:^(NSError * _Nonnull error) {
        //
    }];
}

标签详情模型-ThingSmartRoomListDataModel

@interface ThingSmartRoomInfoDataModel : NSObject <NSCopying>
/// Room id
@property (nonatomic, copy) NSString *roomId;
/// List of associated tag ids
@property (nonatomic, copy) NSArray<NSString *> *roomTagIds;
/// Room name
@property (nonatomic, copy) NSString *name;
@end

@interface ThingSmartRoomListDataModel : NSObject <YYModel>
/// List of tagged rooms:<tagId : room>
@property (nonatomic, strong) NSDictionary<NSString *, NSArray<ThingSmartRoomInfoDataModel *> *> *roomGroupMap;
/// List of untagged rooms:<room>
@property (nonatomic, strong) NSArray<ThingSmartRoomInfoDataModel *> *rooms;
@end

修改房间归属标签

批量修改房间归属标签,标签下可以没有房间,成功时调用 success 回调。

接口说明

- (void)manageRoomTagWithRoomRelationship:(NSDictionary<NSString *, NSArray<NSString *> *> *)roomRelationship
                               roomTagIds:(NSArray<NSString *> *)roomTagIds
                                   homeId:(long long)homeId
                                  success:(ThingSuccessHandler __nullable)success
                                  failure:(ThingFailureError __nullable)failure;

参数说明

参数 说明
roomRelationship 当前家庭下有房间的标签列表,参数举例:{ "roomTagId_1":["roomId_1","roomId_2"] }
roomTagIds 当前家庭下所有标签,参数举例:["roomTagId_1", "roomTagId_2", "roomTagId_3"]
homeId 家庭 ID
success 成功回调
failure 失败回调

创建带标签的房间

接口说明

在当前家庭下,直接创建带标签的房间。

- (void)addHomeRoomWithName:(NSString *)roomName
                     homeId:(long long)homeId
                    success:(void(^)(ThingSmartRoomModel *roomModel))success
                    failure:(ThingFailureError)failure;

参数说明

参数 说明
name 房间名称
roomTagId 标签 ID
success 成功回调
failure 失败回调