mirror of
https://codeberg.org/icewind/taspromto.git
synced 2026-08-02 12:14:45 +02:00
store rf/mitemp names with device state
This commit is contained in:
parent
2936b3cf22
commit
7335d35c68
3 changed files with 72 additions and 30 deletions
|
|
@ -8,7 +8,9 @@ use std::{
|
|||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MiTempState {
|
||||
pub struct MiTempDevice {
|
||||
pub name: String,
|
||||
pub addr: BDAddr,
|
||||
temperature: f32,
|
||||
humidity: f32,
|
||||
dew_point: f32,
|
||||
|
|
@ -16,9 +18,11 @@ pub struct MiTempState {
|
|||
pub last_seen: Instant,
|
||||
}
|
||||
|
||||
impl Default for MiTempState {
|
||||
fn default() -> Self {
|
||||
MiTempState {
|
||||
impl MiTempDevice {
|
||||
pub fn new(addr: BDAddr, name: String) -> Self {
|
||||
MiTempDevice {
|
||||
name,
|
||||
addr,
|
||||
temperature: 0.0,
|
||||
humidity: 0.0,
|
||||
dew_point: 0.0,
|
||||
|
|
@ -26,9 +30,7 @@ impl Default for MiTempState {
|
|||
last_seen: Instant::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MiTempState {
|
||||
pub fn update(&mut self, json: &JsonValue) {
|
||||
self.last_seen = Instant::now();
|
||||
if let Some(temperature) = json["Temperature"].as_number().map(f32::from) {
|
||||
|
|
@ -53,7 +55,7 @@ pub fn format_mi_temp_state<W: Write>(
|
|||
mut writer: W,
|
||||
addr: BDAddr,
|
||||
names: &BTreeMap<BDAddr, String>,
|
||||
state: &MiTempState,
|
||||
state: &MiTempDevice,
|
||||
) -> fmt::Result {
|
||||
// sensor_battery{name="Living Room", mac="58:2D:34:39:1D:5B"} 100
|
||||
// sensor_temperature{name="Living Room", mac="58:2D:34:39:1D:5B"} 16.2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue