Skip to main content

Crate rustuya

Crate rustuya 

Source
Expand description

§Rustuya

Asynchronous Tuya Local API implementation for local control and monitoring of Tuya-compatible devices without cloud dependencies.

§Quick Start

use rustuya::sync::Device;

let device = Device::new("DEVICE_ID", "DEVICE_KEY");
device.set_value(1, true);

§Choosing sync vs async

Rustuya ships two parallel facades over the same internal actor:

When you’re calling from…Use
A non-async program (CLI, sync binary, scripting helpers)sync::Device, sync::SubDevice, sync::Scanner
Inside a tokio runtime (#[tokio::main], tokio::spawn, axum, etc.)Device, DeviceBuilder, Scanner (async)

Both flavours share state and reach the same backing tokio runtime — the sync wrappers are just bridges. Calling the sync API from inside a tokio runtime is not a supported configuration: the wrappers use blocking_send, which would otherwise panic. Since v0.3.0 a runtime guard turns that into a clear error, but you should pick the right facade up front rather than relying on the guard.

See the sync module docs for the full caveat.

§Lifecycle

Device::new (and its sync mirror) spawn a background connection task immediately on the library’s internal runtime. The task stays alive until the last Device clone is dropped or Device::stop is called. Constructing many thousands of devices upfront is therefore avoidable — prefer lazy construction in those scenarios.

Re-exports§

pub use device::Device;
pub use device::DeviceBuilder;
pub use error::TuyaError;
pub use protocol::CommandType;
pub use protocol::Version;
pub use scanner::Scanner;

Modules§

crypto
Cryptographic operations for the Tuya protocol.
device
Tuya device communication and state management.
error
Error types and result definitions for the Tuya protocol.
protocol
Tuya wire protocol implementation.
scanner
UDP-based device discovery and scanning.
sync
Synchronous API wrappers for Tuya device communication.

Constants§

VERSION

Functions§

connect_concurrency
Returns the configured connect-concurrency cap, or 0 if unset (unbounded).
install_panic_logging
Installs a process-global panic hook that logs every panic’s thread, location (file:line:col), message, and a backtrace via the log facade (so it reaches pyo3-log / a consumer subscriber) before the default hook runs. Opt-in and idempotent; the previous hook is chained, not replaced.
maximize_fd_limit
Maximizes the file descriptor limit (Unix-like system only).
set_connect_concurrency
Sets the global cap on concurrent connection establishment, opting in to the connect-storm guard.
version