Last Updated on : 2024-08-23 09:48:00download
This topic describes how to manage devices by room. The class ThingSmartRoomBiz is used for room management to implement operations on a room.
The ThingSmartRoomBiz component offers more features than the ThingSmartRoom. If you are still using ThingSmartRoom, please refer to this document.
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;
Parameters
| Parameter | 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 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;
Parameters
| Parameter | 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. 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;
Parameters
| Parameter | 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. 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;
Parameters
| Parameter | 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. 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;
Parameters
| Parameter | 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
}
}
Query the room relationship snapshot, including the devices, groups, and scenes in the room.
- (void)fetchRoomSnapshotWithHomeId:(long long)homeId
roomId:(long long)roomId
success:(void (^_Nullable)(ThingDiyHomeRoomSnapshot * roomSnapshot))success
failure:(ThingFailureError _Nullable)failure;
Parameters
| Parameter | Description |
|---|---|
| homeId | The ID of the home to which the room belongs. |
| roomId | The room ID. |
| success | The success callback, returning the room snapshot. |
| failure | The failure callback. |
Example
- (void)fetchRoomSnapshotWithHomeId:(long long)homeId roomId:(long long)roomId{
[[ThingSmartRoomBiz sharedInstance] fetchRoomSnapshotWithHomeId:homeId roomId:roomId success:^(ThingDiyHomeRoomSnapshot * _Nonnull roomSnapshot) {
//
} failure:^(NSError * _Nonnull error) {
//
}];
}
Room snapshot model -ThingDiyHomeRoomSnapshot
// Room rule snapshot
@interface ThingDiyHomeRoomSnapshotRule : NSObject
@property (nonatomic, strong) NSString * ruleId;
@property (nonatomic, strong) NSString * ruleName;
@property (nonatomic, strong) NSString * background;
@property (nonatomic, strong) NSString * icon;
@end
// Room device/groupo snapshot
@interface ThingDiyHomeRoomSnapshotDevice : NSObject
// deviceId or groupId
@property (nonatomic, strong) NSString * bizId;
//5:group ; 6:device
@property (nonatomic, assign) NSUInteger bizType;
@property (nonatomic, assign) NSUInteger displayOrder;
- (BOOL)isGroup;
@end
// Room snapshot
@interface ThingDiyHomeRoomSnapshot : NSObject
@property (nonatomic, strong) NSArray<ThingDiyHomeRoomSnapshotRule *> * ruleList;
@property (nonatomic, strong) NSArray<ThingDiyHomeRoomSnapshotDevice *> * deviceList;
@end
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback