rustuya 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,61 @@
1
+ [package]
2
+ name = "rustuya"
3
+ version = "0.1.0"
4
+ authors = ["3735943886"]
5
+ edition = "2024"
6
+ license = "MIT"
7
+ repository = "https://github.com/3735943886/rustuya"
8
+ documentation = "https://docs.rs/rustuya"
9
+ homepage = "https://github.com/3735943886/rustuya"
10
+ description = "A fast and concurrent Tuya Local API implementation in Rust"
11
+ keywords = ["tuya", "iot", "smart-home", "automation"]
12
+ categories = ["hardware-support", "network-programming", "api-bindings"]
13
+ include = [
14
+ "src/**/*",
15
+ "examples/*.rs",
16
+ "!examples/z_*.rs",
17
+ "Cargo.toml",
18
+ "README.md",
19
+ "LICENSE"
20
+ ]
21
+ readme = "README.md"
22
+
23
+ [lib]
24
+ name = "rustuya"
25
+ crate-type = ["rlib"]
26
+
27
+ [dependencies]
28
+ serde = { version = "1.0", features = ["derive"] }
29
+ serde_json = "1.0"
30
+ aes = "0.8"
31
+ aes-gcm = "0.10"
32
+ hmac = "0.12"
33
+ sha2 = "0.10"
34
+ crc = "3.0"
35
+ rand = "0.9"
36
+ hex = "0.4"
37
+ base64 = "0.22"
38
+ md-5 = "0.10"
39
+ thiserror = "2.0"
40
+ log = "0.4"
41
+ env_logger = "0.11"
42
+ byteorder = "1.5"
43
+ cipher = { version = "0.4", features = ["block-padding"] }
44
+ block-padding = "0.3"
45
+ ecb = "0.1"
46
+ tokio = { version = "1.0", features = ["rt-multi-thread", "net", "sync", "time", "macros", "io-util"] }
47
+ socket2 = { version = "0.5", features = ["all"] }
48
+ async-stream = "0.3"
49
+ tokio-stream = { version = "0.1", features = ["sync"] }
50
+ tokio-util = { version = "0.7", features = ["rt"] }
51
+ futures-core = "0.3"
52
+ futures-util = "0.3"
53
+ rlimit = "0.10"
54
+ parking_lot = "0.12"
55
+
56
+ [profile.release]
57
+ opt-level = 3
58
+ lto = true
59
+ codegen-units = 1
60
+ panic = "abort"
61
+ strip = true
rustuya-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 3735943886
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
rustuya-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: rustuya
3
+ Version: 0.1.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Programming Language :: Rust
8
+ Classifier: Programming Language :: Python :: 3
9
+ Summary: A fast and concurrent Tuya Local API implementation in Rust
10
+ Keywords: tuya,iot,smart-home,automation
11
+ Home-Page: https://github.com/3735943886/rustuya
12
+ Author: 3735943886
13
+ License: MIT
14
+ Requires-Python: >=3.7
15
+ Project-URL: Homepage, https://github.com/3735943886/rustuya
16
+ Project-URL: Repository, https://github.com/3735943886/rustuya
@@ -0,0 +1,58 @@
1
+ # Rustuya
2
+
3
+ [![Crates.io](https://img.shields.io/crates/v/rustuya.svg)](https://crates.io/crates/rustuya)
4
+ [![Documentation](https://docs.rs/rustuya/badge.svg)](https://docs.rs/rustuya)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ **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.
8
+
9
+ > [!WARNING]
10
+ > This project is in an **early development stage (v0.1.0)**. APIs are subject to change.
11
+
12
+
13
+ ## Installation
14
+
15
+ Add `rustuya` to `Cargo.toml`:
16
+
17
+ ```bash
18
+ cargo add rustuya tokio --features tokio/full
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### Basic Device Control
24
+
25
+ ```rust
26
+ use rustuya::sync::Device;
27
+ use serde_json::json;
28
+
29
+ fn main() {
30
+ let device = Device::new("DEVICE_ID", "DEVICE_ADDRESS", "DEVICE_KEY", "DEVICE_VERSION");
31
+
32
+ device.set_value(1, json!(true));
33
+ }
34
+ ```
35
+
36
+ ### Real-time Status Monitoring
37
+
38
+ ```rust
39
+ use rustuya::sync::Device;
40
+
41
+ fn main() {
42
+ let device = Device::new("DEVICE_ID", "DEVICE_ADDRESS", "DEVICE_KEY", "DEVICE_VERSION");
43
+ let receiver = device.listener();
44
+
45
+ println!("Listening for messages...");
46
+ for message in receiver {
47
+ println!("Received: {:?}", message);
48
+ }
49
+ }
50
+ ```
51
+
52
+ ## Credits
53
+
54
+ This project references the communication protocols and cipher implementations from the [tinytuya](https://github.com/jasonacox/tinytuya) Python library.
55
+
56
+ ## License
57
+
58
+ MIT
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Scanner Example (Async)
3
+ *
4
+ * This example demonstrates how to use the asynchronous UDP scanner to find
5
+ * Tuya devices on the local network and detect their protocol versions.
6
+ *
7
+ * Author: 3735943886
8
+ */
9
+ use rustuya::Scanner;
10
+ use std::time::Duration;
11
+
12
+ #[tokio::main]
13
+ async fn main() {
14
+ // Initialize logger to see discovery details
15
+ env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
16
+
17
+ println!("--- Rustuya - Scanner Async ---");
18
+ println!("Scanning the network for Tuya devices (18s)...");
19
+
20
+ // 1. Create a new scanner with a timeout of 18 seconds
21
+ let scanner = Scanner::new().with_timeout(Duration::from_secs(18));
22
+
23
+ // 2. Perform the scan
24
+ match scanner.scan().await {
25
+ Ok(devices) => {
26
+ let count = devices.len();
27
+ for dev in devices {
28
+ println!("-------------------------------------------");
29
+ // Mandatory fields
30
+ println!("ID: {}", dev.id);
31
+ println!("IP: {}", dev.ip);
32
+
33
+ // Optional: Version
34
+ if let Some(v) = dev.version {
35
+ println!("Version: {}", v);
36
+ } else {
37
+ println!("Version: Unknown");
38
+ }
39
+
40
+ // Optional: Product Key
41
+ if let Some(pk) = dev.product_key {
42
+ println!("Product: {}", pk);
43
+ }
44
+ }
45
+ println!("-------------------------------------------");
46
+ println!("\nTotal: {} devices found.", count);
47
+ }
48
+ Err(e) => {
49
+ eprintln!("Scan failed: {}", e);
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Scanner Example (Sync)
3
+ *
4
+ * This example demonstrates how to use the synchronous UDP scanner to find
5
+ * Tuya devices on the local network and detect their protocol versions.
6
+ *
7
+ * Author: 3735943886
8
+ */
9
+ use rustuya::sync::Scanner;
10
+ use std::time::Duration;
11
+
12
+ fn main() {
13
+ // Initialize logger to see discovery details
14
+ env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
15
+
16
+ println!("--- Rustuya - Scanner Sync ---");
17
+ println!("Scanning the network for Tuya devices (18s)...");
18
+
19
+ // 1. Create a new scanner with a timeout of 18 seconds
20
+ let scanner = Scanner::new().with_timeout(Duration::from_secs(18));
21
+
22
+ // 2. Perform the scan (Blocking)
23
+ match scanner.scan() {
24
+ Ok(devices) => {
25
+ let count = devices.len();
26
+ for dev in devices {
27
+ println!("-------------------------------------------");
28
+ // Mandatory fields
29
+ println!("ID: {}", dev.id);
30
+ println!("IP: {}", dev.ip);
31
+
32
+ // Optional: Version
33
+ if let Some(v) = dev.version {
34
+ println!("Version: {}", v);
35
+ } else {
36
+ println!("Version: Unknown");
37
+ }
38
+
39
+ // Optional: Product Key
40
+ if let Some(pk) = dev.product_key {
41
+ println!("Product: {}", pk);
42
+ }
43
+ }
44
+ println!("-------------------------------------------");
45
+ println!("\nTotal: {} devices found.", count);
46
+ }
47
+ Err(e) => {
48
+ eprintln!("Scan failed: {}", e);
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.0,<2.0"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "rustuya"
7
+ version = "0.1.0"
8
+ description = "A fast and concurrent Tuya Local API implementation in Rust"
9
+ authors = [
10
+ { name = "3735943886" }
11
+ ]
12
+ requires-python = ">=3.7"
13
+ license = { text = "MIT" }
14
+ keywords = ["tuya", "iot", "smart-home", "automation"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Rust",
20
+ "Programming Language :: Python :: 3",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/3735943886/rustuya"
25
+ Repository = "https://github.com/3735943886/rustuya"
26
+
27
+ [tool.maturin]
28
+ features = ["pyo3/extension-module"]
29
+ module-name = "rustuya"
30
+ manifest-path = "python/Cargo.toml"