Room Information Management

Last Updated on : 2023-10-07 09:53:11download

This topic describes how to implement the features of room management using APIs. These APIs allow you to create, modify, and remove a room, manage devices or groups in a room, and register listeners for receiving room-based event callbacks. The class ThingSmartRoomBiz is used for room management to implement operations on a room.

Class (or protocol) Description
ThingSmartRoomBiz Room management class
ThingSmartRoomModel Room model class
ThingSmartRoomBizDelegate Room delegate protocol

Data model of ThingSmartRoomModel

Field Type Description
roomId long long The room ID.
iconUrl NSString The room icon.
name NSString The name of the room.
displayOrder NSInteger The order of rooms.

Add a room

Add a room in a specific home. You need to pass in the room name and home ID. Make a callback on success to return the room model. Additionally, you can register a listener and implement the delegate method ThingSmartRoomBizDelegate to receive a callback when a room is added.

API description

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

Parameter description

Parameters Description
roomName The name of the room to add.
homeId The home ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)addRoom:(NSString *)roomName homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] addHomeRoomWithName:roomName homeId:homeId success:^(ThingSmartRoomModel *roomModel) {

    } failure:^(NSError *error) {

    }];
}

Swift:

func addRoom(roomName:String, homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().addHomeRoom(withName: roomName, homeId: homeId) { roomModel in

    } failure: { error in

    }
}

Remove a room

Remove a room from a specific home. You need to pass in the room ID and home ID. Make a callback on success. Additionally, you can register a listener and implement the delegate method ThingSmartRoomBizDelegate to receive a callback when a room is removed.

API description

- (void)removeHomeRoomWithRoomId:(long long)roomId
                          homeId:(long long)homeId
                         success:(ThingSuccessHandler)success
                         failure:(ThingFailureError)failure;

Parameter description

Parameters Description
roomId The ID of the room to remove.
homeId The ID of the home to which the room belongs.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)removeRoom:(long long)roomId homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] removeHomeRoomWithRoomId:roomId homeId:homeId success:^{

    } failure:^(NSError *error) {

    }];
}

Swift:

func removeRoom(roomId:Int64, homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().removeHomeRoom(withRoomId: roomId, homeId: homeId) {

    } failure: { error in

    }
}

Rename a room

Change the name of a room. The new name cannot be empty. Make a callback on success to return the room model. Additionally, you can register a listener and implement the delegate method ThingSmartRoomBizDelegate to receive a callback when a room is renamed.

API description

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

Parameter description

Parameters Description
roomName The new name of the room.
roomId The ID of the target room.
homeId The ID of the home to which the room belongs.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)updateRoomWithName:(NSString *)roomName roomId:(long long)roomId homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] updateHomeRoomWithName:roomName roomId:roomId homeId:homeId success:^(ThingSmartRoomModel *roomModel) {

    } failure:^(NSError *error) {

    }];
}

Swift:

func updateRoom(roomName:String, roomId:Int64, homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().updateHomeRoom(withName: roomName, roomId: roomId, homeId: homeId) { roomModel in

    } failure: { error in

    }
}

Query the list of rooms in a home

Query the list of rooms in a home. You need to pass in the home ID. Make a callback on success to return the array of the room model.

API description

- (void)getRoomListWithHomeId:(long long)homeId
                      success:(void(^)(NSArray <ThingSmartRoomModel *> *roomList))success
                      failure:(ThingFailureError)failure;

Parameter description

Parameters Description
homeId The home ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getRoomListWithHomeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] getRoomListWithHomeId:homeId success:^(NSArray<ThingSmartRoomModel *> *roomList) {

    } failure:^(NSError *error) {

    }];
}

Swift:

func getRoomList(with homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().getRoomList(withHomeId: homeId) { roomModelArray in

    } failure: { error in

    }
}

Query the list of default rooms

Get the list of default rooms when the user creates a home. The default room model includes the room name and whether it is selected by default.

API description

- (void)getDefaultRoomsWithSuccess:(void(^)(NSArray <ThingSmartDefaultRoomItem *>*rooms))success
                           failure:(ThingFailureError)failure;

Parameter description

Parameters Description
success The success callback.
failure The failure callback.

Data model of ThingSmartDefaultRoomItem

Field Type Description
name NSString The name of the room.
isSelected BOOL Specifies whether the room is selected by default.

Example

Objective-C:

- (void)getDefaultRoomList {
    [[ThingSmartRoomBiz sharedInstance] getDefaultRoomsWithSuccess:^(NSArray<ThingSmartDefaultRoomItem *> *rooms) {

    } failure:^(NSError *error) {

    }];
}

Swift:

func getDefaultRoomList() {
    ThingSmartRoomBiz.sharedInstance().getDefaultRooms { roomList in

    } failure: { error in

    }
}

Get recommended room names

When the user adds a room, get the recommended room names. Make a callback on success to return the list of recommended names.

API description

- (void)getRecommendRoomsWithSuccess:(void(^)(NSArray<NSString *> *rooms))success
                             failure:(ThingFailureError)failure;

