Room Management

Last Updated on : 2022-02-17 06:55:39download

The room management SDK provides a bunch of capabilities. For example, add rooms to a house, sort rooms, add devices to rooms, remove devices from rooms, add groups to rooms, remove groups from rooms, and delete rooms. Users can also control devices or groups by room.

Feature overview

ITuyaCommunityRoom is used to describe all information about a room. One or more rooms can be created in each house. You can call its API methods to get room details, query a list of devices or groups from a room, and sort the devices and groups displayed in a room.

You can call TuyaCommunitySDK.newRoomInstance() to get information about a room.

Add a room

API description

void addHouseRoom(String name, ITuyaCommunityResultCallback<TuyaCommunityRoomBean> callback);

Request parameter

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

Data types of TuyaCommunityRoomBean

Property Type Description
roomId String The room ID.
name String The name of the room.
displayOrder Integer The sorting order.
deviceList List A list of devices.
groupList List A list of groups.

Example

TuyaCommunitySDK.newHouseInstance(houseId).addHouseRoom("Room name", new ITuyaCommunityResultCallback<TuyaCommunityRoomBean>() {
		@Override
		public void onSuccess(TuyaCommunityRoomBean bean) {
			// do something
		}
		@Override
		public void onFailure(String errorCode, String errorMsg) {
			// do something
		}
	});

Delete a room

API description

    void removeHouseRoom(long roomId, ISuccessFailureCallback callback);

Request parameter

Parameter Description
roomId The room ID.
callback The callback.

Example

TuyaCommunitySDK.newHouseInstance(houseId).removeHouseRoom(roomId, new ISuccessFailureCallback() {
		@Override
		public void onSuccess() {
			// do something
		}
		@Override
		public void onFailure(String code, String error) {
			// do something
		}
	});

Sort a list of rooms

API description

void sortHouseRoom(List<Long> idList, ISuccessFailureCallback callback)

Request parameter

Parameter Description
idList The list of room IDs.
callback The callback.

Example

TuyaCommunitySDK.newHouseInstance(houseId).sortHouseRoom(idList, new ISuccessFailureCallback() {
		@Override
		public void onSuccess() {
			// do something
		}
		@Override
		public void onFailure(String code, String error) {
			// do something
		}
	});

Query room information by device ID

API description

Returns room information by device ID.

TuyaCommunityRoomBean getDeviceRoomBean(String devId)

Request parameter

Parameter Description
devId The device ID.

Example

TuyaCommunitySDK.getHouseDataInstance().getDeviceRoomBean("Device ID");

Update a room name

API description

void updateRoomName(String name, ISuccessFailureCallback callback)

Request parameter

Parameter Description
name The new room name.

Example

TuyaCommunitySDK.newRoomInstance(roomId).updateRoomName(name, new ISuccessFailureCallback() {
		@Override
		public void onSuccess() {
			// do something
		}
		@Override
		public void onFailure(String code, String error) {
			// do something
		}
	});

Add a device to a room

API description

void addDevice(String devId, ISuccessFailureCallback callback)

Request parameter

Parameter Description
devId The device ID.

Example

TuyaCommunitySDK.newRoomInstance(roomId).addDevice(devId, new ISuccessFailureCallback() {
		@Override
		public void onSuccess() {
			// do something
		}
		@Override
		public void onFailure(String code, String error) {
			// do something
		}
	});

Remove a device from a room

API description

void removeDevice(String devId, ISuccessFailureCallback callback)

Request parameter

Parameter Description
devId The device ID.

Example

TuyaCommunitySDK.newRoomInstance(roomId).removeDevice(devId, new ISuccessFailureCallback() {
		@Override
		public void onSuccess() {
			// do something
		}
		@Override
		public void onFailure(String code, String error) {
			// do something
		}
	});

Add a group to a room

API description

void addGroup(long groupId, ISuccessFailureCallback callback)

Request parameter

Parameter Description
groupId The group ID.

Example

TuyaCommunitySDK.newRoomInstance(roomId).addGroup(groupId, new ISuccessFailureCallback() {
		@Override
		public void onSuccess() {
			// do something
		}
		@Override
		public void onFailure(String code, String error) {
			// do something
		}
	});

Remove a group from a room

API description

void removeGroup(Long groupId, ISuccessFailureCallback resultCallback)

Request parameter

Parameter Description
groupId The group ID.

Example

TuyaCommunitySDK.newRoomInstance(roomId).removeGroup(groupId, new ISuccessFailureCallback() {
		@Override
		public void onSuccess() {
			// do something
		}
		@Override
		public void onFailure(String code, String error) {
			// do something
		}
	});

Modify mappings between rooms and device groups in bulk

API description

Transfers device groups in to or out of a room in bulk.

This API method can be called to sort devices in a room. Perform the following steps:

  1. Call this API method and pass in the target device set object CommunityDeviceAndGroupInRoomBean.
  2. Call the API method getHouseDetail() in House Management to get TuyaCommunityHouseBean that includes the list of all devices.
  3. Search the device list by device ID to get the list of devices that are returned by batchModifyRoomRelation.
  4. Sort the devices locally by the displayOrder field in DeviceBean.
void batchModifyRoomRelation(List<CommunityDeviceAndGroupInRoomBean> list, ISuccessFailureCallback callback)

Request parameter

Parameter Description
list The group or device.

Data format of CommunityDeviceAndGroupInRoomBean

Parameter Parameter type Description
id String The ID of the device or group.
type int The type. Valid values:
6: device
5: group

Example

TuyaCommunitySDK.newRoomInstance(roomId).batchModifyRoomRelation(list, new ISuccessFailureCallback() {
		@Override
		public void onSuccess() {
			// do something
		}
		@Override
		public void onFailure(String code, String error) {
			// do something
		}
	});