A simple library to control TP-Link Smart Home devices.
Discover existing TP-Link devices on your network.
use tplink::DeviceKind;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let devices = tplink::discover()?;
for (ip, device) in devices {
match device {
DeviceKind::Plug(mut plug) => {
plug.turn_off()?;
assert_eq!(plug.is_on()?, false);
}
DeviceKind::Bulb(mut bulb) => {
bulb.set_brightness(50)?;
assert_eq!(bulb.brightness()?, 50);
}
_ => eprintln!("unrecognised device found on the network: {}", ip),
}
}
Ok(())
}
More examples can be found here.
Device | Model |
---|---|
Plug | HS100 |
Bulb | LB100, LB110 |
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.