teslatte/src/cli/vehicle.rs

87 lines
2.5 KiB
Rust
Raw Normal View History

use crate::cli::print_json;
2023-08-30 15:46:16 +10:00
use crate::vehicles::{SetChargeLimit, SetChargingAmps, SetScheduledCharging};
use crate::{Api, VehicleId};
use clap::{Args, Subcommand};
#[derive(Debug, Subcommand)]
pub enum VehicleCommand {
/// Get vehicle data.
VehicleData,
/// Open the charge port door or unlocks the cable.
ChargePortDoorOpen,
/// For vehicles with a motorized charge port, this closes it.
ChargePortDoorClose,
/// Set charge limit.
SetChargeLimit(SetChargeLimit),
/// Set charge amps.
SetChargingAmps(SetChargingAmps),
/// Set the charge limit to the standard %.
ChargeStandard,
/// Set the charge limit to the maximum %.
ChargeMaxRange,
/// Start charging.
ChargeStart,
/// Stop charging.
ChargeStop,
2023-08-30 15:46:16 +10:00
/// Set scheduled charging.
SetScheduledCharging(SetScheduledCharging),
}
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::VehicleData => {
print_json(api.vehicle_data(&self.id).await);
2022-07-21 21:00:45 +10:00
}
VehicleCommand::SetChargeLimit(limit) => {
print_json(api.set_charge_limit(&self.id, &limit).await);
2022-07-21 21:00:45 +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 => {
print_json(api.charge_start(&self.id).await);
2022-07-21 21:00:45 +10:00
}
VehicleCommand::ChargeStop => {
print_json(api.charge_stop(&self.id).await);
2022-07-21 21:00:45 +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(())
}
}