Last Updated on : 2024-08-28 01:53:48download
This topic describes how to implement the features of room management using APIs. These APIs allow you to create, modify, and remove a room, manage devices or groups in a room, and register listeners for receiving room-based event callbacks. FamilyManagerCoreKit.getRoomUseCase()
is used for room management to implement operations on a room.
Add a room in a specific home. You need to pass in the room name and home ID. Make a callback
on success to return the room model.
API description
void addRoom(long homeId, String name,
IFamilyDataCallback<BizResponseData<TRoomBean>> callback);
Parameter description
Parameters | Description |
---|---|
name | The name of the room to add. |
homeId | The ID of the home with which the room is bound. |
callback | The callback. |
Example
FamilyManagerCoreKit.getRoomUseCase().addRoom(0,"room1",object :IFamilyDataCallback<BizResponseData<TRoomBean>>{
override fun onSuccess(result: BizResponseData<TRoomBean>?) {
val data = result?.data
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
})
Remove a room from a specific home. You need to pass in the room ID and home ID. Make a callback
on success.
API description
void removeRoom(long homeId, long roomId,
IFamilyDataCallback<Boolean> callback);
Parameter description
Parameters | Description |
---|---|
roomId | The ID of the room to remove. |
homeId | The ID of the home to which the room belongs. |
callback | The callback. |
Example
FamilyManagerCoreKit.getRoomUseCase().removeRoom(homeId, roomId, object:IFamilyDataCallback<Boolean>{
override fun onSuccess(result: Boolean?) {
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
});
Change the name of a room. The new name cannot be empty. Make a callback
on success to return the room model.
API description
void updateRoom(long roomId, String roomName,IFamilyDataCallback<Boolean> callback);
Parameter description
Parameters | Description |
---|---|
roomName | The new name of the room. |
roomId | The ID of the target room. |
callback | The success callback. |
Example
FamilyManagerCoreKit.getRoomUseCase().updateRoom(homeId, "xxx", object :IFamilyDataCallback<Boolean>{
override fun onSuccess(result: Boolean?) {
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
});
Query the list of rooms in a home. You need to pass in the home ID. Make a callback
on success to return the array of the room model.
API description
void getRoomList(long homeId, boolean ignoreCache,IFamilyDataCallback<BizResponseData<List<TRoomBean>>> callback);
Parameter description
Parameters | Description |
---|---|
homeId | The home ID. |
ignoreCache | Specifies whether to use the cache.
|
success | The success callback. |
Example
val ignoreCache = false//
FamilyManagerCoreKit.getRoomUseCase().getRoomList(homeId, ignoreCache, object :IFamilyDataCallback<BizResponseData<List<TRoomBean>>>{
override fun onSuccess(result: BizResponseData<List<TRoomBean>>?) {
val datalist = result?.data
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
});
When the user adds a room, query the recommended room names. Make a callback
to return the list of recommended names.
API description
void getRecommendRoomList(int listType,IFamilyDataCallback<BizResponseData<List<RoomCheckBean>>> callback);
Parameter description
Parameters | Description |
---|---|
listType | The type:
|
callback | The failure callback. |
Example
FamilyManagerCoreKit.getRoomUseCase().getRecommendRoomList(ROOM_LIST_DEFAULT,object :IFamilyDataCallback<BizResponseData<List<RoomCheckBean>>>{
override fun onSuccess(result: BizResponseData<List<RoomCheckBean>>?) {
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
})
Sort the list of rooms in a home, including moving a device or group to another room (adding and deleting a device or group). Pass in the room ID after sorting and make a callback
on success.
API description
void sortRoom(long homeId, List<Long> sortedIds,IFamilyDataCallback<Boolean> callback);
Parameter description
Parameters | Description |
---|---|
homeId | The ID of the home to which the room belongs. |
sortedIds | The list of room IDs to sort. |
callback | The callback. |
Example
FamilyManagerCoreKit.getRoomUseCase().sortRoom(0, roomIds , object :IFamilyDataCallback<Boolean>{
override fun onSuccess(result: Boolean?) {
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
})
Register IThingHomeRoomInfoChangeListener
to get notified when the user adds or removes a room, and organizes devices or groups by room.
IThingHomeRoomInfoChangeExListener
is an extension of IThingHomeRoomInfoChangeListener
. It enables you to get notified when the user renames a room, sorts rooms, and adds or removes devices or groups in a specific room ID.
API description
public interface IThingHomeRoomInfoChangeListener {
/**
* the Room of Device Information Update.
* <p>Such as name, etc.</p>
*
* @param devId The id of the device which you are listening to.
*/
void onDeviceRoomInfoUpdate(String devId);
/**
* the Room of Group Information Update.
* <p>Such as name, etc.</p>
*
* @param groupId The id of the Group which you are listening to.
*/
void onGroupRoomInfoUpdate(Long groupId);
/**
* the Room of Information Update.
* <p>Such as name, etc.</p>
*
* @param roomId The id of the Room which you are listening to.
*/
void onRoomAdd(String homeId, Long roomId);
/**
* the Room of Information Update.
* <p>Such as name, etc.</p>
*
* @param roomId The id of the Room which you are listening to.
*/
void onRoomDelete(String homeId, Long roomId);
}
public interface IThingHomeRoomInfoChangeExListener extends IThingHomeRoomInfoChangeListener {
/**
* device been added or removed from room
*
* @param roomId room id
* @param devId device id
* @param add add or not
*/
void onDeviceRoomInfoChanged(long roomId, String devId, boolean add);
/**
* group been added or removed from room
*
* @param roomId room id
* @param id group id
* @param add add or not
*/
void onGroupRoomInfoChanged(long roomId, long id, boolean add);
/**
* room name changed
*
* @param roomId room id
* @param name new room name
*/
void onRoomNameChanged(long roomId, String name);
/**
* room order changed
*/
void onRoomOrderChanged();
}
Example
val listener = object :IThingHomeRoomInfoChangeExListener{
override fun onDeviceRoomInfoUpdate(devId: String?) {
}
override fun onGroupRoomInfoUpdate(groupId: Long?) {
}
override fun onRoomAdd(homeId: String?, roomId: Long?) {
}
override fun onRoomDelete(homeId: String?, roomId: Long?) {
}
override fun onDeviceRoomInfoChanged(roomId: Long, devId: String?, add: Boolean) {
}
override fun onGroupRoomInfoChanged(roomId: Long, id: Long, add: Boolean) {
}
override fun onRoomNameChanged(roomId: Long, name: String?) {
}
override fun onRoomOrderChanged() {
}
}
//register HomeDeviceRoomlistener
FamilyManagerCoreKit.registerHomeDeviceRoomListener(homeId,listener)
//unregister HomeDeviceRoomlistener
FamilyManagerCoreKit.unregisterHomeDeviceRoomListener(homeId,listener)
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback