Tuya.Net
Public Member Functions | Static Public Member Functions
com.clusterrr.TuyaNet.TuyaIRControl Class Reference

Tuya virtual IR remote control More...

Inheritance diagram for com.clusterrr.TuyaNet.TuyaIRControl:
Inheritance graph
[legend]
Collaboration diagram for com.clusterrr.TuyaNet.TuyaIRControl:
Collaboration graph
[legend]

Public Member Functions

 TuyaIRControl (string ip, string localKey, string deviceId, TuyaProtocolVersion protocolVersion=TuyaProtocolVersion.V33, int port=6668, int receiveTimeout=250)
 Creates a new instance of the TuyaDevice class. More...
 
 TuyaIRControl (string ip, TuyaApi.Region region, string accessId, string apiSecret, string deviceId, TuyaProtocolVersion protocolVersion=TuyaProtocolVersion.V33, int port=6668, int receiveTimeout=250)
 Creates a new instance of the TuyaDevice class. More...
 
async Task< string > GetButtonCodeAsync (int timeout, int retries=2, CancellationToken cancellationToken=default)
 Learns button code of remote control. More...
 
async Task SendButtonCodeAsync (string buttonCode, int retries=2, int? overrideRecvTimeout=null, CancellationToken cancellationToken=default)
 Sends button code. More...
 
- Public Member Functions inherited from com.clusterrr.TuyaNet.TuyaDevice
 TuyaDevice (string ip, string localKey, string deviceId, TuyaProtocolVersion protocolVersion=TuyaProtocolVersion.V33, int port=6668, int receiveTimeout=250)
 Creates a new instance of the TuyaDevice class. More...
 
 TuyaDevice (string ip, TuyaApi.Region region, string accessId, string apiSecret, string deviceId, TuyaProtocolVersion protocolVersion=TuyaProtocolVersion.V33, int port=6668, int receiveTimeout=250)
 Creates a new instance of the TuyaDevice class. More...
 
string FillJson (string json, bool addGwId=true, bool addDevId=true, bool addUid=true, bool addTime=true)
 Fills JSON string with base fields required by most commands. More...
 
byte[] EncodeRequest (TuyaCommand command, string json)
 Creates encoded and encrypted payload data from JSON string. More...
 
TuyaLocalResponse DecodeResponse (byte[] data)
 Parses and decrypts payload data from received bytes. More...
 
async Task< TuyaLocalResponseSendAsync (TuyaCommand command, string json, int retries=2, int nullRetries=1, int? overrideRecvTimeout=null, CancellationToken cancellationToken=default)
 Sends JSON string to device and reads response. More...
 
async Task< byte[]> SendAsync (byte[] data, int retries=2, int nullRetries=1, int? overrideRecvTimeout=null, CancellationToken cancellationToken=default)
 Sends raw data over to device and read response. More...
 
async Task< Dictionary< int, object > > GetDpsAsync (int retries=5, int nullRetries=1, int? overrideRecvTimeout=null, CancellationToken cancellationToken=default)
 Requests current DPs status. More...
 
async Task< Dictionary< int, object > > SetDpAsync (int dp, object value, int retries=2, int nullRetries=1, int? overrideRecvTimeout=null, bool allowEmptyResponse=false, CancellationToken cancellationToken=default)
 Sets single DP to specified value. More...
 
async Task< Dictionary< int, object > > SetDpsAsync (Dictionary< int, object > dps, int retries=2, int nullRetries=1, int? overrideRecvTimeout=null, bool allowEmptyResponse=false, CancellationToken cancellationToken=default)
 Sets DPs to specified value. More...
 
async Task< Dictionary< int, object > > UpdateDpsAsync (IEnumerable< int > dpIds, int retries=5, int nullRetries=1, int? overrideRecvTimeout=null, CancellationToken cancellationToken=default)
 Update DP values. More...
 
async Task RefreshLocalKeyAsync (bool forceTokenRefresh=false, CancellationToken cancellationToken=default)
 Get current local key from Tuya Cloud API More...
 
void Dispose ()
 Disposes object. More...
 

Static Public Member Functions

static ushort[] Base64ToPulses (string codeBase64)
 Converts Base64 encoded button code into pulses duration. More...
 
static string PulsesToBase64 (ushort[] pulses)
 Converts pulses duration into Base64 encoded button code. More...
 
static ushort[] HexToPulses (string codeHex)
 Converts hex encoded button code into pulses duration. More...
 
static string PulsesToHex (ushort[] pulses)
 Converts pulses duration into hex encoded button code. More...
 

