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.
|
2023-08-30 15:14:33 +10:00
|
|
|
VehicleData,
|
2023-08-29 11:33:03 +10:00
|
|
|
|
2023-08-30 15:14:33 +10:00
|
|
|
/// Open the charge port door or unlocks the cable.
|
|
|
|
ChargePortDoorOpen,
|
|
|
|
|
|
|
|
/// For vehicles with a motorized charge port, this closes it.
|
|
|
|
ChargePortDoorClose,
|
2023-08-29 11:33:03 +10:00
|
|
|
|
|
|
|
/// Set charge limit.
|
|
|
|
SetChargeLimit { percent: u8 },
|
|
|
|
|
|
|
|
/// Set charge amps.
|
|
|
|
SetChargingAmps { charging_amps: i64 },
|
|
|
|
|
2023-08-30 15:14:33 +10:00
|
|
|
/// Set the charge limit to the standard %.
|
|
|
|
ChargeStandard,
|
|
|
|
|
|
|
|
/// Set the charge limit to the maximum %.
|
|
|
|
ChargeMaxRange,
|
|
|
|
|
2023-08-29 11:33:03 +10:00
|
|
|
/// 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 {
|
2023-08-30 15:14:33 +10:00
|
|
|
VehicleCommand::VehicleData => {
|
2023-08-29 16:13:43 +10:00
|
|
|
print_json(api.vehicle_data(&self.id).await);
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
VehicleCommand::SetChargeLimit { percent } => {
|
2023-08-29 16:13:43 +10:00
|
|
|
print_json(
|
|
|
|
api.set_charge_limit(&self.id, &SetChargeLimit { percent })
|
|
|
|
.await,
|
|
|
|
);
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
VehicleCommand::SetChargingAmps { charging_amps } => {
|
2023-08-29 16:13:43 +10:00
|
|
|
print_json(
|
|
|
|
api.set_charging_amps(&self.id, &SetChargingAmps { charging_amps })
|
|
|
|
.await,
|
|
|
|
);
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
VehicleCommand::ChargeStart => {
|
2023-08-29 16:13:43 +10:00
|
|
|
print_json(api.charge_start(&self.id).await);
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
VehicleCommand::ChargeStop => {
|
2023-08-29 16:13:43 +10:00
|
|
|
print_json(api.charge_stop(&self.id).await);
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
2023-08-30 15:14:33 +10:00
|
|
|
VehicleCommand::ChargePortDoorOpen => {
|
|
|
|
print_json(api.charge_port_door_open(&self.id).await);
|
|
|
|
}
|
|
|
|
VehicleCommand::ChargePortDoorClose => {
|
|
|
|
print_json(api.charge_port_door_close(&self.id).await);
|
|
|
|
}
|
|
|
|
VehicleCommand::ChargeStandard => {
|
|
|
|
print_json(api.charge_standard(&self.id).await);
|
|
|
|
}
|
|
|
|
VehicleCommand::ChargeMaxRange => {
|
|
|
|
print_json(api.charge_max_range(&self.id).await);
|
|
|
|
}
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|