Room Scene Management

Last Updated on : 2024-08-23 09:47:59download

This topic describes how to manage the scene associated with a room. For example, associate a scene with a room and bulk remove or set scenes for a room.

The ThingSmartRoomBiz component offers more features than the ThingSmartRoom. If you are still using ThingSmartRoom, please refer to this document.

Associate a room when saving a scene

API description

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

Parameters

Parameter Type Description
sceneInfo TSceneRequestInfo object The saved scene data.
homeID long long The home ID.
success block The scene model returned on successful saving.
failure block The error code returned on failed saving.

TSceneRequestInfo object

Parameter Type Description
sceneModel ThingSmartSceneModel The scene model.
needCleanGidSid bool Specify whether to clear the standard scene information, usually set to false.

Room parameter for ThingSmartSceneModel

Parameter Type Description
roomIds array An array of room IDs.

Example

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

    }
}

Bulk remove scenes from a room

API description

In the current home, bulk remove the selected scenes from a specific room.

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

Parameters

Parameter Type Description
homeId long long The home ID.
roomId string The room ID.
sceneIds string The list of scene IDs, for example, "id1,id2,id3".
success block true is retuned on success. Otherwise, false is returned.
failure block Return error

Example

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 a room

API description

In the current home, sort the selected scene in a specific room.

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

Parameters

Parameter Type Description
homeId long long The home ID.
roomId string The room ID.
sceneIds string The list of scene IDs, for example, "id1,id2,id3".
success block true is retuned on success. Otherwise, false is returned.
failure block Return error

Example

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

    }
}

Bulk set rooms for a scene

API description

In the current home, assign the selected scene to a specific room.

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

Parameters

Parameter Type Description
gid long long The home ID.
ruleIds array The list of scene IDs.
roomIds array The list of room IDs.
success block true is retuned on success. Otherwise, false is returned.
failure block Return error

Example

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

    }
}