Area Management

Last Updated on : 2024-04-03 10:06:48download

Get first-level area list

API description

ThingCommercialLightingProject.newProjectInstance(long projectId)
            .getAreaList(IThingResultCallback<List<AreaBean>> callback);

Parameter description

Parameter Description
projectId The project ID.

Example

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

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

Get sub-area list

API description

ThingCommercialLightingArea.newAreaInstance(long projectId, long areaId).getSubAreaList(
    IThingResultCallback<List<AreaBean>> listener
);

Parameter description

Parameter Description
projectId The project ID.
areaId The area ID.

Example

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

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

Get area hierarchy list

API description

Get the list of first-level hierarchy.

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

Parameter description

Parameter Description
projectId The project ID.
needUnassignedArea Specifies whether to return the unassigned area.
needPublicArea Specifies whether to return the public area.

Example

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

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

Get area information

API description

ThingCommercialLightingArea.newAreaInstance(long projectId, long areaId).getAreaInfo(
    IThingResultCallback<SimpleAreaBean> callback
);

Parameter description

Parameter Description
projectId The project ID.
areaId The area ID.

Example

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

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

Get area relation ID

API description

SimpleAreaBean # getRelationId()

Parameter description

Parameter Description
projectId The project ID.
areaId The area ID.

Example

ThingCommercialLightingArea.newAreaInstance(projectId, areaId).getAreaInfo(new IThingResultCallback<SimpleAreaBean>() {
    @Override
    public void onSuccess(SimpleAreaBean result) {
        long relationId = result.getRelationId();
    }

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

Get device list in an area

API description

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

Parameter description

Parameter Description
tag The criteria for the device list, defaulting to an empty string.
limit The number of items returned per page.
offsetKey The current page number. The page number starts at 1 and is incremented by 1 for subsequent pages.
callback The callback.

Example

        ThingCommercialLightingArea.newAreaInstance(mProjectId, mAreaId).queryDeviceListInArea("", 20,
                "1", new IThingResultCallback<LightingDeviceListBean>() {
                    @Override
                    public void onSuccess(LightingDeviceListBean result) {
                        //success callback0
                    }

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

Create area

Create area (for indoor or parking lot projects)

API description

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

Parameter description

Parameter Description
projectId The project ID.
currentAreaId The ID of the area. If not specified, it defaults to 0.
name The name of the area.
roomLevel The ID of the area hierarchy.

Example

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

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

Create area (for outdoor projects)

API description

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

Parameter description

Parameter Description
projectId The project ID.
currentAreaId The ID of the area. If not specified, it defaults to 0.
name The name of the area.
roomLevel The ID of the area hierarchy.
longitude The longitude of the area.
latitude The latitude of the area.
address The address of the area.
callback The callback.

Example

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

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

Create sub-area (for indoor or parking lot projects)

API description

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

Parameter description

Parameter Description
projectId The project ID.
areaId The area ID.
subAreaName The name of the sub-area.

Example

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

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

Create sub-area (for outdoor projects)

API description

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

Parameter description

Parameter Description
projectId The project ID.
areaId The area ID.
subAreaName The name of the sub-area.
longitude The longitude of the area.
latitude The latitude of the area.
address The geographical location of the area.

Example

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

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

Modify area

Modify area (for indoor or parking lot projects)

API description

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

Parameter description

Parameter Description
projectId The project ID.
areaId The area ID.
name The name of the area.

Example

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

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

Modify area (for outdoor projects)

API description

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

Parameter description

Parameter Description
projectId The project ID.
areaId The area ID.
name The name of the area.
longitude The longitude of the area.
latitude The latitude of the area.
address The geographical location of the area.

Example

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

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

Delete area

API description

ThingCommercialLightingArea.newAreaInstance(long projectId, long areaId).delete(
    IThingResultCallback<Boolean> callback
);

Parameter description

Parameter Description
projectId The project ID.
areaId The area ID.

Example

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

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

Transfer device

Transfer devices from one area to another. The following figure shows how it works.

Area Management

API description

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

Parameter description

Parameter Description
devIds The list of device IDs.
transferListener The callback for device transfer and its result.

Callbacks in DefaultDeviceTransferListener:

public abstract class DefaultDeviceTransferListener implements IDeviceTransferListener {

    @Override
    public void onFilterMeshDeviceFail(String errorMsg, String errorCode) {
            // Callback for failure in filtering Bluetooth mesh device
    }

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

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

    @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) {
               // Failed to create a new group 
   }

    @Override
    public void bindDeviceToGroupByLocalError(long groupId, String devId, String errorMsg, String errorCode) {
            // Failed to locally bind a mesh device with the group
    }

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

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

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

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

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


        // Exception callback, invoking this callback means the device transfer operation has an exception, and the handleResult callback will not be triggered
    @Override
    public abstract void onError(String errorMsg, String errorCode);
}