Add site mode, UI tweaks
This commit is contained in:
parent
ec8e9f3dec
commit
ea1d3ab379
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@ -76,7 +75,8 @@ pub fn start(
|
|||||||
.find(|s| s.id == reg.site_id)
|
.find(|s| s.id == reg.site_id)
|
||||||
.ok_or(anyhow!("Invalid site id {}", reg.site_id))?
|
.ok_or(anyhow!("Invalid site id {}", reg.site_id))?
|
||||||
.details(&mut ctx)?
|
.details(&mut ctx)?
|
||||||
.circuits.into_iter()
|
.circuits
|
||||||
|
.into_iter()
|
||||||
.find(|c| c.id == reg.circuit_id)
|
.find(|c| c.id == reg.circuit_id)
|
||||||
.ok_or(anyhow!("Invalid circuit id {}", reg.circuit_id))?;
|
.ok_or(anyhow!("Invalid circuit id {}", reg.circuit_id))?;
|
||||||
|
|
||||||
|
66
src/main.rs
66
src/main.rs
@ -3,7 +3,7 @@ use std::error::Error;
|
|||||||
use anyhow::{Context as AnyhowContext, Result};
|
use anyhow::{Context as AnyhowContext, Result};
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use easee::api::{ApiError, Charger, ChargerState, ChargingSession, Context};
|
use easee::api::{ApiError, Charger, ChargerState, ChargingSession, Context, SetCurrent, Triphase};
|
||||||
use easee::observation;
|
use easee::observation;
|
||||||
|
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
@ -27,6 +27,16 @@ enum Session {
|
|||||||
Latest,
|
Latest,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Subcommand)]
|
||||||
|
enum SiteCommand {
|
||||||
|
Set {
|
||||||
|
phase1: f64,
|
||||||
|
phase2: f64,
|
||||||
|
phase3: f64,
|
||||||
|
ttl: i32,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Subcommand)]
|
#[derive(Debug, Clone, Subcommand)]
|
||||||
enum Mode {
|
enum Mode {
|
||||||
Login,
|
Login,
|
||||||
@ -39,6 +49,12 @@ enum Mode {
|
|||||||
Charge {
|
Charge {
|
||||||
command: Command,
|
command: Command,
|
||||||
},
|
},
|
||||||
|
Site {
|
||||||
|
site_id: i32,
|
||||||
|
circuit_id: i32,
|
||||||
|
#[command(subcommand)]
|
||||||
|
cmd: Option<SiteCommand>,
|
||||||
|
},
|
||||||
Stream,
|
Stream,
|
||||||
Power,
|
Power,
|
||||||
Control,
|
Control,
|
||||||
@ -49,7 +65,7 @@ struct CLI {
|
|||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
debug: bool,
|
debug: bool,
|
||||||
|
|
||||||
#[arg(short, long)]
|
#[arg(short = 'i', long)]
|
||||||
charger_id: Vec<String>,
|
charger_id: Vec<String>,
|
||||||
|
|
||||||
#[arg(short, long, default_value = "./config.json")]
|
#[arg(short, long, default_value = "./config.json")]
|
||||||
@ -141,7 +157,7 @@ fn status(id: &str, c: ChargerState) {
|
|||||||
let cable = if c.cable_locked { "LOCK" } else { "open" };
|
let cable = if c.cable_locked { "LOCK" } else { "open" };
|
||||||
let mode = c.charger_op_mode;
|
let mode = c.charger_op_mode;
|
||||||
let power = c.total_power;
|
let power = c.total_power;
|
||||||
println!("{id}: [{mode:?}] ({power}W) cable:{cable}");
|
println!("{id}: [{mode:?}] ({power:.3}kW) cable:{cable}");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
@ -158,20 +174,20 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut ctx = load_context()?;
|
let mut ctx = load_context()?;
|
||||||
let config = config::load_config(&args.config)?;
|
let config = config::load_config(&args.config).context("config file")?;
|
||||||
|
|
||||||
match args.mode {
|
match args.mode {
|
||||||
Mode::Login => login()?,
|
Mode::Login => login()?,
|
||||||
Mode::List => {
|
Mode::List => {
|
||||||
for site in ctx.sites()? {
|
for site in ctx.sites()? {
|
||||||
println!(
|
println!("Site {} (level {})", site.id, site.level_of_access);
|
||||||
"Site {} (level {})",
|
|
||||||
site.id, site.level_of_access
|
|
||||||
);
|
|
||||||
for circuit in site.details(&mut ctx)?.circuits {
|
for circuit in site.details(&mut ctx)?.circuits {
|
||||||
println!(" Circuit {} ({}A)", circuit.id, circuit.rated_current);
|
println!(" Circuit {} ({}A)", circuit.id, circuit.rated_current);
|
||||||
for charger in circuit.chargers {
|
for charger in circuit.chargers {
|
||||||
println!(" Charger {} (level {})", charger.id, charger.level_of_access);
|
println!(
|
||||||
|
" Charger {} (level {})",
|
||||||
|
charger.id, charger.level_of_access
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,6 +220,38 @@ fn main() -> Result<()> {
|
|||||||
let chargers = load_chargers(&mut ctx, &args.charger_id)?;
|
let chargers = load_chargers(&mut ctx, &args.charger_id)?;
|
||||||
control::start(ctx, config, chargers)?;
|
control::start(ctx, config, chargers)?;
|
||||||
}
|
}
|
||||||
|
Mode::Site {
|
||||||
|
site_id,
|
||||||
|
circuit_id,
|
||||||
|
cmd,
|
||||||
|
} => {
|
||||||
|
let site = ctx.circuit(site_id, circuit_id)?;
|
||||||
|
match cmd {
|
||||||
|
Some(SiteCommand::Set {
|
||||||
|
phase1,
|
||||||
|
phase2,
|
||||||
|
phase3,
|
||||||
|
ttl,
|
||||||
|
}) => {
|
||||||
|
let current = Triphase {
|
||||||
|
phase1,
|
||||||
|
phase2,
|
||||||
|
phase3,
|
||||||
|
};
|
||||||
|
site.set_dynamic_current(
|
||||||
|
&mut ctx,
|
||||||
|
SetCurrent {
|
||||||
|
time_to_live: Some(ttl),
|
||||||
|
current,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let current = site.dynamic_current(&mut ctx)?;
|
||||||
|
println!("{:?}", current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user