From 8b96ecf3bc3ab31bdac35cf09bbf969491729b5e Mon Sep 17 00:00:00 2001 From: gak Date: Wed, 30 Aug 2023 16:15:17 +1000 Subject: [PATCH] feat: set_scheduled_departure --- src/cli/vehicle.rs | 17 +++++++++++------ src/vehicles.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/cli/vehicle.rs b/src/cli/vehicle.rs index 13da3b9..ec4023e 100644 --- a/src/cli/vehicle.rs +++ b/src/cli/vehicle.rs @@ -1,5 +1,7 @@ use crate::cli::print_json; -use crate::vehicles::{SetChargeLimit, SetChargingAmps, SetScheduledCharging}; +use crate::vehicles::{ + SetChargeLimit, SetChargingAmps, SetScheduledCharging, SetScheduledDeparture, +}; use crate::{Api, VehicleId}; use clap::{Args, Subcommand}; @@ -34,6 +36,9 @@ pub enum VehicleCommand { /// Set scheduled charging. SetScheduledCharging(SetScheduledCharging), + + /// Set scheduled departure. + SetScheduledDeparture(SetScheduledDeparture), } #[derive(Debug, Args)] @@ -74,11 +79,11 @@ impl VehicleArgs { VehicleCommand::ChargeMaxRange => { print_json(api.charge_max_range(&self.id).await); } - VehicleCommand::SetScheduledCharging(scheduled_charging) => { - print_json( - api.set_scheduled_charging(&self.id, &scheduled_charging) - .await, - ); + VehicleCommand::SetScheduledCharging(charging) => { + print_json(api.set_scheduled_charging(&self.id, &charging).await); + } + VehicleCommand::SetScheduledDeparture(departure) => { + print_json(api.set_scheduled_departure(&self.id, &departure).await); } } Ok(()) diff --git a/src/vehicles.rs b/src/vehicles.rs index 5ecf5b1..e7eb16f 100644 --- a/src/vehicles.rs +++ b/src/vehicles.rs @@ -20,6 +20,7 @@ impl Api { post_arg_empty!(charge_start, "/vehicles/{}/command/charge_start", VehicleId); post_arg_empty!(charge_stop, "/vehicles/{}/command/charge_stop", VehicleId); post_arg!(set_scheduled_charging, SetScheduledCharging, "/vehicles/{}/command/set_scheduled_charging", VehicleId); + post_arg!(set_scheduled_departure, SetScheduledDeparture, "/vehicles/{}/command/set_scheduled_departure", VehicleId); } #[derive(Debug, Clone, Deserialize)] @@ -341,6 +342,38 @@ pub struct SetScheduledCharging { pub time: Option, } +#[derive(Debug, Serialize)] +#[cfg_attr(feature = "cli", derive(clap::Args))] +pub struct SetScheduledDeparture { + /// Whether scheduled departure is enabled. + #[cfg_attr(feature = "cli", clap(short, long))] + pub enable: bool, + + /// Minutes after midnight (local time) to depart. + /// + /// NOTE: In the future this will be a time instead of minutes. + #[cfg_attr(feature = "cli", clap(short, long))] + pub departure_time: Option, + + #[cfg_attr(feature = "cli", clap(short, long))] + pub preconditioning_enabled: bool, + + #[cfg_attr(feature = "cli", clap(short = 'w', long))] + pub preconditioning_weekdays_only: bool, + + #[cfg_attr(feature = "cli", clap(short, long))] + pub off_peak_charging_enabled: bool, + + #[cfg_attr(feature = "cli", clap(short = 'y', long))] + pub off_peak_charging_weekdays_only: bool, + + /// Minutes after midnight (local time) to end off peak charging. + /// + /// NOTE: In the future this will be a time instead of minutes. + #[cfg_attr(feature = "cli", clap(short = 'n', long))] + pub end_off_peak_time: Option, +} + #[cfg(test)] mod tests { use super::*;