房间设备管理

更新时间:2024-08-23 09:48:00下载pdf

本文介绍房间和设备相关的功能,对应 ThingSmartRoomBiz 类,调用接口来实现对单个房间的操作。

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

批量修改房间与设备、群组的关系

调用接口时,传入设备 ID 和群组 ID,可批量将已配网的设备和群组添加到房间中。调用接口时,传入空数组,可批量将房间下的设备和群组移除。
此外,还可以通过注册监听的方式,实现 ThingSmartRoomBizDelegate 代理方法,接收房间中设备群组关系变化回调。

接口说明

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

参数说明

参数 说明
deviceGroupList 设备或群组 ID 列表
roomId 房间 ID
homeId 房间所属的家庭 ID
success 成功回调
failure 失败回调

调用示例

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

    }
}

添加设备到房间

添加单个已配网设备到房间中,添加成功调用 success 回调。
此外,还可以通过注册监听的方式,实现 ThingSmartRoomBizDelegate 代理方法,接收房间中设备关系变化回调。

接口说明

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

参数说明

参数 说明
deviceId 将要添加到房间中的设备 ID
roomId 房间 ID
homeId 房间所属的家庭 ID
success 成功回调
failure 失败回调

调用示例

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

    }
}

从房间中移除设备

从房间中移除单个设备,移除成功调用 success 回调。请注意设备还在当前家庭下没有被移除。
此外,还可以通过注册监听的方式,实现 ThingSmartRoomBizDelegate 代理方法,接收房间中设备关系变化回调。

接口说明

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

参数说明

参数 说明
deviceId 将要从房间中移除的设备 ID
roomId 房间 ID
homeId 房间所属的家庭 ID
success 成功回调
failure 失败回调

调用示例

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

    }
}

添加群组到房间

添加群组到房间中,添加成功调用 success 回调。
此外还可以通过注册监听的方式,实现 ThingSmartRoomBizDelegate 代理方法,接收房间下群组关系变化回调。

接口说明

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

参数说明

参数 说明
groudId 将要添加到房间中的群组 ID
roomId 房间 ID
homeId 房间所属的家庭 ID
success 成功回调
failure 失败回调

调用示例

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

    }
}

从房间中移除群组

从房间中移除群组,移除成功调用 success 回调。请注意,群组还在当前家庭下没有被移除。
此外,还可以通过注册监听的方式,实现 ThingSmartRoomBizDelegate 代理方法,接收房间下群组关系变化回调。

接口说明

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

参数说明

参数 说明
groudId 将要从房间中移除的群组 ID
roomId 房间 ID
homeId 房间所属的家庭 ID
success 成功回调
failure 失败回调

调用示例

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

    }
}

查询房间快照

查询房间关系快照,快照包含房间下的设备、群组和场景等信息。

- (void)fetchRoomSnapshotWithHomeId:(long long)homeId
                             roomId:(long long)roomId
                            success:(void (^_Nullable)(ThingDiyHomeRoomSnapshot * roomSnapshot))success
                            failure:(ThingFailureError _Nullable)failure;

参数说明

参数 说明
homeId 房间所属的家庭 ID
roomId 房间 ID
success 成功回调,返回房间快照
failure 失败回调

调用示例

- (void)fetchRoomSnapshotWithHomeId:(long long)homeId roomId:(long long)roomId{
    [[ThingSmartRoomBiz sharedInstance] fetchRoomSnapshotWithHomeId:homeId roomId:roomId success:^(ThingDiyHomeRoomSnapshot * _Nonnull roomSnapshot) {
        //
    } failure:^(NSError * _Nonnull error) {
        //
    }];
}

房间快照模型-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