Asset Service

Last Updated on : 2024-05-27 03:56:24download

This topic describes the asset service, allowing you to operate assets and get information about devices associated with an asset.

Check if the asset system is used through IUser.getSpaceType(). 1 indicates the space system, and 2 indicates the asset system.

Common properties

IAsset

Method Description
getAssetId(): String The unique identifier of the asset.
getAssetName(): String The name of the asset.
getParentAssetId(): String The unique identifier of the parent asset.
getPermission(): String The asset permissions.
  • all: All permissions on assets.
  • read: Read-only permission on assets.
getCurrentSubAssetNum(): Int The number of sub-assets.
getCurrentAssetDeviceNum(): Int The number of devices in assets.
getUserDefinedPath(): String The asset path.

IAssetDeviceListResult

Method Description
getDevices(): List The list of devices.
getHasMore(): Boolean Whether more devices exist.
getLastRowKey(): String The RowKey of the last row, used for pagination.

IAssetDevice

Method Description
getDeviceId(): String The device ID.
getDeviceName(): String The name of the device.
isOnline(): Boolean Indicates whether the device is online on the LAN or internet.
getIcon(): String The icon of the device.
getActiveTime(): Long The time when the device is activated.
getAssetId(): String The asset ID.
getCategoryName(): String The name of the product category.
getCategory(): String The code of the product category.
getIsGateWay(): Boolean Whether it is a gateway.
getSub(): Boolean Whether a sub-device exists.
getProductName(): String The name of the product.
getTimeZone(): String The time zone of the device.

IDeviceStatistic

Method Description
getStatisticType(): String The statistic type.
getTotal(): Long The total number of devices.
getTypeValue(): String The display name of the statistic type.

Add asset

Parameters

Parameter Type Required Description
name String Yes The name of the asset.
parentAssetId String No The ID of the parent asset.
callback IndustryCallBack Yes The callback.

Example

AssetService.create("name", "parentAssetId", new IndustryCallBack() {
            @Override
            public void onSuccess() {
                Log.d(TAG, "onSuccess: ");
            }

            @Override
            public void onError(int i, String s) {
                Log.d(TAG, "onError: ");

            }
        });

Rename asset

Parameters

Parameter Type Required Description
assetId String Yes The ID of the target asset.
name String Yes The new name.
callback IndustryCallBack Yes The callback.

Example

AssetService.update("assetId", "name", new IndustryCallBack() {
            @Override
            public void onSuccess() {
                Log.d(TAG, "onSuccess: ");

            }

            @Override
            public void onError(int i, String s) {
                Log.d(TAG, "onError: ");

            }
        });

Delete asset

Parameters

Parameter Type Required Description
assetId String Yes The ID of the target asset.
callback IndustryCallBack Yes The callback.

Example

AssetService.remove("assetId", new IndustryCallBack() {
            @Override
            public void onSuccess() {
                Log.d(TAG, "onSuccess: ");

            }

            @Override
            public void onError(int i, String s) {
                Log.d(TAG, "onError: ");

            }
        });

Get the property of a single asset

Parameters

Parameter Type Required Description
assetId String Yes The ID of the target asset.
callback IndustryValueCallBack Yes The callback.

Example

AssetService.asset("assetId", new IndustryValueCallBack<IAsset>() {
            @Override
            public void onSuccess(IAsset iAsset) {
                Log.d(TAG, "onSuccess: ");
            }

            @Override
            public void onError(int i, String s) {
                Log.d(TAG, "onError: ");

            }
        });

Get the list of sub-asset properties

Parameters

Parameter Type Required Description
assetId String? No The ID of the target asset. If the value is nil, all sub-assets will be queried.
callback IndustryValueCallBack<List> Yes The callback, returning the list of sub-assets.

Example

AssetService.subAssets("assetId", new IndustryValueCallBack<List<IAsset>>() {
            @Override
            public void onSuccess(List<IAsset> iAssets) {
                Log.d(TAG, "onSuccess: ");

            }

            @Override
            public void onError(int i, String s) {
                Log.d(TAG, "onError: ");

            }
        });

Get the list of device statistics

Parameters

Parameter Type Required Description
assetId String No The ID of the target asset.
callback IndustryValueCallBack<List> Yes The callback, returning the list of device statistics.

Example

AssetService.statistics("assetId", new IndustryValueCallBack<List<IDeviceStatistic>>() {
            @Override
            public void onSuccess(List<IDeviceStatistic> result) {
                Log.d(TAG, "onSuccess: ");
            }

            @Override
            public void onError(int i, String s) {
                Log.d(TAG, "onError: ");

            }
        });

Get the list of devices

Parameters

Parameter Type Required Description
assetId String Yes The ID of the target asset.
lastRowKey String? No The RowKey of the last row returned from the previous query, used for pagination.
callback IndustryValueCallBack Yes The callback, returning the list of devices.

Example

AssetService.devices("assetId", "lastRowKey", new IndustryValueCallBack<IAssetDeviceListResult>() {
            @Override
            public void onSuccess(IAssetDeviceListResult iAssetDeviceListResult) {
                Log.d(TAG, "onSuccess: ");
            }

            @Override
            public void onError(int i, String s) {
                Log.d(TAG, "onError: ");

            }
        });

Parameters

Parameter Type Required Description
assetId String No The ID of the target asset.
statisticsType String No The statistic type IDeviceStatistic.getStatisticType.
lastRowKey String? No The RowKey of the last row returned from the previous query, used for pagination.
pageSize Int Yes The number of items returned per page.
callback IndustryValueCallBack Yes The callback, returning the list of devices.

Example

AssetService.devices("assetId", null, 20, "lastRowKey", new IndustryValueCallBack<IAssetDeviceListResult>() {
            @Override
            public void onSuccess(IAssetDeviceListResult iAssetDeviceListResult) {
                Log.d(TAG, "onSuccess: ");
            }

            @Override
            public void onError(int i, String s) {
                Log.d(TAG, "onError: ");

            }
        });

Query the list of devices

Parameters

Parameter Type Required Description
assetId String No The ID of the target asset.
lastRowKey String? No The RowKey of the last row returned from the previous query, used for pagination.
deviceName String Yes The name of the device.
pageSize Int Yes The number of items returned per page.
callback IndustryValueCallBack Yes The callback, returning the list of devices.

Example

AssetService.search("assetId", "Light", 20, "lastRowKey", new IndustryValueCallBack<IAssetDeviceListResult>() {
            @Override
            public void onSuccess(IAssetDeviceListResult iAssetDeviceListResult) {
                Log.d(TAG, "onSuccess: ");
            }

            @Override
            public void onError(int i, String s) {
                Log.d(TAG, "onError: ");

            }
        });

Get the management instance of a single asset

Parameters

Parameter Type Required Description
assetId String Yes The ID of the target asset.

Example

IAssetManager manager = AssetService.assetManager("assetId");