From 5c24841c8edb690dcc6bb50439baea5e62e4b8ac Mon Sep 17 00:00:00 2001 From: Andy Lowry Date: Tue, 25 Jul 2017 14:50:23 +0100 Subject: [PATCH] Fix for on and off commands --- src/lib.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a50004f..1dc1fbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,13 +26,13 @@ impl SmartPlug { // Wakes up the device pub fn on(&self) -> Result { - 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 { - let json = "{\"system\":{\"set_relay_state\":{\"state\":0}}}"; + let json = "{\"system\":{\"set_relay_state\":{\"state\":0},\"get_sysinfo\":{}}}"; self.submit_to_device(json) } @@ -127,14 +127,29 @@ fn send(ip: &str, payload: &[u8]) -> Result, 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(); + } }