English
English
简体中文
Contact Us
Register
Log In

Room Information Management

Last Updated on : 2021-11-19 12:12:05download

Functional description

TuyaSmartHome must be initialized with the correct value of roomId to implement information management for a single room in a home. An incorrect room ID might cause failed initialization. In this case, nil will be returned.

Class name (protocol name) Description
TuyaSmartRoom Manage information about rooms and devices in the rooms.

Add a room

API description

- (void)addHomeRoomWithName:(NSString *)name
                    success:(TYSuccessHandler)success
                    failure:(TYFailureError)failure;

Parameters

Parameter Description
name The name of a room.
success The success callback.
failure The failure callback.

Example

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)")
        }
    })
}

Remove a room

API description

- (void)removeHomeRoomWithRoomId:(long long)roomId
                         success:(TYSuccessHandler)success
                         failure:(TYFailureError)failure;

Parameters

Parameter Description
roomId The room ID.
success The success callback.
failure The failure callback.

Example

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)")
        }
    })
}

Sort a list of rooms

API description

- (void)sortRoomList:(NSArray <TuyaSmartRoomModel *> *)roomList
             success:(TYSuccessHandler)success
             failure:(TYFailureError)failure;

Parameters

Parameter Description
roomList The list of rooms.
success The success callback.
failure The failure callback.

Example

ObjC:

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

Swift:

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

Add a group to a room

API description

- (void)addGroupWithGroupId:(NSString *)groupId success:(TYSuccessHandler)success failure:(TYFailureError)failure;

Parameters

Parameter Description
groupId The group ID.
success The success callback.
failure The failure callback.

Example

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)")
        }
    })
}

Remove a group from a room

API description

- (void)removeGroupWithGroupId:(NSString *)groupId success:(TYSuccessHandler)success failure:(TYFailureError)failure;

Parameters

Parameter Description
groupId The group ID.
success The success callback.
failure The failure callback.

Example

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)")
        }
    })
}

Add a device to a room

API description

- (void)addDeviceWithDeviceId:(NSString *)deviceId success:(TYSuccessHandler)success failure:(TYFailureError)failure;

Parameters

Parameter Description
deviceId The device ID.
success The success callback.
failure The failure callback.

Example

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)")
        }
    })
}

Remove a device from a room

API description

- (void)removeDeviceWithDeviceId:(NSString *)deviceId success:(TYSuccessHandler)success failure:(TYFailureError)failure;

Parameters

Parameter Description
deviceId The device ID.
success The success callback.
failure The failure callback.

Example

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)")
        }
    })
}

Update a room name

API description

- (void)updateRoomName:(NSString *)roomName success:(TYSuccessHandler)success failure:(TYFailureError)failure;

Parameters

Parameter Description
roomName The name of a room.
success The success callback.
failure The failure callback.

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)")
        }
    })
}

Customize a room image

Customizes an image for a room. You call TuyaSmartRoomModel.iconUrl to get the URL of the image.

API description

- (void)updateIcon:(UIImage *)icon success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
icon The image of the room.
success The success callback.
failure The failure callback.

Example

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)")
        }
    })
}

Modify mappings between rooms and devices or groups in bulk

API description

- (void)saveBatchRoomRelationWithDeviceGroupList:(NSArray <NSString *> *)deviceGroupList
                                         success:(TYSuccessHandler)success
                                         failure:(TYFailureError)failure;

Parameters

Parameter Description
deviceGroupList The list of device IDs or group IDs.
success The success callback.
failure The failure callback.

Example

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)")
        }
    })
}