refactor: reuse POST request structs for cli

This commit is contained in:
gak 2023-08-30 15:27:17 +10:00
parent 68b835124f
commit 844583a6b1
No known key found for this signature in database
2 changed files with 9 additions and 13 deletions

View file

@ -15,10 +15,10 @@ pub enum VehicleCommand {
ChargePortDoorClose,
/// Set charge limit.
SetChargeLimit { percent: u8 },
SetChargeLimit(SetChargeLimit),
/// Set charge amps.
SetChargingAmps { charging_amps: i64 },
SetChargingAmps(SetChargingAmps),
/// Set the charge limit to the standard %.
ChargeStandard,
@ -47,17 +47,11 @@ impl VehicleArgs {
VehicleCommand::VehicleData => {
print_json(api.vehicle_data(&self.id).await);
}
VehicleCommand::SetChargeLimit { percent } => {
print_json(
api.set_charge_limit(&self.id, &SetChargeLimit { percent })
.await,
);
VehicleCommand::SetChargeLimit(limit) => {
print_json(api.set_charge_limit(&self.id, &limit).await);
}
VehicleCommand::SetChargingAmps { charging_amps } => {
print_json(
api.set_charging_amps(&self.id, &SetChargingAmps { charging_amps })
.await,
);
VehicleCommand::SetChargingAmps(charging_amps) => {
print_json(api.set_charging_amps(&self.id, &charging_amps).await);
}
VehicleCommand::ChargeStart => {
print_json(api.charge_start(&self.id).await);

View file

@ -314,13 +314,15 @@ pub struct Vehicle {
}
#[derive(Debug, Serialize)]
#[cfg_attr(feature = "cli", derive(clap::Args))]
pub struct SetChargingAmps {
pub charging_amps: i64,
}
#[derive(Debug, Serialize)]
#[cfg_attr(feature = "cli", derive(clap::Args))]
pub struct SetChargeLimit {
// pub percent: Percentage,
// TODO: percent: Percentage,
pub percent: u8,
}