Expand description
§Rust Tuyapi
This library can be used to interact with Tuya/Smart Home devices. It utilizes the Tuya protocol version 3.1 and 3.3 to send and receive messages from the devices.
§Example
This shows how to turn on a wall socket.
// The dps value is device specific, this socket turns on with key "1"
let mut dps = HashMap::new();
dps.insert("1".to_string(), json!(true));
let current_time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as u32;
// Create the payload to be sent, this will be serialized to the JSON format
let payload = Payload::Struct(PayloadStruct{
dev_id: "123456789abcdef".to_string(),
gw_id: Some("123456789abcdef".to_string()),
uid: None,
t: Some(current_time),
dp_id: None,
dps: Some(dps),
});
// Create a TuyaDevice, this is the type used to set/get status to/from a Tuya compatible
// device.
let tuya_device = TuyaDevice::create("ver3.3", Some("fedcba987654321"),
IpAddr::from_str("192.168.0.123").unwrap())?;
// Set the payload state on the Tuya device, an error here will contain
// the error message received from the device.
tuya_device.set(payload, 0)?;
Re-exports§
pub use transports::Transport;
pub use tuyadevice::TuyaDevice;
Modules§
- Message Parser
- TuyaTransports
- TuyaDevice
Structs§
- The PayloadStruct is Serialized to json and sent to the device. The dps field contains the actual commands to set and are device specific.
Enums§
- The Payload enum represents a payload sent to, and recevied from the Tuya devices. It might be a struct (ser/de from json) or a plain string.
Traits§
- This trait is implemented to allow truncated logging of secret data.