房间场景管理

更新时间:2024-08-23 09:47:59下载pdf

本文主要操作场景跟房间的关联关系。例如,将场景保存至某些房间内,在房间内批量移除或设置场景。

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

场景保存时关联房间

接口说明

/// Add a scene.
/// @param sceneInfo The added scene attributes.
/// @param homeID The home ID.
/// @param success On success, return the ThingSmartSceneModel object.
/// @param failure When an error occurred, return error.
+ (void)addScene:(TSceneRequestInfo *)sceneInfo
          homeID:(long long)homeID
         success:(ThingSceneGetModelCompletion)success
         failure:(ThingFailureError)failure;

参数说明

参数 类型 说明
sceneInfo TSceneRequestInfo 对象 保存的场景数据信息
homeID long long 家庭 ID
success block 保存成功返回场景模型
failure block 保存失败返回错误信息

TSceneRequestInfo 对象

参数 类型 说明
sceneModel ThingSmartSceneModel 场景模型数据
needCleanGidSid bool 是否需要清除标准场景信息,一般设置为 false

ThingSmartSceneModel 模型相关房间参数

参数 类型 说明
roomIds array 房间 ID 数组

调用示例

Objective-C

- (void)saveScene:(ThingSmartSceneModel *)sceneModel inRoom:(NSArray *)roomIds hoomId:(long long)homeId {
    sceneModel.roomIds = roomIds;
    
    TSceneRequestInfo *requestInfo = [[TSceneRequestInfo alloc] init];
    requestInfo.sceneModel = sceneModel;
    requestInfo.needCleanGidSid = NO;

    [ThingSmartScene addScene:requestInfo homeID:homeId success:^(ThingSmartSceneModel * _Nonnull scene) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift

func saveScene(sceneModel: ThingSmartSceneModel, inRoom: [String], hoomId: Int64) {
    sceneModel.roomIds = inRoom
    
    let requestInfo = TSceneRequestInfo.init()
    requestInfo.sceneModel = sceneModel
    requestInfo.needCleanGidSid = false
    
    ThingSmartScene.add(requestInfo, homeID: hoomId) { resultModel in
        
    } failure: { error in
        
    }
}

批量移除房间下的场景

接口说明

在当前家庭中,在某个房间内批量移除所选场景。

/// Remove scenes in the specified room.
/// @param roomId The room ID.
/// @param sceneIds The list of scene IDs, eg: "id1,id2,id3"
/// @param success Success callback.
/// @param failure Failure callback.
- (void)removeSceneWithHomeId:(long long)homeId
                       roomId:(NSString *)roomId
                     sceneIds:(NSString *)sceneIds
                      success:(ThingSuccessBOOL)success
                      failure:(ThingFailureError)failure;

参数说明

参数 类型 说明
homeId long long 家庭 ID
roomId string 房间 ID
sceneIds string 场景 ID 列表,例如,"id1,id2,id3"
success block 成功返回 true,否则返回 false
failure block 返回错误信息

调用示例

Objective-C

- (void)removeScenesInRoom:(NSString *)roomId sceneIds:(NSString *)sceneIds hoomId:(long long)homeId {
    [[ThingSmartSceneManager sharedInstance] removeSceneWithHomeId:homeId roomId:roomId sceneIds:sceneIds success:^(BOOL result) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift

func removeScene(hoomId: Int64, roomId: String, sceneIds: String) {
    ThingSmartSceneManager.sharedInstance().removeScene(withHomeId: hoomId, roomId: roomId, sceneIds: sceneIds) { res in
        
    } failure: { error in
        
    }
}

排序房间内的场景

接口说明

在当前家庭中,在某个房间内对所选场景进行排序。

/// Sort scenes in the specified room.
/// @param roomId The room ID.
/// @param sceneIds The list of scene IDs, eg: "id1,id2,id3"
/// @param success Success callback.
/// @param failure Failure callback.
- (void)sortSceneWithHomeId:(long long)homeId
                       room:(NSString *)roomId
                   sceneIds:(NSString *)sceneIds
                    success:(ThingSuccessBOOL)success
                    failure:(ThingFailureError)failure;

参数说明

参数 类型 说明
homeId long long 家庭 ID
roomId string 房间 ID
sceneIds string 场景 ID 列表,例如,"id1,id2,id3"
success block 成功返回 true,否则返回 false
failure block 返回错误信息

调用示例

Objective-C

- (void)sortScenesInRoom:(NSString *)roomId sceneIds:(NSString *)sceneIds hoomId:(long long)homeId {
    [[ThingSmartSceneManager sharedInstance] sortSceneWithHomeId:homeId room:roomId sceneIds:sceneIds success:^(BOOL result) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift

func sortScenes(roomId: String, sceneIds: String, hoomId: Int64) {
    ThingSmartSceneManager.sharedInstance().sortScene(withHomeId: hoomId, room: roomId, sceneIds: sceneIds) { res in
        
    } failure: { error in
        
    }
}

批量设置场景所在的房间

接口说明

在当前家庭中,将所选场景设置到所选的房间内。

/// Batch save scenes in specified rooms.
/// @param gid The home ID.
/// @param ruleIds The list of scene IDs.
/// @param roomIds The list of room IDs.
/// @param success Success callback.
/// @param failure Failure callback.
- (void)batchSaveSceneInRoomsWithGid:(long long)gid
                             ruleIds:(NSArray<NSString *> *)ruleIds
                             roomIds:(NSArray<NSString *> *)roomIds
                             success:(ThingSuccessBOOL)success
                             failure:(ThingFailureError)failure;

参数说明

参数 类型 说明
gid long long 家庭 ID
ruleIds array 场景 ID 列表
roomIds array 房间 ID 列表
success block 成功返回 true,否则返回 false
failure block 返回错误信息

调用示例

Objective-C

- (void)batchSaveScenesInRooms:(NSArray<NSString *> *)roomIds sceneIds:(NSArray<NSString *> *)sceneIds hoomId:(long long)homeId {
    [[ThingSmartSceneManager sharedInstance] batchSaveSceneInRoomsWithGid:homeId ruleIds:sceneIds roomIds:roomIds success:^(BOOL result) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift

func batchSaveScenes(roomIds: [String], sceneIds: [String], hoomId: Int64) {
    ThingSmartSceneManager.sharedInstance().batchSaveSceneInRooms(withGid: hoomId, ruleIds: sceneIds, roomIds: roomIds) { res in
        
    } failure: { error in
        
    }
}