2023-08-29 13:11:28 +10:00
|
|
|
use crate::cli::print_json;
|
2023-08-30 15:46:16 +10:00
|
|
|
use crate::vehicles::{SetChargeLimit, SetChargingAmps, SetScheduledCharging};
|
2023-08-29 10:49:04 +10:00
|
|
|
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.
|
2023-08-30 15:27:17 +10:00
|
|
|
SetChargeLimit(SetChargeLimit),
|
2023-08-29 11:33:03 +10:00
|
|
|
|
|
|
|
/// Set charge amps.
|
2023-08-30 15:27:17 +10:00
|
|
|
SetChargingAmps(SetChargingAmps),
|
2023-08-29 11:33:03 +10:00
|
|
|
|
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,
|
2023-08-30 15:46:16 +10:00
|
|
|
|
|
|
|
/// Set scheduled charging.
|
|
|
|
SetScheduledCharging(SetScheduledCharging),
|
2023-08-29 11:33:03 +10:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2023-08-30 15:27:17 +10:00
|
|
|
VehicleCommand::SetChargeLimit(limit) => {
|
|
|
|
print_json(api.set_charge_limit(&self.id, &limit).await);
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
2023-08-30 15:27:17 +10:00
|
|
|
VehicleCommand::SetChargingAmps(charging_amps) => {
|
|
|
|
print_json(api.set_charging_amps(&self.id, &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);
|
|
|
|
}
|
2023-08-30 15:46:16 +10:00
|
|
|
VehicleCommand::SetScheduledCharging(scheduled_charging) => {
|
|
|
|
print_json(
|
|
|
|
api.set_scheduled_charging(&self.id, &scheduled_charging)
|
|
|
|
.await,
|
|
|
|
);
|
|
|
|
}
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|