rustuya 0.1.0

A Rust implementation of the Tuya Local API.
Documentation
rustuya-0.1.0 has been yanked.

Rustuya

Crates.io Documentation License: MIT

Rustuya is an asynchronous Rust implementation of the Tuya Local API. It allows for local control and monitoring of Tuya-compatible devices without cloud dependencies.

[!WARNING]
This project is in an early development stage (v0.1.0). APIs are subject to change.

Installation

Add rustuya to Cargo.toml:

cargo add rustuya tokio --features tokio/full

Quick Start

Basic Device Control

use rustuya::Device;
use serde_json::json;

#[tokio::main]
async fn main() {
    // Address and version can be "Auto" for automatic discovery
    let device = Device::new("DEVICE_ID", "DEVICE_ADDRESS", "DEVICE_KEY", "DEVICE_VERSION");

    // Switch ON (DP 1 is usually power)
    let _ = device.set_value(1, json!(true)).await;
}

Real-time Status Monitoring

use rustuya::Device;
use tokio_stream::StreamExt;

#[tokio::main]
async fn main() {
    let device = Device::new("DEVICE_ID", "DEVICE_ADDRESS", "DEVICE_KEY", "DEVICE_VERSION");
    let mut stream = device.stream();

    while let Some(message) = stream.next().await {
        println!("Received: {:?}", message);
    }
}

Credits

This project references the communication protocols and cipher implementations from the tinytuya Python library.

License

MIT