feat: added vehicle charge related apis
This commit is contained in:
parent
78ed8a9477
commit
68b835124f
|
@ -21,9 +21,6 @@ async fn main() {
|
||||||
if !vehicles.is_empty() {
|
if !vehicles.is_empty() {
|
||||||
let vehicle_data = api.vehicle_data(&vehicles[0].id).await.unwrap();
|
let vehicle_data = api.vehicle_data(&vehicles[0].id).await.unwrap();
|
||||||
dbg!(vehicle_data);
|
dbg!(vehicle_data);
|
||||||
|
|
||||||
let charge_state = api.charge_state(&vehicles[0].id).await.unwrap();
|
|
||||||
dbg!(&charge_state);
|
|
||||||
} else {
|
} else {
|
||||||
println!("No vehicles found!");
|
println!("No vehicles found!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,13 @@ use clap::{Args, Subcommand};
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
pub enum VehicleCommand {
|
pub enum VehicleCommand {
|
||||||
/// Get vehicle data.
|
/// Get vehicle data.
|
||||||
Data,
|
VehicleData,
|
||||||
|
|
||||||
/// Get charge state.
|
/// Open the charge port door or unlocks the cable.
|
||||||
ChargeState,
|
ChargePortDoorOpen,
|
||||||
|
|
||||||
|
/// For vehicles with a motorized charge port, this closes it.
|
||||||
|
ChargePortDoorClose,
|
||||||
|
|
||||||
/// Set charge limit.
|
/// Set charge limit.
|
||||||
SetChargeLimit { percent: u8 },
|
SetChargeLimit { percent: u8 },
|
||||||
|
@ -17,6 +20,12 @@ pub enum VehicleCommand {
|
||||||
/// Set charge amps.
|
/// Set charge amps.
|
||||||
SetChargingAmps { charging_amps: i64 },
|
SetChargingAmps { charging_amps: i64 },
|
||||||
|
|
||||||
|
/// Set the charge limit to the standard %.
|
||||||
|
ChargeStandard,
|
||||||
|
|
||||||
|
/// Set the charge limit to the maximum %.
|
||||||
|
ChargeMaxRange,
|
||||||
|
|
||||||
/// Start charging.
|
/// Start charging.
|
||||||
ChargeStart,
|
ChargeStart,
|
||||||
|
|
||||||
|
@ -35,12 +44,9 @@ pub struct VehicleArgs {
|
||||||
impl VehicleArgs {
|
impl VehicleArgs {
|
||||||
pub async fn run(self, api: &Api) -> miette::Result<()> {
|
pub async fn run(self, api: &Api) -> miette::Result<()> {
|
||||||
match self.command {
|
match self.command {
|
||||||
VehicleCommand::Data => {
|
VehicleCommand::VehicleData => {
|
||||||
print_json(api.vehicle_data(&self.id).await);
|
print_json(api.vehicle_data(&self.id).await);
|
||||||
}
|
}
|
||||||
VehicleCommand::ChargeState => {
|
|
||||||
print_json(api.charge_state(&self.id).await);
|
|
||||||
}
|
|
||||||
VehicleCommand::SetChargeLimit { percent } => {
|
VehicleCommand::SetChargeLimit { percent } => {
|
||||||
print_json(
|
print_json(
|
||||||
api.set_charge_limit(&self.id, &SetChargeLimit { percent })
|
api.set_charge_limit(&self.id, &SetChargeLimit { percent })
|
||||||
|
@ -59,6 +65,18 @@ impl VehicleArgs {
|
||||||
VehicleCommand::ChargeStop => {
|
VehicleCommand::ChargeStop => {
|
||||||
print_json(api.charge_stop(&self.id).await);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,15 @@ use serde::{Deserialize, Serialize};
|
||||||
impl Api {
|
impl Api {
|
||||||
get!(vehicles, Vec<Vehicle>, "/vehicles");
|
get!(vehicles, Vec<Vehicle>, "/vehicles");
|
||||||
get_arg!(vehicle_data, VehicleData, "/vehicles/{}/vehicle_data", VehicleId);
|
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_charge_limit, SetChargeLimit, "/vehicles/{}/command/set_charge_limit", VehicleId);
|
||||||
post_arg!(set_charging_amps, SetChargingAmps, "/vehicles/{}/command/set_charging_amps", 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_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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue