♻️ refactor + location conditions
This commit is contained in:
parent
ce9cdc4256
commit
3076ebe6a0
19 changed files with 1228 additions and 520 deletions
|
@ -1,7 +1,8 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{get_locations, routes::ToAPI};
|
||||
use crate::{config::get_config, get_locations};
|
||||
use based::request::api::ToAPI;
|
||||
|
||||
/// A Storage Location
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
@ -17,10 +18,31 @@ pub struct Location {
|
|||
pub conditions: Option<StorageConditions>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct StorageConditions {
|
||||
/// Median temperature
|
||||
pub temperature: i64,
|
||||
pub temperature: f64,
|
||||
/// Accurate temperature sensor reading
|
||||
pub temperature_sensor: Option<String>,
|
||||
}
|
||||
|
||||
impl StorageConditions {
|
||||
/// Get a accurate temperature from a sensor endpoint
|
||||
pub async fn accurate_temperature(&self) -> Option<f64> {
|
||||
let conf = get_config();
|
||||
let client = reqwest::Client::new();
|
||||
let res: serde_json::Value = client
|
||||
.get(self.temperature_sensor.clone()?)
|
||||
.bearer_auth(conf.home_assistant?)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.json()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
res.as_object()?.get("state")?.as_f64()
|
||||
}
|
||||
}
|
||||
|
||||
impl Location {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue