2023-08-29 13:11:28 +10:00
|
|
|
use crate::cli::print_json;
|
2023-08-29 10:49:04 +10:00
|
|
|
use crate::vehicles::{SetChargeLimit, SetChargingAmps};
|
|
|
|
use crate::{Api, VehicleId};
|
2023-08-29 10:29:06 +10:00
|
|
|
use clap::{Args, Subcommand};
|
|
|
|
|
2023-08-29 11:33:03 +10:00
|
|
|
#[derive(Debug, Subcommand)]
|
|
|
|
pub enum VehicleCommand {
|
|
|
|
/// Get vehicle data.
|
|
|
|
Data,
|
|
|
|
|
|
|
|
/// Get charge state.
|
|
|
|
ChargeState,
|
|
|
|
|
|
|
|
/// Set charge limit.
|
|
|
|
SetChargeLimit { percent: u8 },
|
|
|
|
|
|
|
|
/// Set charge amps.
|
|
|
|
SetChargingAmps { charging_amps: i64 },
|
|
|
|
|
|
|
|
/// Start charging.
|
|
|
|
ChargeStart,
|
|
|
|
|
|
|
|
/// Stop charging.
|
|
|
|
ChargeStop,
|
|
|
|
}
|
|
|
|
|
2022-07-21 21:00:45 +10:00
|
|
|
#[derive(Debug, Args)]
|
|
|
|
pub struct VehicleArgs {
|
|
|
|
pub id: VehicleId,
|
|
|
|
|
|
|
|
#[clap(subcommand)]
|
|
|
|
pub command: VehicleCommand,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl VehicleArgs {
|
|
|
|
pub async fn run(self, api: &Api) -> miette::Result<()> {
|
|
|
|
match self.command {
|
|
|
|
VehicleCommand::Data => {
|
2023-08-29 13:11:28 +10:00
|
|
|
print_json(api.vehicle_data(&self.id).await?);
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
VehicleCommand::ChargeState => {
|
2023-08-29 13:11:28 +10:00
|
|
|
print_json(api.charge_state(&self.id).await?);
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
VehicleCommand::SetChargeLimit { percent } => {
|
2023-08-29 13:11:28 +10:00
|
|
|
api.set_charge_limit(&self.id, &SetChargeLimit { percent })
|
|
|
|
.await?;
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
VehicleCommand::SetChargingAmps { charging_amps } => {
|
2023-08-29 13:11:28 +10:00
|
|
|
api.set_charging_amps(&self.id, &SetChargingAmps { charging_amps })
|
|
|
|
.await?;
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
VehicleCommand::ChargeStart => {
|
2023-08-29 13:11:28 +10:00
|
|
|
api.charge_start(&self.id).await?;
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
VehicleCommand::ChargeStop => {
|
2023-08-29 13:11:28 +10:00
|
|
|
api.charge_stop(&self.id).await?;
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|