tplinker/
lib.rs

1//! A library to query and control `TPLink` smart devices on the local network.
2//!
3//! Supported devices include HS100, HS110, LB110, LB120, KL110.
4//!
5//! Inspired and influenced by [`pyHS100`](https://github.com/GadgetReactor/pyHS100) and
6//! [hs100api](https://github.com/abronan/hs100-rust-api).
7//!
8//! # Usage
9//!
10//! There are two main entrypoints. If you know the IP address and device type you can
11//! instantiate directly. Alternatively you can discover devices on the local network.
12//!
13//! In order to do things with devices you must bring in the capabiliy traits from
14//! [`capabilities`](./capabilities/index.html).
15//!
16//! ## Discovery
17//!
18//! To see all `TPLink` smart devices on the local network use
19//! [`discovery::discover`](./discovery/fn.discover.html).
20//!
21//! ```no_run
22//! use tplinker::{
23//!   discovery::discover,
24//!   devices::Device,
25//!   capabilities::Switch,
26//! };
27//!
28//! for (addr, data) in discover().unwrap() {
29//!   let device = Device::from_data(addr, &data);
30//!   let sysinfo = data.sysinfo();
31//!   println!("{}\t{}\t{}", addr, sysinfo.alias, sysinfo.hw_type);
32//!   match device {
33//!     Device::HS110(device) => { device.switch_on().unwrap(); },
34//!     _ => {},
35//!   }
36//! }
37//! ```
38//!
39//! ## Direct device
40//!
41//! To connect to a specific TPLink device use the specific device struct from
42//! [`devices`](./devices/index.html).
43//!
44//! ```no_run
45//! use tplinker::{
46//!   devices::LB110,
47//!   capabilities::{Switch, Dimmer},
48//! };
49//!
50//! let device = LB110::new("192.168.0.99:9999").unwrap();
51//! if device.is_on().unwrap() {
52//!   let brightness = device.brightness().unwrap();
53//!   if brightness < 50 {
54//!     device.set_brightness(brightness + 20).unwrap();
55//!   }
56//! }
57//! ```
58//!
59//! ## Capabilities
60//!
61//! In order to do things with devices you must bring in the relevant capability
62//! traits from [`capabilities`](./capabilities/index.html).
63
64#![deny(missing_docs)]
65
66extern crate byteorder;
67
68#[macro_use]
69extern crate serde_derive;
70
71pub mod capabilities;
72pub mod datatypes;
73pub mod devices;
74pub mod discovery;
75pub mod error;
76mod protocol;
77
78pub use discovery::discover;