From cb8df6019a3d53215cc6225277847805bc195385 Mon Sep 17 00:00:00 2001 From: gak Date: Wed, 30 Aug 2023 15:46:16 +1000 Subject: [PATCH] feat: added set_scheduled_charging --- src/cli/vehicle.rs | 11 ++++++++++- src/vehicles.rs | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/cli/vehicle.rs b/src/cli/vehicle.rs index 2275f6b..13da3b9 100644 --- a/src/cli/vehicle.rs +++ b/src/cli/vehicle.rs @@ -1,5 +1,5 @@ use crate::cli::print_json; -use crate::vehicles::{SetChargeLimit, SetChargingAmps}; +use crate::vehicles::{SetChargeLimit, SetChargingAmps, SetScheduledCharging}; use crate::{Api, VehicleId}; use clap::{Args, Subcommand}; @@ -31,6 +31,9 @@ pub enum VehicleCommand { /// Stop charging. ChargeStop, + + /// Set scheduled charging. + SetScheduledCharging(SetScheduledCharging), } #[derive(Debug, Args)] @@ -71,6 +74,12 @@ 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, + ); + } } Ok(()) } diff --git a/src/vehicles.rs b/src/vehicles.rs index b0921bc..5ecf5b1 100644 --- a/src/vehicles.rs +++ b/src/vehicles.rs @@ -15,11 +15,11 @@ impl Api { post_arg_empty!(charge_port_door_close, "/vehicles/{}/command/charge_port_door_close", VehicleId); post_arg!(set_charge_limit, SetChargeLimit, "/vehicles/{}/command/set_charge_limit", VehicleId); post_arg!(set_charging_amps, SetChargingAmps, "/vehicles/{}/command/set_charging_amps", VehicleId); - // TODO: post_arg!(set_charging_scheduled_charging, SetChargingAmps, "/vehicles/{}/command/set_scheduled_charging", VehicleId); post_arg_empty!(charge_standard, "/vehicles/{}/command/charge_standard", VehicleId); post_arg_empty!(charge_max_range, "/vehicles/{}/command/charge_max_range", VehicleId); 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); } #[derive(Debug, Clone, Deserialize)] @@ -326,6 +326,21 @@ pub struct SetChargeLimit { pub percent: u8, } +/// set_scheduled_charging +#[derive(Debug, Serialize)] +#[cfg_attr(feature = "cli", derive(clap::Args))] +pub struct SetScheduledCharging { + /// Whether scheduled charging is enabled. + #[cfg_attr(feature = "cli", clap(short, long))] + pub enable: bool, + + /// Minutes after midnight (local time) to start charging. If omitted it will be midnight. + /// + /// NOTE: In the future this will be a time instead of minutes. + #[cfg_attr(feature = "cli", clap(short, long))] + pub time: Option, +} + #[cfg(test)] mod tests { use super::*;