English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Asset Management

Last Updated on : 2022-01-07 07:03:31download

TYAssetManager provides API methods that enable interactions to manage assets.

Currently, the SDK cannot be used to add, modify, or delete assets. These operations can only be implemented on the Tuya IoT Platform. For more information, see Manage Assets.

Query authorized assets for users

Parameters

Parameter Type Required Description
parentAssetID String false The ID of the parent asset.
pageNumber Int false The number of the page to be returned. By default, the value is empty to return the first page.
pageSize Int false The number of entries to be returned per page. Default value: 20. Maximum value: 20.

TYActionableAssetsRequestResult

Parameter Type Description
hasMoreResult Bool Indicates whether additional data is available.
assets Array<TYVagueAsset> The list of assets.
projectName String The name of the project.

TYVagueAsset

Parameter Type Description
id String The ID of the asset.
name String The name of the asset.
permission String The permissions on the asset. Valid values: all: all permissions. read: read-only permission.

Example

TYAssetManager().queryAssets { [weak self] (result, error) in
    guard error == nil else {
        print(error?.localizedDescription)
        return
    }
    UserModel.shared.asset = result?.assets.first
    self?.currentHomeLabel.text = UserModel.shared.asset?.name
}

Query devices of a specific asset on pages

Parameters

Parameter Type Required Description
assetID String true The ID of the asset.
pageSize Int true The number of entries to be returned per page. Maximum value: 20.
lastRowKey String false The row key of the last entry on each page.

TYDevicesRequestResult

Parameter Type Description
devices Array<TYVagueDevice> The list of device response objects in the asset.
lastRowKey String The row key of the last entry on each page.
totalSize Int The number of entries to be returned per page.
hasNextResult Bool Specifies whether to return the next page.

TYVagueDevice

Parameter Type Description
id String The ID of the device.
assetID String The ID of the asset.
assetName String The name of the asset.

Example

TYAssetManager().queryDevices(in: "", pageSize: 0, lastRowKey: "20") { result, error in
    guard error == nil else {
        print(error?.localizedDescription)
        return
    }
    let devices = result?.devices
}