Group Management

Last Updated on : 2022-02-17 05:46:20download

Overview

  • A group is an aggregation of one or more devices according to certain rules, through the control of the group to achieve the purpose of group control of the devices under the group.
  • packed group is an aggregation of one or more different types of small groups, through the control of the packed group to achieve the purpose of group control of the small groups within the packed group, and then control all the devices in the small groups.
  • The Business Photo SDK provides the ability to create, edit, and control packed groups, etc. There is no support for the operation of individual small groups.
  • packed groups are attached to the regional dimension, and cannot be created when there is no region.

The relationship between Packed-groups—groups—devices is shown in the figure before.

Group Management

Get the list of devices that can create packed groups

Interface description

// Create a packed  group instance
ILightingGroupPack groupPackInstance = TuyaCommercialLightingGroupPack.newGroupPackInstance(long projectId,String groupPackId);

// Get the list of devices that can join the group
groupPackInstance.getAvailableDevices2JoinGroupPack(long areaId, @GroupPackType String topCategory, int limit, 
                                    String offsetKey,ITuyaResultCallback<GroupDeviceListRespBean> callback)

Parameter description

Parameter Description
projectId current project ID
groupPackId The groupPackId, if there is no groupPackId at creation time, you can pass the empty string
areaId The current area ID, the group is attached to the area dimension, if there is no area, the group cannot be created.
topCategory The first level category code, the current version only supports creating lighting category group, pass GroupPackCategory.CATEGORY_LIGHTING
limit The number of devices requested per page.
offsetKey The number of pages of the current request, the first page is 1, and the subsequent pages are incremented
callback Callback for device list results

Create a packed group

interface description

TuyaCommercialLightingGroupPack.getGroupPackManager()
  .createPackedGroup(long projectId,long areaId,String packedGroupName,List<ComplexDeviceBean> addDevices,
                                        @GroupPackCategory int topCategory,String deviceId,DefaultDeviceTransferListener listener)

Parameter Description

Parameter Description
projectId current project ID
areaId The current area ID, the packed group is attached to the area dimension, no packed group can be created if there is no area.
packedGroupName The name of the packed group.
addDevices The list of devices to be added to the packed group, which is the data returned by the Get list of devices that can be added to the packed group interface.
topCategory The first level category code, the current version only supports creating lighting category group, pass GroupPackCategory.CATEGORY_LIGHTING
deviceId The main device ID, you can pass the empty string
listener The callback for creating a packed of groups, the specific meaning of the various callback methods can be found in the Area Management section of the DefaultDeviceTransferListener introduction.

Edit/Update Packed-Group Device List

Interface Description

// Create a packed  group instance object
ILightingGroupPack groupPackInstance = TuyaCommercialLightingGroupPack.newGroupPackInstance(long projectId,String groupPackId);

// Update the list of devices in the group
groupPackInstance.updateDevicesByIds(List<String> bindDevIds, List<String> unbindDevIds, final ITuyaResultCallback< DeviceTaskResultBean> callback);

Parameter Description

parameter description
projectId projectId
groupPackId groupPackId
bindDevIds The set of device IDs newly added to the current group.
unbindDevIds The set of device IDs removed from the current group.
callback result callback, where DeviceTaskResultBean#success is the set of device IDs for successful operation, failed is the set of device IDs for failed operation

Get the packed group information

Interface Description

// Create a packed  group instance object
ILightingGroupPack groupPackInstance = TuyaCommercialLightingGroupPack.newGroupPackInstance(long projectId,String groupPackId);

//Get information
groupPackInstance.getPackedGroupInfo(ITuyaResultCallback<GroupPackBean> resultListener);

Parameter description

parameter description
projectId projectId
groupPackId groupPackId
resultListener resultCallback

Group renaming

Interface Description

// Create a groupPack instance object
ILightingGroupPack groupPackInstance = TuyaCommercialLightingGroupPack.newGroupPackInstance(long projectId,String groupPackId);

groupPackInstance.renamePackedGroup(String name,IResultCallback callback);

Parameter Description

Parameter Description
projectId projectId
groupPackId groupPackId
name The new name of the current groupPack
callback result callback

Get the list of devices in a group

Interface Description

// Create a groupPack instance object
ILightingGroupPack groupPackInstance = TuyaCommercialLightingGroupPack.newGroupPackInstance(long projectId,String groupPackId);

groupPackInstance.getDevicesInGroupPack(int limit,String offsetKey,ITuyaResultCallback<GroupDeviceListRespBean> callback);

Parameter Description

