diff --git a/config.example.json b/config.example.json index 5e5d62c..e703e3b 100644 --- a/config.example.json +++ b/config.example.json @@ -20,6 +20,8 @@ "power_bias_watts": 3000.0, "monophase_volts": 240, "polling_interval": 15, + "current_min": 7, + "current_max": 16, "p": 0.2, "i": 0.1, "d": 0 diff --git a/src/config.rs b/src/config.rs index f7cfe57..18660f6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,5 @@ +use std::ops::Range; + use anyhow::Result; use serde::Deserialize; use serde_json; @@ -36,6 +38,8 @@ pub struct Regulator { pub power_bias_watts: f64, pub monophase_volts: f64, pub polling_interval: u64, + pub current_min: f64, + pub current_max: f64, pub p: f64, pub i: f64, pub d: f64, diff --git a/src/control.rs b/src/control.rs index efa0887..6764b38 100644 --- a/src/control.rs +++ b/src/control.rs @@ -71,12 +71,12 @@ pub fn start( if let Some(reg) = config.regulator { let circuit = ctx - .sites_details()? + .sites()? .into_iter() - .find(|s| s.site.id == reg.site_id) + .find(|s| s.id == reg.site_id) .ok_or(anyhow!("Invalid site id {}", reg.site_id))? - .circuits - .into_iter() + .details(&mut ctx)? + .circuits.into_iter() .find(|c| c.id == reg.circuit_id) .ok_or(anyhow!("Invalid circuit id {}", reg.circuit_id))?; diff --git a/src/main.rs b/src/main.rs index 5413811..01232ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -163,12 +163,12 @@ fn main() -> Result<()> { match args.mode { Mode::Login => login()?, Mode::List => { - for site in ctx.sites_details()? { + for site in ctx.sites()? { println!( "Site {} (level {})", - site.site.id, site.site.level_of_access + site.id, site.level_of_access ); - for circuit in site.circuits { + for circuit in site.details(&mut ctx)?.circuits { println!(" Circuit {} ({}A)", circuit.id, circuit.rated_current); for charger in circuit.chargers { println!("Charger {} (level {}", charger.id, charger.level_of_access);