allow passing trough mh-z19 co2 readings

This commit is contained in:
Robin Appelman 2020-12-14 22:32:35 +01:00
commit 5aa9718e30

View file

@ -23,6 +23,7 @@ pub struct DeviceState {
pub power_watts: Option<f32>, pub power_watts: Option<f32>,
pub power_yesterday: Option<f32>, pub power_yesterday: Option<f32>,
pub power_today: Option<f32>, pub power_today: Option<f32>,
pub co2: Option<f32>,
pub mi_temp_devices: BTreeMap<BDAddr, MiTempState>, pub mi_temp_devices: BTreeMap<BDAddr, MiTempState>,
} }
@ -52,6 +53,12 @@ impl DeviceState {
{ {
self.power_today = Some(today); self.power_today = Some(today);
} }
if let Some(today) = json["MHZ19B"]["CarbonDioxide"]
.as_number()
.and_then(|num| f32::try_from(num).ok())
{
self.co2 = Some(today);
}
for (key, value) in json.entries() { for (key, value) in json.entries() {
if let Some(addr) = key.strip_prefix("MJ_HT_V1-") { if let Some(addr) = key.strip_prefix("MJ_HT_V1-") {
@ -144,6 +151,14 @@ pub fn format_device_state<W: Write>(
)?; )?;
} }
if let Some(co2) = state.co2 {
writeln!(
writer,
"sensor_co2{{tasmota_id=\"{}\", name=\"{}\"}} {}",
device.hostname, state.name, co2
)?;
}
for (addr, state) in state.mi_temp_devices.iter() { for (addr, state) in state.mi_temp_devices.iter() {
format_mi_temp_state(&mut writer, *addr, mi_temp_names, state)?; format_mi_temp_state(&mut writer, *addr, mi_temp_names, state)?;
} }