更新时间:2022-01-07 07:03:32下载pdf
本文介绍获取设备信息、修改设备信息、移除设备、获取设备支持的指令集、下发指令等接口的使用。
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceID | String | true | 设备 ID |
TYDevice
说明
参数名 | 类型 | 说明 |
---|---|---|
id | String | 设备 ID |
uuid | String | 设备 uuid |
category | String | 产品品类 |
name | String | 设备名称 |
productID | String | 产品 ID |
productName | String | 产品名称 |
localKey | String | 密钥 |
isSubDevice | Bool | 是否为子设备 |
assetID | String | 资产 ID |
ipAddress | String | 设备 IP |
timeZone | String | 时区 |
activeTime | Int | 激活时间 |
updateTime | Int | 更新时间 |
createTime | Int | 初次配网时间 |
isOnline | Bool | 是否在线 |
icon | String | 设备图标(前缀:https://images.tuyacn.com/) |
longitude | String | 设备经度 |
latitude | String | 设备纬度 |
model | String | 设备模型 |
代码示例 |
TYDeviceManager().queryDeviceInfo(of: "") { deviceInfo, error in
guard error == nil else {
print(error?.localizedDescription)
return
}
let name = deviceInfo?.name
let productID = deviceInfo?.productID
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceIDs | Array<String> | true | 设备 ID 列表,限制最多20个 |
代码示例
TYDeviceManager().queryDevicesInfo(of: idArray) { (deviceArray, error) in
guard error == nil else {
print(error?.localizedDescription)
return
}
self.deviceList = deviceArray!
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceID | String | true | 设备 ID |
name | String | true | 设备名称 |
代码示例
TYDeviceManager().modifyDeviceName(for: self.device!.id, to: self.newName) { (bool, error) in
if bool == true {
// Do something
} else {
// Do something
}
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceID | String | true | 设备 ID |
代码示例
TYDeviceManager().removeDevice("Your device ID") { (bool, error) in
if bool == true {
// Do something
return
}
print(error?.localizedDescription)
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceIDs | Array<String> | true | 设备 ID 列表,限制最多20个 |
代码示例
TYDeviceManager().removeDevice("Your device id") { success, error in
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceID | String | true | 设备 ID |
代码示例
TYDeviceManager().resetDevice(for: "Your device id") { success, error in
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceID | String | true | 网关设备 ID |
TYPairedSubDevice
说明
参数名 | 类型 | 说明 |
---|---|---|
id | String | 设备 ID |
name | String | 设备名称 |
isOnline | Boolean | 设备在线状态 |
activeTime | Int | 激活时间 |
updateTime | Int | 设备状态更新时间 |
productID | String | 设备所属产品 ID |
category | String | 品类 |
nodeID | String | 子设备 nodeId |
assetID | String | 资产 ID |
icon | String | 设备图标 |
代码示例
TYDeviceManager().querySubDevices("Your device id") { (deviceArray, error) in
guard error == nil else {
print(error?.localizedDescription)
return
}
let devices = deviceArray
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceID | String | true | 设备 ID |
TYDeviceCommand
说明
参数名 | 类型 | 说明 |
---|---|---|
code | String | 状态码 |
value | Any | 状态值 |
代码示例
TYDeviceManager().queryDeviceStatus(of: "Your device id") { commands, error in
guard error == nil else {
print(error?.localizedDescription)
return
}
let devices = commands
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceID | String | true | 设备 ID |
代码示例
TYDeviceManager().queryDeviceStatus(of: "Your device id") { commands, error in
guard error == nil else {
print(error?.localizedDescription)
return
}
let commands = commands
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
category | String | true | 产品类别(如:dj ) |
TYCategoryStandardCommand
说明
参数名 | 类型 | 说明 |
---|---|---|
category | String | 产品品类 |
functions | Array<TYStandardCommand> | 指令集 |
TYStandardCommand
说明
参数名 | 类型 | 说明 |
---|---|---|
name | String | 指令名称 |
detail | String | 描述 |
code | String | 指令 |
type | String | 指令类型 |
values | String | 指令入参范围 |
代码示例
TYDeviceManager().queryCommandSetFromCategory("") { command, error in
guard error == nil else {
print(error?.localizedDescription)
return
}
let category = command?.category
let commadns = command?.functions
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceID | String | true | 设备 ID |
代码示例
TYDeviceManager().queryCommandSetFromDeviceID("Your device id") { command, error in
guard error == nil else {
print(error?.localizedDescription)
return
}
let category = command?.category
let commadns = command?.functions
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
deviceID | String | true | 设备 ID |
TYDeviceSpecification
说明
参数名 | 类型 | 说明 |
---|---|---|
category | String | 产品品类 |
functions | Array<TYStandardCommand> | 指令集 |
status | Array<TYStandardStatus> | 状态集 |
TYStandardStatus
说明
参数名 | 类型 | 说明 |
---|---|---|
name | String | 指令名称 |
code | String | 指令 |
type | String | 数据类型 |
values | String | 指令范围 |
代码示例
TYDeviceManager().queryDeviceSpecification(of: "Your category id") { specification, error in
guard error == nil else {
print(error?.localizedDescription)
return
}
let category = specification?.category
let functions = specification?.functions
let status = specification?.status
}
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
commands | Array<TYDeviceCommand> | true | 设备控制指令 |
deviceID | String | true | 设备 ID |
TYDeviceCommand
说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
code | String | true | 指令码 |
value | Any | true | 指令值 |
代码示例
TYDeviceManager().sendCommands([dp1, dp2, dp3], to: "Your device ID") { (bool, error) in
guard error == nil else {
print("Faild")
return
}
print("Succeed")
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