This commit is contained in:
Alex Janka 2023-12-28 13:34:02 +11:00
parent c4aa9353a8
commit 40efbea021
3 changed files with 12 additions and 3 deletions

2
Cargo.lock generated
View file

@ -2565,7 +2565,7 @@ dependencies = [
[[package]] [[package]]
name = "tesla-charge-controller" name = "tesla-charge-controller"
version = "0.1.1" version = "0.1.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "tesla-charge-controller" name = "tesla-charge-controller"
version = "0.1.1" version = "0.1.2"
edition = "2021" edition = "2021"
license = "MITNFA" license = "MITNFA"
description = "Controls Tesla charge rate based on solar charge data" description = "Controls Tesla charge rate based on solar charge data"

View file

@ -33,7 +33,7 @@ fn rocket(state: ServerState) -> rocket::Rocket<rocket::Build> {
.attach(Cors) .attach(Cors)
.manage(state) .manage(state)
.mount("/", UiStatic {}) .mount("/", UiStatic {})
.mount("/", routes![home, charge_state,]) .mount("/", routes![home, charge_state, flash])
} }
static UI_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/../client/dist"); static UI_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/../client/dist");
@ -118,6 +118,11 @@ async fn charge_state(state: &State<ServerState>) -> Option<Json<shared_types::C
Some(Json(charge_state)) Some(Json(charge_state))
} }
#[get("/flash")]
async fn flash(state: &State<ServerState>) {
state.flash().await;
}
impl ServerState { impl ServerState {
async fn get_coords(&self) -> Result<Coords> { async fn get_coords(&self) -> Result<Coords> {
let vehicle_data = self let vehicle_data = self
@ -147,6 +152,10 @@ impl ServerState {
let charge_state = vehicle_data.charge_state.context("no drive state")?; let charge_state = vehicle_data.charge_state.context("no drive state")?;
Ok(charge_state.try_into()?) Ok(charge_state.try_into()?)
} }
async fn flash(&self) {
let _ = self.api.flash_lights(&self.vehicle.vin).await;
}
} }
pub struct Cors; pub struct Cors;