use cmds::{CommandClass, Message};
use error::{Error, ErrorKind};
#[derive(Debug, Clone)]
pub struct SwitchBinary;
impl SwitchBinary {
pub fn set<N, V>(node_id: N, value: V) -> Message
where N: Into<u8>, V: Into<bool> {
let value = if value.into() {0xFF} else {0x00};
Message::new(node_id.into(), CommandClass::SWITCH_BINARY, 0x01, vec!(value))
}
pub fn get<N>(node_id: N) -> Message
where N: Into<u8> {
Message::new(node_id.into(), CommandClass::SWITCH_BINARY, 0x02, vec!())
}
pub fn report<M>(msg: M) -> Result<bool, Error>
where M: Into<Vec<u8>> {
let msg = msg.into();
if msg.len() != 6 {
return Err(Error::new(ErrorKind::UnknownZWave, "Message is to short"));
}
if msg[3] != CommandClass::SWITCH_BINARY as u8 || msg[4] != 0x03 {
return Err(Error::new(ErrorKind::UnknownZWave, "Answer contained wrong command class"));
}
let val = if msg[5] < 0xFF {false} else {true};
Ok(val)
}
}