feat: set_scheduled_departure

This commit is contained in:
gak 2023-08-30 16:15:17 +10:00
parent 67058aab47
commit 8b96ecf3bc
No known key found for this signature in database
2 changed files with 44 additions and 6 deletions

View file

@ -1,5 +1,7 @@
use crate::cli::print_json; use crate::cli::print_json;
use crate::vehicles::{SetChargeLimit, SetChargingAmps, SetScheduledCharging}; use crate::vehicles::{
SetChargeLimit, SetChargingAmps, SetScheduledCharging, SetScheduledDeparture,
};
use crate::{Api, VehicleId}; use crate::{Api, VehicleId};
use clap::{Args, Subcommand}; use clap::{Args, Subcommand};
@ -34,6 +36,9 @@ pub enum VehicleCommand {
/// Set scheduled charging. /// Set scheduled charging.
SetScheduledCharging(SetScheduledCharging), SetScheduledCharging(SetScheduledCharging),
/// Set scheduled departure.
SetScheduledDeparture(SetScheduledDeparture),
} }
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -74,11 +79,11 @@ impl VehicleArgs {
VehicleCommand::ChargeMaxRange => { VehicleCommand::ChargeMaxRange => {
print_json(api.charge_max_range(&self.id).await); print_json(api.charge_max_range(&self.id).await);
} }
VehicleCommand::SetScheduledCharging(scheduled_charging) => { VehicleCommand::SetScheduledCharging(charging) => {
print_json( print_json(api.set_scheduled_charging(&self.id, &charging).await);
api.set_scheduled_charging(&self.id, &scheduled_charging) }
.await, VehicleCommand::SetScheduledDeparture(departure) => {
); print_json(api.set_scheduled_departure(&self.id, &departure).await);
} }
} }
Ok(()) Ok(())

View file

@ -20,6 +20,7 @@ impl Api {
post_arg_empty!(charge_start, "/vehicles/{}/command/charge_start", VehicleId); post_arg_empty!(charge_start, "/vehicles/{}/command/charge_start", VehicleId);
post_arg_empty!(charge_stop, "/vehicles/{}/command/charge_stop", 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_charging, SetScheduledCharging, "/vehicles/{}/command/set_scheduled_charging", VehicleId);
post_arg!(set_scheduled_departure, SetScheduledDeparture, "/vehicles/{}/command/set_scheduled_departure", VehicleId);
} }
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
@ -341,6 +342,38 @@ pub struct SetScheduledCharging {
pub time: Option<u64>, pub time: Option<u64>,
} }
#[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<u64>,
#[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<u64>,
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;