many commands
This commit is contained in:
parent
1ea04ba5ec
commit
5672331f5c
128
src/main.rs
128
src/main.rs
|
@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||
use std::{io::BufRead, path::PathBuf};
|
||||
use teslatte::{
|
||||
auth::{AccessToken, RefreshToken},
|
||||
vehicles::{ActuateTrunk, SetChargingAmps},
|
||||
FleetApi, FleetVehicleApi,
|
||||
};
|
||||
use tokio::try_join;
|
||||
|
@ -28,8 +29,23 @@ enum Commands {
|
|||
#[clap(long)]
|
||||
flash: bool,
|
||||
},
|
||||
/// Run charge controller server
|
||||
SetChargeRate {
|
||||
#[clap(long)]
|
||||
amps: usize,
|
||||
},
|
||||
/// Print the default config file
|
||||
GenerateConfig,
|
||||
/// Start charging
|
||||
StartCharge,
|
||||
/// Stop charging
|
||||
StopCharge,
|
||||
/// Toggle boot
|
||||
ToggleBoot,
|
||||
/// Open charger door
|
||||
ChargerOpen,
|
||||
/// Close charger door
|
||||
ChargerClose,
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
|
@ -64,46 +80,104 @@ async fn main() {
|
|||
let args = Args::parse();
|
||||
let auth_path = args.config_dir.join("auth");
|
||||
// let config_path = args.config_dir.join("config");
|
||||
match get_auth(auth_path).await {
|
||||
Ok(api) => {
|
||||
let products = api.products().await;
|
||||
|
||||
match args.command {
|
||||
Commands::GenerateConfig => {
|
||||
println!(
|
||||
"{}",
|
||||
ron::ser::to_string_pretty(&Config::default(), Default::default()).unwrap()
|
||||
);
|
||||
}
|
||||
Commands::Watch { flash } => match get_auth(auth_path).await {
|
||||
Ok(api) => {
|
||||
let products = api.products().await;
|
||||
// println!("got products: {:#?}", products);
|
||||
if let Ok(res) = products {
|
||||
if let Some(teslatte::products::Product::Vehicle(vehicle)) = res.first() {
|
||||
api.wake_up(&vehicle.vin).await.unwrap();
|
||||
|
||||
if flash {
|
||||
if let Ok(res) = products {
|
||||
if let Some(teslatte::products::Product::Vehicle(vehicle)) = res.first() {
|
||||
println!("{vehicle:#?}");
|
||||
match try_join!(
|
||||
api.honk_horn(&vehicle.vin),
|
||||
api.flash_lights(&vehicle.vin)
|
||||
) {
|
||||
Ok(_r) => println!("flashed"),
|
||||
Err(e) => println!("error: {e:#?}"),
|
||||
}
|
||||
|
||||
while loop_prompt() {
|
||||
match match args.command {
|
||||
Commands::GenerateConfig => {
|
||||
println!(
|
||||
"{}",
|
||||
ron::ser::to_string_pretty(&Config::default(), Default::default())
|
||||
.unwrap()
|
||||
);
|
||||
Ok(MaybePostResponse::None)
|
||||
}
|
||||
Commands::Watch { flash } => {
|
||||
if flash {
|
||||
println!("{vehicle:#?}");
|
||||
match try_join!(
|
||||
api.honk_horn(&vehicle.vin),
|
||||
api.flash_lights(&vehicle.vin)
|
||||
) {
|
||||
Ok(_r) => println!("honked"),
|
||||
Ok(_r) => println!("flashed"),
|
||||
Err(e) => println!("error: {e:#?}"),
|
||||
}
|
||||
|
||||
while loop_prompt() {
|
||||
match try_join!(
|
||||
api.honk_horn(&vehicle.vin),
|
||||
api.flash_lights(&vehicle.vin)
|
||||
) {
|
||||
Ok(_r) => println!("honked"),
|
||||
Err(e) => println!("error: {e:#?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(MaybePostResponse::None)
|
||||
}
|
||||
Commands::SetChargeRate { amps } => api
|
||||
.set_charging_amps(
|
||||
&vehicle.vin,
|
||||
&SetChargingAmps {
|
||||
charging_amps: amps as i64,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map(|v| v.into()),
|
||||
Commands::StartCharge => {
|
||||
api.charge_start(&vehicle.vin).await.map(|v| v.into())
|
||||
}
|
||||
Commands::StopCharge => {
|
||||
api.charge_stop(&vehicle.vin).await.map(|v| v.into())
|
||||
}
|
||||
|
||||
Commands::ToggleBoot => api
|
||||
.actuate_trunk(
|
||||
&vehicle.vin,
|
||||
&ActuateTrunk {
|
||||
which_trunk: teslatte::vehicles::Trunk::rear,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map(|v| v.into()),
|
||||
|
||||
Commands::ChargerOpen => api
|
||||
.charge_port_door_open(&vehicle.vin)
|
||||
.await
|
||||
.map(|v| v.into()),
|
||||
|
||||
Commands::ChargerClose => api
|
||||
.charge_port_door_close(&vehicle.vin)
|
||||
.await
|
||||
.map(|v| v.into()),
|
||||
} {
|
||||
Ok(MaybePostResponse::PostResponse(response)) => {
|
||||
println!("post response: {response:#?}")
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(error) => println!("teslatte error: {error:#?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => println!("{}", e.error_string()),
|
||||
},
|
||||
}
|
||||
Err(e) => println!("{}", e.error_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MaybePostResponse {
|
||||
None,
|
||||
PostResponse(teslatte::PostResponse),
|
||||
}
|
||||
|
||||
impl From<teslatte::PostResponse> for MaybePostResponse {
|
||||
fn from(value: teslatte::PostResponse) -> Self {
|
||||
MaybePostResponse::PostResponse(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 491d9a58a8183b91314990274da805c156a6f48c
|
||||
Subproject commit 22bfecd8138ecacfe171255244360917f77ddb00
|
Loading…
Reference in a new issue