parameter description
projectId projectId
groupPackId packed groupId
limit The number of device lists requested per page
offsetKey The number of pages requested, with the first page being 1 and subsequent pages incrementing
callback The result callback

Decompose the packed group

Interface description

When disbanding a group, it is recommended that all devices in the group be removed first. There is a limit to the number of groups a Bluetooth Mesh device can join, and if the number of groups is exceeded, it will be impossible to join the group again.

// Create a packed  group instance object
ILightingGroupPack groupPackInstance = TuyaCommercialLightingGroupPack.newGroupPackInstance(long projectId,String groupPackId);

groupPackInstance.dismiss(IResultCallback callback);

Parameter Description

Parameter Description
projectId projectId
groupPackId groupPackId
callback result callback

Get the list of subgroups in a group.

Interface description

Do not call this interface unless necessary, in principle the small groups in a group are not user-aware.

// Create a packed  group instance object
ILightingGroupPack groupPackInstance = TuyaCommercialLightingGroupPack.newGroupPackInstance(long projectId,String groupPackId);

groupPackInstance.getChildrenGroupBeans(ITuyaResultCallback<List<GroupBean>> callback);

Parameter description

parameter description
projectId projectId
groupPackId groupPackId
callback result callback

Get the list of groups

Interface Description

ILightingGroupPackManager groupPackManager = TuyaCommercialLightingGroupPack.getGroupPackManager();
groupPackManager.getPackedGroupList(long areaId, int limit, String offsetKey, ITuyaResultCallback<GroupPackListBean> callback);

Parameter description

parameter description
areaId current area ID
limit The number of packed group lists requested per page
offsetKey The number of pages requested, the first page is 1, and the number of subsequent pages is incremented
callback The result callback

Register for packed group change listening

Interface description

ILightingGroupPackManager groupPackManager = TuyaCommercialLightingGroupPack.getGroupPackManager();
groupPackManager.registerGroupPackListener(ILightingGroupPackListener listener);

Parameter Description

parameter description
listener result callback

Remove packed group change listener

Interface description

ILightingGroupPackManager groupPackManager = TuyaCommercialLightingGroupPack.getGroupPackManager();
groupPackManager.unRegisterGroupPackListener(ILightingGroupPackListener listener);

Parameter Description

Parameter Description
listener result callback

Sample code

TuyaCommercialLightingGroupPack.getGroupPackManager().unRegisterGroupPackListener(listener);

packed group control

packed group control is a function of the total control of the devices under the packed group, the currently supported regional total control functions are switch, brightness, mode, color temperature, etc. this part of the function must be executed after requesting the packed group list

Get the regional group control management class

Interface description

ILightingGroupPackDpsManager groupPackDpsManager = TuyaCommercialLightingGroupPack.newGroupPackDpsManager(long projectId, GroupPackBean groupPackBean)

Parameter description

Parameter Description
projectId projectID
groupPackBean packed group object

Sample code

ILightingGroupPackDpsManager groupPackDpsManager = TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(projectId,groupPackBean)

Get the relevant DP point data for the region

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getDps()

Parameter description

parameter description
projectId projectID
groupPackBean packed group object

Sample code

String groupDps = TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getDps()

Get area switch status

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getSwitchStatus()

Parameter Description

parameter description
projectId projectID
groupPackBean packed group object

Sample code

boolean switchOn = TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getSwitchStatus()

Get the brightness percentage

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getBrightPercent()

Parameter Description

parameter description
projectId projectID
groupPackBean packed group object

Sample code

int brightnessPercent = TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getBrightPercent()

Get color temperature percentage

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getTemperaturePercent()

Parameter Description

parameter description
projectId projectID
groupPackBean packed group object

Sample code

int temperaturePercent = TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getTemperaturePercent()

Get color light mode color value

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getColorData();

Parameter Description

Parameter Description
projectId projectID
groupPackBean packed group object

Sample code

String colorData = TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getColorData();

Get scene mode

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getSceneStatus();

Parameter Description

parameter description
projectId projectID
groupPackBean packed group object

Sample code

LightDefaultSceneType sceneType = TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getSceneStatus();

Get the current lighting mode

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .getCurrentMode();

Parameter Description

Parameter Description
projectId projectID
groupPackBean packed group object

Sample code

AreaDpMode groupDpMode = TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(projectId,groupPackBean)
        .getCurrentMode();

Toggle switch state

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .publishSwitchStatus(boolean status, final IResultCallback callback);

Parameter Description

parameter description
status switch status, true: on false: off
callback Callback of the result of the execution

