Room Tag Management

Last Updated on : 2024-08-23 09:48:00download

Assign tags to rooms. For example, associate the First Floor tag with the living room and kitchen, and the Second Floor tag with the master bedroom and guest bedroom. Theoretically, a room can be associated with multiple tags. The room tag is optional. If a room has no tags, it will be categorized as an ungrouped room.

The class ThingSmartRoomBiz is used for managing room tags, with the following methods available.

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

Get the list of room tags

API description

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

Parameters

Parameter Description
homeId The home ID.
success The success callback, returning a list of tag models.
failure The failure callback.

Example

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

Tag model -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

Create a room tag

The room tag must be unique.

API description

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

Parameters

Parameter Description
name The tag name.
homeId The home ID.
success The success callback.
failure The failure callback.

Example

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

Delete a room tag

Deleting a room tag only removes the tag and does not delete the associated rooms. Make a callback on success.

API description

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

Parameters

Parameter Description
roomTagId The tag ID.
success The success callback.
failure The failure callback.

Example

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

Modify a room tag

Update a room tag. Make a callback on success.

API description

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

Parameters

Parameter Description
roomTagId The tag ID.
name The tag name.
success The success callback.
failure The failure callback.

Example

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

Sort a room tag

API description

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

Parameters

Parameter Description
roomTagIds The list of tag IDs after sorting.
homeId The home ID.
success The success callback.
failure The failure callback.

Example

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

Get the associated tag for rooms

This method returns the tag details for all rooms in the home. A room can have zero or multiple tags. Make a callback on success.

API description

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

Parameters

Parameter Description
homeId The home ID.
success The success callback, returning the room tag details model ThingSmartRoomListDataModel.
failure The failure callback.

Example

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

Tag details model -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

Change the associated tag for rooms

Bulk change the associated tag for rooms. Note that a tag may not have a room assigned. Make a callback on success.

API description

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

Parameters

Parameter Description
roomRelationship The list of tags that have a room assigned in the current home. Example: { "roomTagId_1":["roomId_1","roomId_2"] }
roomTagIds All the tags in the current home. Example: ["roomTagId_1", "roomTagId_2", "roomTagId_3"]
homeId The home ID.
success The success callback.
failure The failure callback.

Create a room with tag

API description

Create a tagged room in the current home.

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

Parameters

Parameter Description
name The name of the room.
roomTagId The tag ID.
success The success callback.
failure The failure callback.