Parameter description

Parameters Description
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getRecommendRoomList {
    [[ThingSmartRoomBiz sharedInstance] getRecommendRoomsWithSuccess:^(NSArray<NSString *> *rooms) {

    } failure:^(NSError *error) {

    }];
}

Swift:

func getRecommendRoomList() {
    ThingSmartRoomBiz.sharedInstance().getRecommendRooms { roomList in

    } failure: { error in
        <#code#>
    }
}

Sort the list of rooms

Sort the list of rooms in a home. Pass in the list of rooms after sorting and the home ID. Make a callback on success. Additionally, you can register a listener and implement the delegate method ThingSmartRoomBizDelegate to receive a callback when rooms are sorted.

API description

- (void)sortRoomList:(NSArray <ThingSmartRoomModel *> *)rooms
              homeId:(long long)homeId
             success:(ThingSuccessHandler)success
             failure:(ThingFailureError)failure;

Parameter description

Parameters Description
rooms The list of rooms to sort.
homeId The ID of the home to which the room belongs.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)sortRoomList:(NSArray *)roomList homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] sortRoomList:roomList homeId:homeId success:^{

    } failure:^(NSError *error) {

    }];
}

Swift:

func sort(roomList:[ThingSmartRoomModel], homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().sortRoomList(roomList, homeId: homeId) {

    } failure: { error in

    }
}

Organize devices or groups by room

Pass in the device ID or group ID to add multiple paired devices or groups to a room at once. Passing in an empty array will remove devices or groups from a room. Additionally, you can register a listener and implement the delegate method ThingSmartRoomBizDelegate to receive a callback when devices or groups are organized by room.

API description

- (void)saveBatchRoomRelationWithDeviceGroupList:(NSArray <NSString *> *)deviceGroupList
                                          roomId:(long long)roomId
                                          homeId:(long long)homeId
                                         success:(ThingSuccessHandler)success
                                         failure:(ThingFailureError)failure;

Parameter description

Parameters Description
deviceGroupList The list of device IDs or group IDs.
roomId The room ID.
homeId The ID of the home to which the room belongs.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)saveBatchList:(NSArray *)deviceGroupList roomId:(long long)roomId homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] saveBatchRoomRelationWithDeviceGroupList:deviceGroupList roomId:roomId homeId:homeId success:^{

    } failure:^(NSError *error) {

    }];
}

Swift:

func saveBatchList(deviceGroupList:[String], roomId:Int64, homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().saveBatchRoomRelation(withDeviceGroupList: deviceGroupList, roomId: roomId, homeId: homeId) {

    } failure: { error in

    }
}

Add a device to a room

Add a paired device to a room. Make a callback on success. Additionally, you can register a listener and implement the delegate method ThingSmartRoomBizDelegate to receive a callback when devices are organized by room.

API description

- (void)addDeviceWithDeviceId:(NSString *)deviceId
                       roomId:(long long)roomId
                       homeId:(long long)homeId
                      success:(ThingSuccessHandler)success
                      failure:(ThingFailureError)failure;

Parameter description

Parameters Description
deviceId The ID of the target device.
roomId The room ID.
homeId The ID of the home to which the room belongs.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)addDevice:(NSString *)devId roomId:(long long)roomId homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] addDeviceWithDeviceId:devId roomId:roomId homeId:homeId success:^{

    } failure:^(NSError *error) {

    }];
}

Swift:

func addDevice(devId:String, roomId:Int64, homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().addDevice(withDeviceId: devId, roomId: roomId, homeId: homeId) {

    } failure: { error in

    }
}

Remove a device from a room

Remove a device from a room. Make a callback on success. This operation does not remove the device from the home. Additionally, you can register a listener and implement the delegate method ThingSmartRoomBizDelegate to receive a callback when devices are organized by room.

API description

- (void)removeDeviceWithDeviceId:(NSString *)deviceId
                          roomId:(long long)roomId
                          homeId:(long long)homeId
                         success:(ThingSuccessHandler)success
                         failure:(ThingFailureError)failure;

Parameter description

Parameters Description
deviceId The ID of the target device.
roomId The room ID.
homeId The ID of the home to which the room belongs.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)removeDevice:(NSString *)devId roomId:(long long)roomId homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] removeDeviceWithDeviceId:devId roomId:roomId homeId:homeId success:^{

    } failure:^(NSError *error) {

    }];
}

Swift:

func removeDevice(devId:String, roomId:Int64, homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().removeDevice(withDeviceId: devId, roomId: roomId, homeId: homeId) {

    } failure: { error in

    }
}

Add a group to a room

Add a group to a room. Make a callback on success. Additionally, you can register a listener and implement the delegate method ThingSmartRoomBizDelegate to receive a callback when groups are organized by room.

API description

- (void)addGroupWithGroupId:(NSString *)groudId
                     roomId:(long long)roomId
                     homeId:(long long)homeId
                    success:(ThingSuccessHandler)success
                    failure:(ThingFailureError)failure;

Parameter description

