From 68b835124fa88f831de95bb7f120219ad1365370 Mon Sep 17 00:00:00 2001 From: gak Date: Wed, 30 Aug 2023 15:14:33 +1000 Subject: [PATCH] feat: added vehicle charge related apis --- examples/basic.rs | 3 --- src/cli/vehicle.rs | 32 +++++++++++++++++++++++++------- src/vehicles.rs | 7 +++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/examples/basic.rs b/examples/basic.rs index 99e76a5..0a15f7c 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -21,9 +21,6 @@ async fn main() { if !vehicles.is_empty() { let vehicle_data = api.vehicle_data(&vehicles[0].id).await.unwrap(); dbg!(vehicle_data); - - let charge_state = api.charge_state(&vehicles[0].id).await.unwrap(); - dbg!(&charge_state); } else { println!("No vehicles found!"); } diff --git a/src/cli/vehicle.rs b/src/cli/vehicle.rs index 27149d4..c9bcbc4 100644 --- a/src/cli/vehicle.rs +++ b/src/cli/vehicle.rs @@ -6,10 +6,13 @@ use clap::{Args, Subcommand}; #[derive(Debug, Subcommand)] pub enum VehicleCommand { /// Get vehicle data. - Data, + VehicleData, - /// Get charge state. - ChargeState, + /// 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 { percent: u8 }, @@ -17,6 +20,12 @@ pub enum VehicleCommand { /// Set charge amps. SetChargingAmps { charging_amps: i64 }, + /// Set the charge limit to the standard %. + ChargeStandard, + + /// Set the charge limit to the maximum %. + ChargeMaxRange, + /// Start charging. ChargeStart, @@ -35,12 +44,9 @@ pub struct VehicleArgs { impl VehicleArgs { pub async fn run(self, api: &Api) -> miette::Result<()> { match self.command { - VehicleCommand::Data => { + VehicleCommand::VehicleData => { print_json(api.vehicle_data(&self.id).await); } - VehicleCommand::ChargeState => { - print_json(api.charge_state(&self.id).await); - } VehicleCommand::SetChargeLimit { percent } => { print_json( api.set_charge_limit(&self.id, &SetChargeLimit { percent }) @@ -59,6 +65,18 @@ impl VehicleArgs { VehicleCommand::ChargeStop => { print_json(api.charge_stop(&self.id).await); } + 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); + } } Ok(()) } diff --git a/src/vehicles.rs b/src/vehicles.rs index dde9db7..a3f7554 100644 --- a/src/vehicles.rs +++ b/src/vehicles.rs @@ -9,8 +9,15 @@ use serde::{Deserialize, Serialize}; impl Api { get!(vehicles, Vec, "/vehicles"); get_arg!(vehicle_data, VehicleData, "/vehicles/{}/vehicle_data", VehicleId); + + // Charging + post_arg_empty!(charge_port_door_open, "/vehicles/{}/command/charge_port_door_open", VehicleId); + 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); }