Additional Inherited Members

- Properties inherited from com.clusterrr.TuyaNet.TuyaDevice
string IP [get]
 IP address of device. More...
 
string LocalKey [get, set]
 Local key of device. More...
 
string DeviceId [get]
 Device ID. More...
 
int Port = 6668 [get]
 TCP port of device. More...
 
TuyaProtocolVersion ProtocolVersion [get, set]
 Protocol version. More...
 
int ConnectionTimeout = 500 [get, set]
 Connection timeout. More...
 
int ReceiveTimeout [get, set]
 Receive timeout. More...
 
int NetworkErrorRetriesInterval = 100 [get, set]
 Network error retry interval (msec) More...
 
int NullRetriesInterval = 0 [get, set]
 Empty responce retry interval (msec) More...
 
bool PermanentConnection = false [get, set]
 Permanent connection (connect and stay connected). More...
 

Detailed Description

Tuya virtual IR remote control

Constructor & Destructor Documentation

◆ TuyaIRControl() [1/2]

com.clusterrr.TuyaNet.TuyaIRControl.TuyaIRControl ( string  ip,
string  localKey,
string  deviceId,
TuyaProtocolVersion  protocolVersion = TuyaProtocolVersion.V33,
int  port = 6668,
int  receiveTimeout = 250 
)
inline

Creates a new instance of the TuyaDevice class.

Parameters
ipIP address of device.
localKeyLocal key of device (obtained via API).
deviceIdDevice ID.
protocolVersionProtocol version.
portTCP port of device.
receiveTimeoutReceive timeout (msec).

◆ TuyaIRControl() [2/2]

com.clusterrr.TuyaNet.TuyaIRControl.TuyaIRControl ( string  ip,
TuyaApi.Region  region,
string  accessId,
string  apiSecret,
string  deviceId,
TuyaProtocolVersion  protocolVersion = TuyaProtocolVersion.V33,
int  port = 6668,
int  receiveTimeout = 250 
)
inline

Creates a new instance of the TuyaDevice class.

Parameters
ipIP address of device.
regionRegion to access Cloud API.
accessIdAccess ID to access Cloud API.
apiSecretAPI secret to access Cloud API.
deviceIdDevice ID.
protocolVersionProtocol version.
portTCP port of device.
receiveTimeoutReceive timeout (msec).


Member Function Documentation

◆ GetButtonCodeAsync()

async Task<string> com.clusterrr.TuyaNet.TuyaIRControl.GetButtonCodeAsync ( int  timeout,
int  retries = 2,
CancellationToken  cancellationToken = default 
)
inline

Learns button code of remote control.

Parameters
timeoutLearing timeout, you should press RC button during this interval.
cancellationTokenCancellation token.
Returns
Button code as Base64 string.
Here is the call graph for this function:

◆ SendButtonCodeAsync()

async Task com.clusterrr.TuyaNet.TuyaIRControl.SendButtonCodeAsync ( string  buttonCode,
int  retries = 2,
int?  overrideRecvTimeout = null,
CancellationToken  cancellationToken = default 
)
inline

Sends button code.

Parameters
buttonCodeButton code in Base64 encoding.
cancellationTokenCancellation token.
Here is the call graph for this function:

◆ Base64ToPulses()

static ushort [] com.clusterrr.TuyaNet.TuyaIRControl.Base64ToPulses ( string  codeBase64)
inlinestatic

Converts Base64 encoded button code into pulses duration.

Parameters
codeBase64Base64 encoded button code.
Returns
Pulses/gaps length in microsecods.

◆ PulsesToBase64()

static string com.clusterrr.TuyaNet.TuyaIRControl.PulsesToBase64 ( ushort[]  pulses)
inlinestatic

Converts pulses duration into Base64 encoded button code.

Parameters
pulsesPulses/gaps length in microsecods.
Returns
Base64 encoded button code.

◆ HexToPulses()

static ushort [] com.clusterrr.TuyaNet.TuyaIRControl.HexToPulses ( string  codeHex)
inlinestatic

Converts hex encoded button code into pulses duration.

Parameters
codeHexHex encoded button code.
Returns
Pulses/gaps length in microsecods.

◆ PulsesToHex()

static string com.clusterrr.TuyaNet.TuyaIRControl.PulsesToHex ( ushort[]  pulses)
inlinestatic

Converts pulses duration into hex encoded button code.

Parameters
pulsesPulses/gaps length in microsecods.
Returns
Hex encoded button code.