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]]
name = "tesla-charge-controller"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"anyhow",
"clap",

View file

@ -1,6 +1,6 @@
[package]
name = "tesla-charge-controller"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
license = "MITNFA"
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)
.manage(state)
.mount("/", UiStatic {})
.mount("/", routes![home, charge_state,])
.mount("/", routes![home, charge_state, flash])
}
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))
}
#[get("/flash")]
async fn flash(state: &State<ServerState>) {
state.flash().await;
}
impl ServerState {
async fn get_coords(&self) -> Result<Coords> {
let vehicle_data = self
@ -147,6 +152,10 @@ impl ServerState {
let charge_state = vehicle_data.charge_state.context("no drive state")?;
Ok(charge_state.try_into()?)
}
async fn flash(&self) {
let _ = self.api.flash_lights(&self.vehicle.vin).await;
}
}
pub struct Cors;