Tuya.Net
|
Connection with Tuya device. More...
Public Member Functions | |
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< TuyaLocalResponse > | SendAsync (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... | |
Properties | |
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... | |
Connection with Tuya device.
|
inline |
Creates a new instance of the TuyaDevice class.
ip | IP address of device. |
localKey | Local key of device (obtained via API). |
deviceId | Device ID. |
protocolVersion | Protocol version. |
port | TCP port of device. |
receiveTimeout | Receive timeout (msec). |
|
inline |
Creates a new instance of the TuyaDevice class.
ip | IP address of device. |
region | Region to access Cloud API. |
accessId | Access ID to access Cloud API. |
apiSecret | API secret to access Cloud API. |
deviceId | Device ID. |
protocolVersion | Protocol version. |
port | TCP port of device. |
receiveTimeout | Receive timeout (msec). |
|
inline |
Fills JSON string with base fields required by most commands.
json | JSON string |
addGwId | Add "gwId" field with device ID. |
addDevId | Add "devId" field with device ID. |
addUid | Add "uid" field with device ID. |
addTime | Add "time" field with current timestamp. |
|
inline |
Creates encoded and encrypted payload data from JSON string.
command | Tuya command ID. |
json | String with JSON to send. |
|
inline |
Parses and decrypts payload data from received bytes.
data | Raw data to parse and decrypt. |
async Task<TuyaLocalResponse> com.clusterrr.TuyaNet.TuyaDevice.SendAsync | ( | TuyaCommand | command, |
string | json, | ||
int | retries = 2 , |
||
int | nullRetries = 1 , |
||
int? | overrideRecvTimeout = null , |
||
CancellationToken | cancellationToken = default |
||
) |
Sends JSON string to device and reads response.
command | Tuya command ID. |
json | JSON string. |
retries | Number of retries in case of network error (default - 2). |
nullRetries | Number of retries in case of empty answer (default - 1). |
overrideRecvTimeout | Override receive timeout (default - ReceiveTimeout property). |
cancellationToken | Cancellation token. |
|
inline |
Sends raw data over to device and read response.
data | Raw data to send. |
retries | Number of retries in case of network error (default - 2). |
nullRetries | Number of retries in case of empty answer (default - 1). |
overrideRecvTimeout | Override receive timeout (default - ReceiveTimeout property). |
cancellationToken | Cancellation token. |
|
inline |
Requests current DPs status.
retries | Number of retries in case of network error (default - 2). |
nullRetries | Number of retries in case of empty answer (default - 1). |
overrideRecvTimeout | Override receive timeout (default - ReceiveTimeout property). |
cancellationToken | Cancellation token. |
async Task<Dictionary<int, object> > com.clusterrr.TuyaNet.TuyaDevice.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.
dp | DP number. |
value | Value. |
retries | Number of retries in case of network error (default - 2). |
nullRetries | Number of retries in case of empty answer (default - 1). |
overrideRecvTimeout | Override receive timeout (default - ReceiveTimeout property). |
allowEmptyResponse | Do not throw exception on empty Response |
cancellationToken | Cancellation token. |
|
inline |
Sets DPs to specified value.
dps | Dictionary of DP numbers and values to set. |
retries | Number of retries in case of network error (default - 2). |
nullRetries | Number of retries in case of empty answer (default - 1). |
overrideRecvTimeout | Override receive timeout (default - ReceiveTimeout property). |
allowEmptyResponse | Do not throw exception on empty Response |
cancellationToken | Cancellation token. |
|
inline |
Update DP values.
dpIds | DP identificators to update (can be empty for some devices). |
retries | Number of retries in case of network error (default - 2). |
nullRetries | Number of retries in case of empty answer (default - 1). |
overrideRecvTimeout | Override receive timeout (default - ReceiveTimeout property). |
cancellationToken | Cancellation token. |
|
inline |
Get current local key from Tuya Cloud API
forceTokenRefresh | Refresh access token even it's not expired. |
cancellationToken | Cancellation token. |
|
inline |
Disposes object.
|
get |
IP address of device.
|
getset |
Local key of device.
|
get |
Device ID.
|
get |
TCP port of device.
|
getset |
Protocol version.
|
getset |
Connection timeout.
|
getset |
Receive timeout.
|
getset |
Network error retry interval (msec)
|
getset |
Empty responce retry interval (msec)
|
getset |
Permanent connection (connect and stay connected).