房间信息管理

更新时间:2024-03-04 07:24:32

功能说明

家庭里单个房间信息管理相关的所有功能对应 ThingSmartRoom 类。您需要使用正确的 roomId 进行初始化。错误的 roomId 会导致初始化失败,返回 nil

类名(协议名) 说明
ThingSmartRoom 房间信息及房间内设备管理

新增房间

接口说明

- (void)addHomeRoomWithName:(NSString *)name
                    success:(ThingSuccessHandler)success
                    failure:(ThingFailureError)failure;

参数说明

参数 说明
name 房间名称
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)addHomeRoom {
    [self.home addHomeRoomWithName:@"room_name" success:^{
        NSLog(@"add room success");
    } failure:^(NSError *error) {
        NSLog(@"add room failure: %@", error);
    }];
}

Swift:

func addHomeRoom() {
    home?.addRoom(withName: "room_name", success: {
        print("add room success")
    }, failure: { (error) in
        if let e = error {
            print("add room failure: \(e)")
        }
    })
}

删除房间

接口说明

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

参数说明

参数 说明
roomId 房间 ID
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)removeHomeRoom {
    [self.home removeHomeRoomWithRoomId:roomId success:^{
        NSLog(@"remove room success");
    } failure:^(NSError *error) {
        NSLog(@"remove room failure: %@", error);
    }];
}

Swift:

func removeHomeRoom() {
    home?.removeRoom(withRoomId: roomId, success: {
        print("remove room success")
    }, failure: { (error) in
        if let e = error {
            print("remove room failure: \(e)")
        }
    })
}

房间排序

接口说明

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

参数说明

参数 说明
roomList 房间模型列表
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)sortHomeRoom {
    [self.home sortRoomList:(NSArray<ThingSmartRoomModel *> *) success:^{
        NSLog(@"sort room success");
    } failure:^(NSError *error) {
        NSLog(@"sort room failure: %@", error);
    }];
}

Swift:

func sortHomeRoom() {
    home?.sortRoomList([ThingSmartRoomModel]!, success: {
        print("sort room success")
    }, failure: { (error) in
        if let e = error {
            print("sort room failure: \(e)")
        }
    })
}

添加群组到房间

接口说明

- (void)addGroupWithGroupId:(NSString *)groupId success:(ThingSuccessHandler)success failure:(ThingFailureError)failure;

参数说明

参数 说明
groupId 群组 ID
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)addGroup {
    [self.room addGroupWithGroupId:@"groupId" success:^{
        NSLog(@"add group to room success");
    } failure:^(NSError *error) {
        NSLog(@"add group to room failure: %@", error);
    }];
}

Swift:

func addGroup() {
    room?.addGroup(withGroupId: "your_groupId", success: {
        print("add group to room success")
    }, failure: { (error) in
        if let e = error {
            print("add group to room failure: \(e)")
        }
    })
}

从房间中移除群组

接口说明

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

参数说明

参数 说明
groupId 群组 ID
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)removeGroup {
    [self.room removeGroupWithGroupId:@"groupId" success:^{
        NSLog(@"remove group from room success");
    } failure:^(NSError *error) {
        NSLog(@"remove group from room failure: %@", error);
    }];
}

Swift:

func removeGroup() {
    room?.removeGroup(withDeviceId: "your_devId", success: {
        print("remove device from room success")
    }, failure: { (error) in
        if let e = error {
            print("remove device from room failure: \(e)")
        }
    })
}

添加设备到房间

接口说明

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

参数说明

参数 说明
deviceId 设备 ID
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)addDevice {
    [self.room addDeviceWithDeviceId:@"devId" success:^{
        NSLog(@"add device to room success");
    } failure:^(NSError *error) {
        NSLog(@"add device to room failure: %@", error);
    }];
}

Swift:

func addDevice() {
    room?.addDevice(withDeviceId: "your_devId", success: {
        print("add device to room success")
    }, failure: { (error) in
        if let e = error {
            print("add device to room failure: \(e)")
        }
    })
}

从房间中移除设备

接口说明

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

参数说明

参数 说明
deviceId 设备 ID
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)removeDevice {
    [self.room removeDeviceWithDeviceId:@"devId" success:^{
        NSLog(@"remove device from room success");
    } failure:^(NSError *error) {
        NSLog(@"remove device from room failure: %@", error);
    }];
}

Swift:

func removeDevice() {
    room?.removeDevice(withDeviceId: "your_devId", success: {
        print("remove device from room success")
    }, failure: { (error) in
        if let e = error {
            print("remove device from room failure: \(e)")
        }
    })
}

更新房间名称

接口说明

- (void)updateRoomName:(NSString *)roomName success:(ThingSuccessHandler)success failure:(ThingFailureError)failure;

参数说明

参数 说明
roomName 房间名称
success 成功回调
failure 失败回调

Objc:

- (void)updateRoomName {
    [self.room updateRoomName:@"new_room_name" success:^{
        NSLog(@"update room name success");
    } failure:^(NSError *error) {
        NSLog(@"update room name failure: %@", error);
    }];
}

Swift:

func updateRoomName() {
    room?.updateName("new_room_name", success: {
        print("update room name success")
    }, failure: { (error) in
        if let e = error {
            print("update room name failure: \(e)")
        }
    })
}

自定义房间图片

房间可支持自定义图片(image),然后可通过 ThingSmartRoomModel.iconUrl 查询图片地址。

接口说明

- (void)updateIcon:(UIImage *)icon success:(nullable ThingSuccessHandler)success failure:(nullable ThingFailureError)failure;

参数说明

参数 说明
icon 房间图片
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)updateIcon {
    [self.room updateIcon:[UIImage imageNamed:@"xxx.JPG"] success:^{
      NSLog(@"room image update success %@", room.roomModel.iconUrl);
    } failure:^(NSError *error) {
      NSLog(@"room image update failure: %@", error);
    }];
}

Swift:

func updateIcon() {

    room?.updateIcon(UIImage(named: "xxx.jpg") success: {
        print("room image update success")
    }, failure: { (error) in
        if let e = error {
            print("room image update failure: \(e)")
        }
    })
}

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

接口说明

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

参数说明

参数 说明
deviceGroupList 设备 ID 或群组 ID 列表
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)saveBatchRoomRelation {
    [self.room saveBatchRoomRelationWithDeviceGroupList:(NSArray <NSString *> *)deviceGroupList success:^{
        NSLog(@"save batch room relation success");
    } failure:^(NSError *error) {
        NSLog(@"save batch room relation failure: %@", error);
    }];
}

Swift:

func saveBatchRoomRelation() {
    room?.saveBatchRoomRelation(withDeviceGroupList: [String]!, success: {
        print("save batch room relation success")
    }, failure: { (error) in
        if let e = error {
            print("save batch room relation failure: \(e)")
        }
    })
}