Example code

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .publishSwitchStatus(true, new IResultCallback() {
            @Override
            public void onError(String errorCode, String errorMsg) {
                if (callback ! = null) {
                    callback.onError(errorCode, errorMsg);
                }
            }

            @Override
            public void onSuccess() {
                if (callback ! = null) {
                    callback.onSuccess();
                }
            }
        });

Switching light modes

Three lighting modes are currently supported, namely WHITE mode, COLORFUL mode and SCENE mode, corresponding to MODE_WHITE_LIGHT, MDOE_COLORFUL_LIGHT and MODE_SCENE in the AreaDpMode enumeration respectively.

Interface Description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .publishWorkMode(AreaDpMode mode, IResultCallback callback);

Parameter Description

Parameter Description
Mode The enumeration value of the mode to be switched, including MODE_WHITE_LIGHT, MDOE_COLORFUL_LIGHT and MODE_SCENE
callback execution result callback

Sample code

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(projectId,groupPackBean)
        .publishWorkMode(AreaDpMode.MODE_WHITE_LIGHT, new IResultCallback() {
            @Override
            public void onError(String errorCode, String errorMsg) {
                if (callback ! = null) {
                    callback.onError(errorCode, errorMsg);
                }
            }

            @Override
            public void onSuccess() {
                if (callback ! = null) {
                    callback.onSuccess();
                }
            }
        });

Adjusting color temperature value

This operation is only supported in white light mode.

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .publishTemperaturePercent(int value, IResultCallback callback);

Parameter Description

Parameter Description
value The value of the color temperature, in the range 0-1000
callback The result callback

Sample code

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(projectId,groupPackBean)
        .publishTemperaturePercent(int value, new IResultCallback() {
            @Override
            public void onError(String errorCode, String errorMsg) {
                if (callback ! = null) {
                    callback.onError(errorCode, errorMsg);
                }
            }

            @Override
            public void onSuccess() {
                if (callback ! = null) {
                    callback.onSuccess();
                }
            }
        });

Set scenario

This operation is only supported in scene mode.

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .publishSceneStatus(LightDefaultSceneType type, IResultCallback callback);

Parameter Description

Parameter Description
type Scene type, including NONE, WORK, MEETING, SIESTA, OFF_DUTY, sub-table indicates no mode, meeting mode light, work mode light, lunch break mode light and off duty mode light.
callback callback for execution result

Sample code

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(projectId,groupPackBean)
        .publishSceneStatus(LightDefaultSceneType.WORK, new IResultCallback() {
            @Override
            public void onError(String errorCode, String errorMsg) {
                if (callback ! = null) {
                    callback.onError(errorCode, errorMsg);
                }
            }

            @Override
            public void onSuccess() {
                if (callback ! = null) {
                    callback.onSuccess();
                }
            }
        });

Set color light

This operation is only supported in color light mode.

Get the color light mode data by getColorData, the data is 12-bit combination data, the combination rule is hhhhssssvvvv, where hhhh means the hue value after hex, sssss means the saturation value after hex, vvvvv means the brightness value after hex, you can use stringToHSV method to convert colorData to hsv value, the code is as follows.

public static float[] stringToHSV(String hsv){
        int h = Integer.valueOf(hsv.substring(0,4),16);
        int s = Integer.valueOf(hsv.substring(4,8),16);
        valueOf(hsv.substring(8,12),16); int v = Integer.valueOf(hsv.substring(8,12),16); int v = Integer.valueOf(hsv.substring(8,12),16);
        return new float[]{(float)h,(float)s,(float)v};
}

And the value of HSV can be converted to colorData by hsvToString with the following code.

public static String hsvToString(int[] hsv) {
        String h = numToHex4(hsv[0]);
        String s = numToHex4(hsv[1]);
        String v = numToHex4(hsv[2]);
        String hhhhssssvvvv = h + s + v;
        return hhhhssssvvvv;
 }
 
 public static String numToHex4(int num) {
        return String.format("%04x", num);
 }

Interface description

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(long projectId,GroupPackBean groupPackBean)
        .publishColors(String color, IResultCallback callback);

Parameter Description

Parameter Description
color The color value, a 16-bit string in the format of hhhhhssssvvvv
callback The result callback

Sample code

TuyaCommercialLightingGroupPack
        .newGroupPackDpsManager(projectId,groupPackBean)
        .publishColors("hhhhhssssvvvvv", new IResultCallback() {
            @Override
            public void onError(String errorCode, String errorMsg) {
                if (callback ! = null) {
                    callback.onError(errorCode, errorMsg);
                }
            }

            @Override
            public void onSuccess() {
                if (callback ! = null) {
                    callback.onSuccess();
                }
            }
        });