Skip to main content

wiz_lights_rs/
lib.rs

1//! # wiz_lights_rs
2//!
3//! An async Rust library for controlling Philips Wiz smart lights over UDP.
4//!
5//! This crate provides a **runtime-agnostic** async API to communicate with Wiz smart bulbs
6//! on your local network. It supports setting colors, brightness, color temperature,
7//! scenes, and power states.
8//!
9//! ## Quick Start
10//!
11//! ```ignore
12//! use std::net::Ipv4Addr;
13//! use std::str::FromStr;
14//! use wiz_lights_rs::{Light, Payload, Color};
15//!
16//! // Works with any async runtime!
17//! async fn control_light() -> Result<(), Box<dyn std::error::Error>> {
18//!     // Create a light instance with the bulb's IP address
19//!     let light = Light::new(Ipv4Addr::from_str("192.168.1.100")?, Some("Living Room"));
20//!
21//!     // Set the light to blue
22//!     let mut payload = Payload::new();
23//!     payload.color(&Color::from_str("0,0,255")?);
24//!     light.set(&payload).await?;
25//!     Ok(())
26//! }
27//! ```
28//!
29//! ## Features
30//!
31//! - **Runtime Agnostic**: Works with tokio, async-std, or smol async runtimes
32//! - **RGB Colors**: Set any RGB color using the [`Color`] type
33//! - **Brightness**: Control brightness from 10-100% using [`Brightness`]
34//! - **Color Temperature**: Set warm to cool white (1000K-8000K) using [`Kelvin`]
35//! - **Scenes**: Use preset lighting scenes with [`SceneMode`]
36//! - **Power Control**: Turn lights on/off or reboot with [`PowerMode`]
37//! - **Room Grouping**: Organize lights into [`Room`]s for batch operations
38//! - **Discovery**: Find bulbs on your network with [`discover_bulbs`]
39//! - **Hue/Saturation**: Alternative color mode with [`HueSaturation`]
40//! - **Push Notifications**: Real-time state updates via [`push::PushManager`]
41//!
42//! ## Communication
43//!
44//! All communication with Wiz bulbs occurs over UDP on port 38899. The bulbs must
45//! be on the same local network and ideally have static IP addresses assigned.
46//!
47//! ## Runtime Selection
48//!
49//! This library is runtime-agnostic. Select your preferred runtime using feature flags:
50//!
51//! ### Using tokio (default)
52//!
53//! ```toml
54//! [dependencies]
55//! wiz-lights-rs = "0.1"
56//! tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
57//! ```
58//!
59//! ### Using async-std
60//!
61//! ```toml
62//! [dependencies]
63//! wiz-lights-rs = { version = "0.1", default-features = false, features = ["runtime-async-std"] }
64//! async-std = { version = "1.12", features = ["attributes"] }
65//! ```
66//!
67//! ### Using smol
68//!
69//! ```toml
70//! [dependencies]
71//! wiz-lights-rs = { version = "0.1", default-features = false, features = ["runtime-smol"] }
72//! smol = "2"
73//! ```
74//!
75//! ## Feature Flags
76//!
77//! - `runtime-tokio` (default): Use the tokio async runtime
78//! - `runtime-async-std`: Use the async-std runtime
79//! - `runtime-smol`: Use the smol runtime
80
81mod config;
82mod discovery;
83mod errors;
84mod history;
85mod light;
86mod payload;
87pub mod push;
88mod response;
89mod room;
90pub mod runtime;
91mod status;
92mod types;
93
94// Re-export public API
95pub use config::{
96    BulbClass, BulbType, ExtendedWhiteRange, Features, KelvinRange, SystemConfig, WhiteRange,
97};
98pub use discovery::{DiscoveredBulb, discover_bulbs};
99pub use errors::Error;
100pub use history::{HistoryEntry, HistorySummary, MessageHistory, MessageType};
101pub use light::Light;
102pub use payload::Payload;
103pub use response::LightingResponse;
104pub use room::Room;
105pub use status::{LastSet, LightStatus};
106pub use types::{
107    Brightness, Color, ColorRGBW, ColorRGBWW, FanDirection, FanMode, FanSpeed, FanState,
108    HueSaturation, Kelvin, PowerMode, Ratio, SceneMode, Speed, White,
109};