Parameters Description
groudId The ID of the target group.
roomId The room ID.
homeId The ID of the home to which the room belongs.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)addGroup:(NSString *)groupId roomId:(long long)roomId homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] addGroupWithGroupId:groupId roomId:roomId homeId:homeId success:^{

    } failure:^(NSError *error) {

    }];
}

Swift:

func addGroup(groupId:String, roomId:Int64, homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().addGroup(withGroupId: groupId, roomId: roomId, homeId: homeId) {

    } failure: { error in

    }
}

Remove a group from a room

Remove a group from a room. Make a callback on success. This operation does not remove the group from the home. Additionally, you can register a listener and implement the delegate method ThingSmartRoomBizDelegate to receive a callback when groups are organized by room.

API description

- (void)removeGroupWithGroupId:(NSString *)groupId
                        roomId:(long long)roomId
                        homeId:(long long)homeId
                       success:(ThingSuccessHandler)success
                       failure:(ThingFailureError)failure;

Parameter description

Parameters Description
groudId The ID of the target group.
roomId The room ID.
homeId The ID of the home to which the room belongs.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)removeGroup:(NSString *)groupId roomId:(long long)roomId homeId:(long long)homeId {
    [[ThingSmartRoomBiz sharedInstance] removeGroupWithGroupId:groupId roomId:roomId homeId:homeId success:^{

    } failure:^(NSError *error) {

    }];
}

Swift:

func removeGroup(groupId:String, roomId:Int64, homeId:Int64) {
    ThingSmartRoomBiz.sharedInstance().removeGroup(withGroupId: groupId, roomId: roomId, homeId: homeId) {

    } failure: { error in

    }
}

Event callback

ThingSmartRoomBizDelegate is the delegate protocol for the room management class. You can implement it and register a listener to receive room event callbacks.

Register a listener

API description

- (void)addObserver:(id<ThingSmartRoomBizDelegate>)observer;

Parameter description

Parameters Description
observer The listener.

Example

Objective-C:

- (void)addObserver:(id<ThingSmartRoomBizDelegate>)observer {
    [[ThingSmartRoomBiz sharedInstance] addObserver:observer];
}

Swift:

func add(observer:ThingSmartRoomBizDelegate) {
    ThingSmartRoomBiz.sharedInstance().addObserver(observer)
}

Remove a listener

API description

- (void)removeObserver:(id<ThingSmartRoomBizDelegate>)observer;

Parameter description

Parameters Description
observer The listener.

Example

Objective-C:

- (void)removeObserver:(id<ThingSmartRoomBizDelegate>)observer {
    [[ThingSmartRoomBiz sharedInstance] removeObserver:observer];
}

Swift:

func remove(observer:ThingSmartRoomBizDelegate) {
    ThingSmartRoomBiz.sharedInstance().removeObserver(observer)
}

Room delegate

ThingSmartRoomBizDelegate is the delegate protocol for room management. If you implement this protocol, ThingSmartRoomBiz can notify you of room-based events through a callback.

API description

@protocol ThingSmartRoomBizDelegate <NSObject>

@optional

/**
* The delegate that is instantiated when a room is added.
*
* @param roomBiz        Instance of room management
* @param roomModel    The room model
* @param homeModel    The home model
*/
- (void)roomBiz:(ThingSmartRoomBiz *)roomBiz
     didAddRoom:(ThingSmartRoomModel *)roomModel
         atHome:(ThingSmartHomeModel *)homeModel;

/**
* The delegate that is instantiated when an existing room is removed.
*
* @param roomBiz         Instance of room management
* @param roomId           Room ID
* @param homeModel    The home model
*/
- (void)roomBiz:(ThingSmartRoomBiz *)roomBiz
  didRemoveRoom:(long long)roomId
         atHome:(ThingSmartHomeModel *)homeModel;

/**
* The delegate of room update information, such as the name.
*
* @param roomBiz        Instance of room management
* @param roomModel    The room model
* @param homeModel    The home model
*/
- (void)roomBiz:(ThingSmartRoomBiz *)roomBiz
  didUpdateRoom:(ThingSmartRoomModel *)roomModel
         atHome:(ThingSmartHomeModel *)homeModel;

/**
* The delegate of updating the relationship between room and device or group
*
* @param roomBiz        Instance of room management
* @param roomModel    The room model
* @param homeModel    The home model.
*/
- (void)roomBiz:(ThingSmartRoomBiz *)roomBiz
didUpdateRoomRelation:(ThingSmartRoomModel *)roomModel
         atHome:(ThingSmartHomeModel *)homeModel;

/**
* The delegate of sorting rooms
*
* @param roomBiz         Instance of room management
* @param roomList       The room list
* @param homeModel     The home model.
*/
- (void)roomBiz:(ThingSmartRoomBiz *)roomBiz
didSortRoomList:(NSArray<ThingSmartRoomModel *>*)roomList
         atHome:(ThingSmartHomeModel *)homeModel;

@end

Parameter description

Parameters Description
roomBiz Room management class
roomModel The room model.
homeModel The home model.
roomId The room ID.
roomList The list of rooms.