Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ impl SmartPlug {

// Wakes up the device
pub fn on(&self) -> Result<PlugInfo, Error> {
let json = "{\"system\":{\"set_relay_state\":{\"state\":1}}}";
let json = "{\"system\":{\"set_relay_state\":{\"state\":1},\"get_sysinfo\":{}}}";
self.submit_to_device(json)
}

// Turns off the device
pub fn off(&self) -> Result<PlugInfo, Error> {
let json = "{\"system\":{\"set_relay_state\":{\"state\":0}}}";
let json = "{\"system\":{\"set_relay_state\":{\"state\":0},\"get_sysinfo\":{}}}";
self.submit_to_device(json)
}

Expand Down Expand Up @@ -127,14 +127,29 @@ fn send(ip: &str, payload: &[u8]) -> Result<Vec<u8>, Error> {
mod tests {
use encrypt;
use decrypt;
use SmartPlug;

#[test]
fn encrypt_decrypt() {
let json = "{\"system\":{\"get_sysinfo\":{}}}";

let mut data = encrypt(json);
let mut data = encrypt(json).unwrap();
let resp = decrypt(&mut data.split_off(4));

assert_eq!(json, resp);
}

#[test]
fn can_turn_on() {
let plug = SmartPlug::new("192.168.1.32:9999");

plug.on().unwrap();
}

#[test]
fn can_turn_off() {
let plug = SmartPlug::new("192.168.1.32:9999");

plug.off().unwrap();
}
}