use std::collections::HashMap; use crate::command::CommandRequest; pub mod e1; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum AttributeValue { String(Option), Bool(bool), Int(u8), } impl AttributeValue { pub fn set(&mut self, value: impl Into) { match (self, value.into()) { (Self::String(current), Self::String(new)) => *current = new, (Self::String(current), Self::Bool(new)) => *current = Some(new.to_string()), (Self::String(current), Self::Int(new)) => *current = Some(new.to_string()), (Self::Bool(current), Self::Bool(new)) => *current = new, (Self::Int(current), Self::Int(new)) => *current = new, _ => panic!(), } } pub fn str(&self) -> Option<&str> { match self { Self::String(opt) => opt.as_ref().map(|s| s.as_str()), _ => panic!(), } } pub fn bool(&self) -> bool { match self { Self::Bool(bool) => *bool, _ => panic!(), } } pub fn byte(&self) -> u8 { match self { Self::Int(b) => *b, _ => panic!(), } } } impl From for AttributeValue { fn from(value: String) -> Self { Self::String(Some(value)) } } impl From> for AttributeValue { fn from(value: Option) -> Self { Self::String(value) } } impl From for AttributeValue { fn from(value: bool) -> Self { Self::Bool(value) } } impl From for AttributeValue { fn from(value: u8) -> Self { Self::Int(value) } } pub trait DeviceBackend { fn build_query(&self) -> CommandRequest; fn process_message(&mut self, msg: &[u8]); fn attributes(&self) -> &HashMap<&'static str, AttributeValue>; fn set_attribute(&self, attribute: &str, value: &str) -> (); }