teslatte/src/cli/vehicle.rs

141 lines
4 KiB
Rust
Raw Normal View History

2023-08-30 16:15:17 +10:00
use crate::vehicles::{
Endpoints, GetVehicleData, SetChargeLimit, SetChargingAmps, SetScheduledCharging,
SetScheduledDeparture, SetTemperatures,
2023-08-30 16:15:17 +10:00
};
use crate::{OwnerApi, VehicleApi, VehicleId};
use clap::{Args, Subcommand};
#[derive(Debug, Subcommand)]
pub enum VehicleCommand {
/// Get vehicle data.
VehicleData(Endpoints),
/// 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),
2023-08-30 16:15:17 +10:00
/// Set scheduled departure.
SetScheduledDeparture(SetScheduledDeparture),
2023-08-30 16:19:19 +10:00
/// Honk!
HonkHorn,
/// Flash the lights.
FlashLights,
/// Enable the HVAC
EnableHvac,
/// Disable the HVAC
DisableHvac,
/// Set the temperature for the HVAC
HvacTemperature(SetTemperatures),
/// Door unlock
DoorUnlock,
/// Door lock
DoorLock,
/// For keyless driving
RemoteStartDrive,
}
2022-07-21 21:00:45 +10:00
#[derive(Debug, Args)]
pub struct VehicleArgs {
pub id: VehicleId,
#[clap(subcommand)]
pub command: VehicleCommand,
}
impl VehicleArgs {
2023-10-20 12:18:38 +11:00
pub async fn run(self, api: &OwnerApi) -> miette::Result<()> {
2022-07-21 21:00:45 +10:00
match self.command {
VehicleCommand::VehicleData(endpoints) => {
let get_vehicle_data = GetVehicleData::new_with_endpoints(self.id, endpoints);
api.vehicle_data(&get_vehicle_data).await?;
2022-07-21 21:00:45 +10:00
}
VehicleCommand::SetChargeLimit(limit) => {
api.set_charge_limit(&self.id, &limit).await?;
2022-07-21 21:00:45 +10:00
}
VehicleCommand::SetChargingAmps(charging_amps) => {
api.set_charging_amps(&self.id, &charging_amps).await?;
2022-07-21 21:00:45 +10:00
}
VehicleCommand::ChargeStart => {
api.charge_start(&self.id).await?;
2022-07-21 21:00:45 +10:00
}
VehicleCommand::ChargeStop => {
api.charge_stop(&self.id).await?;
2022-07-21 21:00:45 +10:00
}
VehicleCommand::ChargePortDoorOpen => {
api.charge_port_door_open(&self.id).await?;
}
VehicleCommand::ChargePortDoorClose => {
api.charge_port_door_close(&self.id).await?;
}
VehicleCommand::ChargeStandard => {
api.charge_standard(&self.id).await?;
}
VehicleCommand::ChargeMaxRange => {
api.charge_max_range(&self.id).await?;
}
2023-08-30 16:15:17 +10:00
VehicleCommand::SetScheduledCharging(charging) => {
api.set_scheduled_charging(&self.id, &charging).await?;
2023-08-30 16:15:17 +10:00
}
VehicleCommand::SetScheduledDeparture(departure) => {
api.set_scheduled_departure(&self.id, &departure).await?;
2023-08-30 15:46:16 +10:00
}
2023-08-30 16:19:19 +10:00
VehicleCommand::HonkHorn => {
api.honk_horn(&self.id).await?;
2023-08-30 16:19:19 +10:00
}
VehicleCommand::FlashLights => {
api.flash_lights(&self.id).await?;
2023-08-30 16:19:19 +10:00
}
VehicleCommand::EnableHvac => {
api.auto_conditioning_start(&self.id).await?;
}
VehicleCommand::DisableHvac => {
api.auto_conditioning_stop(&self.id).await?;
}
VehicleCommand::HvacTemperature(temps) => {
api.set_temps(&self.id, &temps).await?;
}
VehicleCommand::DoorUnlock => {
api.door_unlock(&self.id).await?;
}
VehicleCommand::DoorLock => {
api.door_lock(&self.id).await?;
}
VehicleCommand::RemoteStartDrive => {
api.remote_start_drive(&self.id).await?;
}
2022-07-21 21:00:45 +10:00
}
Ok(())
}
}