Area Management

Last Updated on : 2022-02-17 05:45:59download

Get a list of level-1 areas

Interface description

TuyaCommercialLightingProject.newProjectInstance(long projectId)
            .getAreaList(ITuyaResultCallback<List<AreaBean>> callback);

Parameters

Parameters Description
projectId projectID

Example

TuyaCommercialLightingProject.newProjectInstance(projectId).getAreaList(
            new ITuyaResultCallback<List<AreaBean>>() {
            @Override
            public void onSuccess(List<AreaBean> result) {
                    //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                  // error callback
            }
        });

Get the list of sub-areas

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).getSubAreaList(
    ITuyaResultCallback<List<AreaBean>> listener
);

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).getSubAreaList(
    new ITuyaResultCallback<List<AreaBean>>() {
            @Override
            public void onSuccess(List<AreaBean> result) {
                    //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                  // error callback
            }
        }
);

Get a list of areas

Interface description

Returns a list of the level-1 areas for a project.

TuyaCommercialLightingProject.newProjectInstance(long projectId).getAreaLevels(
    boolean needUnassignedArea,
    boolean needPublicArea,
    ITuyaResultCallback<AreaListInProjectResponse> callback
) ;

Parameters

Parameters Description
projectId Project ID
needUnassignedArea Whether to return the unassignedArea hierarchy
needPublicArea Whether to return the PublicArea hierarchy

Example

