TuyaSmartDevice Class Reference

Inherits from NSObject
Declared in TuyaSmartDevice.h

Overview

Device-related functions. 设备相关功能

  deviceModel

@property (nonatomic, strong, readonly) TuyaSmartDeviceModel *deviceModel

  delegate

@property (nonatomic, weak, nullable) id<TuyaSmartDeviceDelegate> delegate

+ deviceWithDeviceId:

Get TuyaSmartDevice instance. If current user don’t have this device, a nil will be return. 获取设备实例。如果当前用户没有该设备,将会返回nil。

+ (nullable instancetype)deviceWithDeviceId:(NSString *)devId

Parameters

devId

Device ID

Return Value

instance

Discussion

Get TuyaSmartDevice instance. If current user don’t have this device, a nil will be return. 获取设备实例。如果当前用户没有该设备,将会返回nil。

Declared In

TuyaSmartDevice.h

– initWithDeviceId:

Get TuyaSmartDevice instance. If current user don’t have this device, a nil will be return. 获取设备实例。如果当前用户没有该设备,将会返回nil。

- (nullable instancetype)initWithDeviceId:(NSString *)devId

Parameters

devId

Device ID

Return Value

instance

Discussion

Get TuyaSmartDevice instance. If current user don’t have this device, a nil will be return. 获取设备实例。如果当前用户没有该设备,将会返回nil。

Declared In

TuyaSmartDevice.h

– init

- (instancetype)init

– onlineMode

Get device online status. 获取设备在线状态

- (TYDeviceOnlineMode)onlineMode

Discussion

Get device online status. 获取设备在线状态

Declared In

TuyaSmartDevice.h

– publishDps:success:failure:

dp command publish. dp命令下发

- (void)publishDps:(NSDictionary *)dps success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

dps

dp dictionary

success

Success block

failure

Failure block

Discussion

dp command publish. dp命令下发

Declared In

TuyaSmartDevice.h

– publishDps:mode:success:failure:

dp command publish. dp命令下发

- (void)publishDps:(NSDictionary *)dps mode:(TYDevicePublishMode)mode success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

dps

dp dictionary

mode

Publish mode(Lan/Internet/Auto)

success

Success block

failure

Failure block

Discussion

dp command publish. dp命令下发

Declared In

TuyaSmartDevice.h

– updateName:success:failure:

Edit device name. 修改设备名称

- (void)updateName:(NSString *)name success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

name

Device name

success

Success block

failure

Failure block

Discussion

Edit device name. 修改设备名称

Declared In

TuyaSmartDevice.h

– updateIcon:success:failure:

Edit device icon. 修改设备图片

- (void)updateIcon:(UIImage *)icon success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

icon

icon

success

Success block

failure

Failure block

Discussion

Edit device icon. 修改设备图片

Declared In

TuyaSmartDevice.h

– syncWithCloud:failure:

Sync device information. 同步设备信息到缓存

- (void)syncWithCloud:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

success

Success block

failure

Failure block

Discussion

Sync device information. 同步设备信息到缓存

Declared In

TuyaSmartDevice.h

+ syncDeviceInfoWithDevId:homeId:success:failure:

Sync device information. 同步设备信息

+ (void)syncDeviceInfoWithDevId:(NSString *)devId homeId:(long long)homeId success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

devId

Device ID

homeId

Home ID

success

Success block

failure

Failure block

Discussion

Sync device information. 同步设备信息

Declared In

TuyaSmartDevice.h

+ syncSubDeviceInfoWithGatewayId:devId:success:failure:

Sync subdevice information. 同步子设备信息

+ (void)syncSubDeviceInfoWithGatewayId:(NSString *)gatewayId devId:(NSString *)devId success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

gatewayId

Gateway ID

devId

Device ID

success

Success block

failure

Failure block

Discussion

Sync subdevice information. 同步子设备信息

Declared In

TuyaSmartDevice.h

– remove:failure:

Remove device. Unbind the device with current user. 移除设备,解除与当前用户的关联关系。

- (void)remove:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

success

Success block

failure

Failure block

Discussion

Remove device. Unbind the device with current user. 移除设备,解除与当前用户的关联关系。

Declared In

TuyaSmartDevice.h

– resetFactory:failure:

Restore factory settings. 恢复出厂设置

- (void)resetFactory:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

success

Success block

failure

Failure block

Discussion

Restore factory settings. 恢复出厂设置

Declared In

TuyaSmartDevice.h

– getSubDeviceListFromCloudWithSuccess:failure:

Get sub-device list of current gateway. 获取当前网关下的子设备列表

- (void)getSubDeviceListFromCloudWithSuccess:(nullable void ( ^ ) ( NSArray<TuyaSmartDeviceModel*> *subDeviceList ))success failure:(nullable TYFailureError)failure

Parameters

success

Success block

failure

Failure block

Discussion

Get sub-device list of current gateway. 获取当前网关下的子设备列表

Declared In

TuyaSmartDevice.h

– syncLocationToDeviceWithSucecess:failure:

Synchronize the Longitude and Latitude of the Mobile Phone to the Device 将手机的经纬度同步到设备

- (void)syncLocationToDeviceWithSucecess:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

success

Success block

failure

Failure block

Discussion

Synchronize the Longitude and Latitude of the Mobile Phone to the Device 将手机的经纬度同步到设备

Declared In

TuyaSmartDevice.h

– getFirmwareUpgradeInfo:failure:

Get firmware upgrade information. 获取设备升级信息

- (void)getFirmwareUpgradeInfo:(nullable void ( ^ ) ( NSArray<TuyaSmartFirmwareUpgradeModel*> *upgradeModelList ))success failure:(nullable TYFailureError)failure

