use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter, Result};

#[derive(Serialize, Deserialize, Debug)]
pub struct OneWire {
    // Allowed Values: sensor, temp, 1wdevice
    pub dev: String,
    pub circuit: String,
    pub address: String,
    pub value: Option<f32>,
    // minimum: 0, maximum: 100
    pub humidity: Option<u8>,
    pub vdd: Option<i32>,
    pub vad: Option<i32>,
    pub vis: Option<i32>,
    pub temp: Option<f32>,
    pub lost: Option<bool>,
    pub time: Option<f32>,
    pub interval: Option<f32>,
    pub typ: String,
}

impl Display for OneWire {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "{}", serde_json::to_string(&self).unwrap())
    }
}