TuyaCommercialLightingProject.newProjectInstance(projectId).getAreaLevels(needUnassignedArea, needPublicArea, new ITuyaResultCallback<AreaListInProjectResponse>() {
            @Override
            public void onSuccess(AreaListInProjectResponse result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Get area information

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).getAreaInfo(
    ITuyaResultCallback<SimpleAreaBean> callback
);

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

        TuyaCommercialLightingArea.newAreaInstance(projectId, areaId).getAreaInfo(new ITuyaResultCallback<SimpleAreaBean>() {
            @Override
            public void onSuccess(SimpleAreaBean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Get a list of devices for an area

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).queryDeviceListInArea(
    String tag, int limit, String offsetKey, ITuyaResultCallback<LightingDeviceListBean> callback
);

Parameters

Parameters Description
tag The conditional category of the device list, passed null by default
limit The number of devices requested per page.
offsetKey The current page number, pass 1 for the first page and increment the number of subsequent pages
callback The result callback
Example
        TuyaCommercialLightingArea.newAreaInstance(mProjectId, mAreaId).queryDeviceListInArea("", 20,
                "1", new ITuyaResultCallback<LightingDeviceListBean>() {
                    @Override
                    public void onSuccess(LightingDeviceListBean result) {
                        //success callback
                    }

                    @Override
                    public void onError(String errorCode, String errorMessage) {
                            //error callback
                    }
                });

Create an area

Create an area (for an indoor project)

Interface description

TuyaCommercialLightingArea.getLightingAreaManager().createArea(
    long projectId,
    long currentAreaId,
    String name,
    int roomLevel,
    ITuyaResultCallback<SimpleAreaBean> callback
 );

Parameters

Parameters Description
projectId Project ID
currentAreaId Current AreaID, if none passed 0
name Area name
roomLevel The level ID of the created Area

Example

TuyaCommercialLightingArea.getLightingAreaManager().createArea(projectId, currentAreaId, name, roomLevel, new ITuyaResultCallback<SimpleAreaBean>() {
            @Override
            public void onSuccess(SimpleAreaBean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Create an area (for an outdoor project)

Interface description

TuyaCommercialLightingArea.getLightingAreaManager().createArea(
    long projectId,
    long currentAreaId,
    String name,
    int roomLevel,
    double longitude,
    double latitude,
    String address,
    ITuyaResultCallback<SimpleAreaBean> callback
 );

Parameters

Parameters Description
projectId Project ID
currentAreaId Current AreaID, if none passed 0
name Area name
roomLevel The level ID of the created Area
longitude The longitude of the current Area location
latitude The dimension of the current Area location
address The address of the current Area
callback Callback

Example

TuyaCommercialLightingArea.getLightingAreaManager().createArea(projectId, currentAreaId, name, roomLevel, longitude, latitude, address, new ITuyaResultCallback<SimpleAreaBean>() {
            @Override
            public void onSuccess(SimpleAreaBean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Create a sub-area (for an indoor area)

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).createSubArea(
    String subAreaName,
    ITuyaResultCallback<SimpleAreaBean> callback
);

Parameters

Parameters Description
projectId projectID
areaId AreaID
subAreaName subAreaName

Example

TuyaCommercialLightingArea.newAreaInstance(projectId, areaId).createSubArea(subAreaName, new ITuyaResultCallback<SimpleAreaBean>() {
            @Override
            public void onSuccess(SimpleAreaBean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Create a sub-area (for an outdoor area)

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).createSubArea(
        String subAreaName,
    double longitude,
    double latitude,
    String address,
    ITuyaResultCallback<SimpleAreaBean> callback
);

Parameters

Parameters Description
projectId projectID
areaId AreaID
subAreaName subAreaName
longitude Area location longitude
latitude Area location latitude
address Area actual location address: latitude and longitude positioned to the location

Example

TuyaCommercialLightingArea.newAreaInstance(projectId, areaId).createSubArea(subAreaName, longitude, latitude, address, new ITuyaResultCallback<SimpleAreaBean>() {
            @Override
            public void onSuccess(SimpleAreaBean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Create a parent area (for an indoor project)

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).createParentArea(
    String parentAreaName,
    ITuyaResultCallback<SimpleAreaBean> callback
);

Parameters

Parameters Description
projectId projectID
areaId AreaID
parentAreaName parentAreaName

Example

TuyaCommercialLightingArea.newAreaInstance(projectId, areaId).createParentArea(parentAreaName, new ITuyaResultCallback<SimpleAreaBean>() {
            @Override
            public void onSuccess(SimpleAreaBean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Create a parent area (for an outdoor project)

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).createParentArea(
    String parentAreaName,
    double longitude,
    double latitude,
    String address,
    ITuyaResultCallback<SimpleAreaBean> callback
);

Parameters

Parameters Description
projectId projectID
areaId AreaID
parentAreaName parentAreaName
longitude Area location longitude
latitude Area location latitude
address Area actual location address: latitude and longitude positioned to the location

Example

TuyaCommercialLightingArea.newAreaInstance(projectId, areaId).createParentArea(parentAreaName, longitude, latitude, address, new ITuyaResultCallback<SimpleAreaBean>() {
            @Override
            public void onSuccess(SimpleAreaBean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Modify an area

Modify an area (for an indoor project)

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).updateName(
    String name,
    ITuyaResultCallback<Boolean> callback
);

Parameters

Parameter Description
projectId projectID
areaId areaID
name Area name

Example

TuyaCommercialLightingArea.newAreaInstance(projectId, areaId).updateName(name, new ITuyaResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Modify an area (for an outdoor project)

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).updateAreaInfo(
    String name,
    double longitude,
    double latitude,
    String address, 
    ITuyaResultCallback<Boolean> callback
);

Parameters

Parameters Description
projectId projectID
areaId AreaID
name Area name
longitude Area location longitude
latitude Area location latitude
address Area actual location address: latitude and longitude location to locate the location

Example

TuyaCommercialLightingArea.newAreaInstance(projectId, areaId).updateAreaInfo(name,longitude,latitude,address, new ITuyaResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        });

Delete an area

Interface description

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).delete(
    ITuyaResultCallback<Boolean> callback
);

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

TuyaCommercialLightingArea.newAreaInstance(long projectId, long areaId).delete(
   new ITuyaResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {
                //success callback
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                    //error callback
            }
        }
);

Transfer devices

Certain devices can be transferred from one area to another area.

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId, long areaId)
        .transferDevices(List<String> devIds,DefaultDeviceTransferListener transferListener)

Parameters

Parameters Description
devIds Set device IDs
transferListener Area transfer process and result callback

The callback of DefaultDeviceTransferListener is described as follows.

public abstract class DefaultDeviceTransferListener implements IDeviceTransferListener {

    @Override
    public void onFilterMeshDeviceFail(String errorMsg, String errorCode) {
            //Filter bluetooth Mesh device failure callback
    }

    @Override
    public void removeDeviceFromGroupByLocalError(long groupId, List<String> devIds, String errorMsg, String errorCode) {
             // The operation to remove the device from the local group failed
    }

    @Override
    public void removeDeviceFromGroupByCloudError(long groupId, List<String> devIds, String errorMsg, String errorCode) {
            //Removal of device from cloud group failed
    }

    @Override
    public void saveDevicesToNewAreaError(long areaId, List<String> devIds, String errorMsg, String errorCode) {
            // Failed to assign the device to the new Area
    }

    @Override
    public void createNewGroupError(long areaId, List<String> devIds, String errorMsg, String errorCode) {
            //Creation of new group failed
   }

    @Override
    public void bindDeviceToGroupByLocalError(long groupId, String devId, String errorMsg, String errorCode) {
            //Local bind mesh device to group operation failed
    }

    @Override
    public void bindDeviceToGroupByGroupError(long groupId, List<String> devId, String errorMsg, String errorCode) {
             // The operation to bind the device to a group in the cloud failed
    }

    @Override
    public void onTransferStateChanged(@TransferState int state) {
            //deprecated
    }

    @Override
    public void onDeviceOperationByLocal(@TransferState int state, @DeviceOperationType int operationType,
                                         List<ComplexDeviceBean> deviceBeans, boolean success) {
        //deprecated
    }

    @Override
    public void onResult(List<FilterGroup> filterGroups) {
        // Outdated result callbacks, do not use them, you can use handleResult callbacks
    }

    // Final result callback, which will be walked to at the end of the process
    @Override
    public abstract void handleResult(TransferResultSummary transferResultSummary);
    

    //Exception callback, going to this callback means the device transfer operation has an exception, at this time will not trigger handleResult callback
    @Override
    public abstract void onError(String errorMsg, String errorCode);
}

Get area information

Get area group control management

Interface Description

ILightingStandardAreaDpsManager areaDpsManager = TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance();

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

ILightingStandardAreaDpsManager areaDpsManager = TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance();

Get relevant DP data for an area

Interface Description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getDps();

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

String areaDps = TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getDps();

Get the area switch status

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getSwitchStatus()

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

boolean switchOn = TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getSwitchStatus()

Get brightness percentage

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getBrightPercent()

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

int brightnessPercent = TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getBrightPercent()

Get color temperature percentage

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getTemperaturePercent()

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

int temperaturePercent = TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getTemperaturePercent();

Get color light mode color value

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getColorData();

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

String colorData = TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getColorData();

Get a scene mode

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getSceneStatus();

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

LightDefaultSceneType sceneType = TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getSceneStatus();

Get the current light mode

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getCurrentMode();

Parameters

Parameters Description
projectId projectID
areaId areaID

Example

AreaDpMode areaDpMode = TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .getCurrentMode();

Control an area group

Area group control is used to control of all devices in an area. Supported control DPs are switch, brightness, mode, color temperature, and more. These DPs must be called in TuyaCommercialLightingArea#newAreaInstance#getSubAreaList to get the AreaBean information of the current area.

Toggle switch state

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .publishSwitchStatus(boolean status, final IResultCallback callback);

Parameters

Parameters Description
status Switch status, true: on false: off
callback The result callback

Example

TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .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();
                }
            }
        });

Switch the light mode

Interface description

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

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .publishWorkMode(AreaDpMode mode, IResultCallback callback);

Parameters

Parameters Description
mode The enumeration value of the mode to be switched, including MODE_WHITE_LIGHT, MDOE_COLORFUL_LIGHT and MODE_SCENE
callback The callback

Example

TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .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();
                }
            }
        });

Adjust the color temperature value

This operation is only supported in white light mode.

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .publishTemperaturePercent(int value, IResultCallback callback);

Parameters

Parameters Description
value The value of the color temperature, from 0 to 1000
callback The result callback

Example

TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .publishTemperaturePercent(50, 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 the scene

This operation is only supported in scene mode.

Interface description

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .publishSceneStatus(LightDefaultSceneType type, IResultCallback callback);

Parameters

Parameters Description
type The scene type, including NONE, WORK, MEETING, SIESTA, OFF_DUTY, sub-table indicates none mode, meeting mode light, work mode light, lunch break mode light and off duty mode light.
callback Execution result callback

Example

TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .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 the color light

This operation is only supported in color light mode.

Returns 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, and vvvvv means the brightness value after hex. You can use the stringToHSV method to convert colorData to hsv value. Example:

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

The value of HSV can be converted to colorData by hsvToString. Example:

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

TuyaCommercialLightingArea
        .newAreaInstance(long projectId,long areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .publishColors(String color, IResultCallback callback);

Parameters

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

Example

TuyaCommercialLightingArea
        .newAreaInstance(projectId,areaId)
        .getLightingStandardAreaDpsManagerInstance()
        .publishColors("hhhhssssvvvv", 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();
                }
            }
        });