Parameters

success

Success block

failure

Failure block

Discussion

Get firmware upgrade information. 获取设备升级信息

Declared In

TuyaSmartDevice.h

– upgradeFirmware:success:failure:

Upgrade firmware. Receive success or failure callback from TuyaSmartDeviceDelegate. 下发升级指令,设备开始升级, 升级成功或失败会通过TuyaSmartDeviceDelegate返回

- (void)upgradeFirmware:(NSInteger)type success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

type

Device type of TuyaSmartFirmwareUpgradeModel

success

Success block

failure

Failure block

Discussion

Upgrade firmware. Receive success or failure callback from TuyaSmartDeviceDelegate. 下发升级指令,设备开始升级, 升级成功或失败会通过TuyaSmartDeviceDelegate返回

Declared In

TuyaSmartDevice.h

– cancelFirmwareRequest

Cancel firmware upgrade network request. 取消未完成的固件升级接口请求

- (void)cancelFirmwareRequest

Discussion

Cancel firmware upgrade network request. 取消未完成的固件升级接口请求

Declared In

TuyaSmartDevice.h

– updateDeviceVersion:type:success:failure:

Report device firmware version. 上报设备固件的版本号

- (void)updateDeviceVersion:(NSString *)version type:(NSInteger)type success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

version

Version

type

Device type

success

Success block

failure

Failure block

Discussion

Report device firmware version. 上报设备固件的版本号

Declared In

TuyaSmartDevice.h

– getWifiSignalStrengthWithSuccess:failure:

Get wifi signal strength. Receive signal strength from[TuyaSmartDeviceDelegate device:signal:]. 获取wifi的信号强度。通过[TuyaSmartDeviceDelegate device:signal:]接收回调

- (void)getWifiSignalStrengthWithSuccess:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

success

Success block

failure

Failure block

Discussion

Get wifi signal strength. Receive signal strength from[TuyaSmartDeviceDelegate device:signal:]. 获取wifi的信号强度。通过[TuyaSmartDeviceDelegate device:signal:]接收回调

Declared In

TuyaSmartDevice.h

– publishMessageInLanWithBody:type:success:failure:

publish message in lan 发送局域网消息

- (void)publishMessageInLanWithBody:(NSDictionary *)body type:(NSInteger)type success:(nullable TYSuccessDict)success failure:(nullable TYFailureError)failure

Parameters

body

message body

type

message type

success

Success block

failure

Failure block

Discussion

publish message in lan 发送局域网消息

Declared In

TuyaSmartDevice.h

– getInitiativeQueryDpsInfoWithDpsArray:success:failure:

Query dp initiative. Some dp won’t report initiative when changed. 获取主动查询的dp点,这些dp点只有在主动查询的时候才上报,否则不会上报。

- (void)getInitiativeQueryDpsInfoWithDpsArray:(nullable NSArray *)dpsArray success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

dpsArray

dpId array. If nil or empty array passed in,All dp will be queried。

success

Success block

failure

Failure block

Discussion

Query dp initiative. Some dp won’t report initiative when changed. 获取主动查询的dp点,这些dp点只有在主动查询的时候才上报,否则不会上报。

Declared In

TuyaSmartDevice.h

– awakeDeviceWithSuccess:failure:

Awake low energy device. 唤醒低功耗设备

- (void)awakeDeviceWithSuccess:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

success

Success block

failure

Failure block

Discussion

Awake low energy device. 唤醒低功耗设备

Declared In

TuyaSmartDevice.h

– addDelegate:forProtocol:

add custom message delegate. Receive custom message from - (void)device:(TuyaSmartDevice *)device didReceiveCustomMessage:(TuyaSmartMQTTMessageModel *)message. 添加自定义消息代理 通过- (void)device:(TuyaSmartDevice *)device didReceiveCustomMessage:(TuyaSmartMQTTMessageModel *)message 回调

- (void)addDelegate:(id<TuyaSmartDeviceDelegate>)delegate forProtocol:(NSInteger)protocol

Parameters

delegate

Delegate

protocol

Protocol

Discussion

add custom message delegate. Receive custom message from - (void)device:(TuyaSmartDevice *)device didReceiveCustomMessage:(TuyaSmartMQTTMessageModel *)message. 添加自定义消息代理 通过- (void)device:(TuyaSmartDevice *)device didReceiveCustomMessage:(TuyaSmartMQTTMessageModel *)message 回调

Declared In

TuyaSmartDevice.h

– removeDelegate:forProtocol:

remove custom message delegate 删除自定义消息代理

- (void)removeDelegate:(id<TuyaSmartDeviceDelegate>)delegate forProtocol:(NSInteger)protocol

Parameters

delegate

Delegate

protocol

Protocol

Discussion

remove custom message delegate 删除自定义消息代理

Declared In

TuyaSmartDevice.h

– publishCustomMessageWithData:protocol:success:failure:

send to custom message 自定义(非dps)消息发送

- (void)publishCustomMessageWithData:(NSDictionary *)data protocol:(NSInteger)protocol success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

data

Data

protocol

Protocol

success

Success block

failure

Failure block

Discussion

send to custom message 自定义(非dps)消息发送

Declared In

TuyaSmartDevice.h

– publishDpWithCommands:success:failure:

dp command publish. 标准 dp 命令下发

- (void)publishDpWithCommands:(NSDictionary *)commands success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure

Parameters

commands

dpCode - value dictionary

success

Success block

failure

Failure block

Discussion

dp command publish. 标准 dp 命令下发

Declared In

TuyaSmartDevice.h