From 8cb97059d77e5c19b1dd710393569293c36915e4 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 21 Jan 2024 08:36:33 +1100 Subject: [PATCH] disable automatic control toggle when car isn't charging --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/server/mod.rs | 17 ++++++++++++-- webapp/index.html | 60 +++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 72 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1ef5ca..266126f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2567,7 +2567,7 @@ dependencies = [ [[package]] name = "tesla-charge-controller" -version = "1.0.9" +version = "1.0.10" dependencies = [ "async-channel", "chrono", diff --git a/Cargo.toml b/Cargo.toml index e373bc0..9e1b207 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tesla-charge-controller" -version = "1.0.9" +version = "1.0.10" edition = "2021" license = "MITNFA" description = "Controls Tesla charge rate based on solar charge data" diff --git a/src/server/mod.rs b/src/server/mod.rs index 2e59c9c..23b894e 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -7,6 +7,7 @@ use rocket::{ serde::json::Json, Request, Response, State, }; +use serde::{Deserialize, Serialize}; use crate::{ api_interface::InterfaceRequest, @@ -82,9 +83,21 @@ async fn car_state(state: &State) -> Result, ServerE Ok(Json(*state.car_state.read()?)) } +#[derive(Clone, Copy, Serialize, Deserialize, Debug)] +struct ControlState { + control_enable: bool, + is_charging_at_home: bool, +} + #[get("/control-state")] -async fn control_state(state: &State) -> Result, ServerError> { - Ok(Json(*state.tcrc_state.read()?)) +async fn control_state(state: &State) -> Result, ServerError> { + let control_enable = state.tcrc_state.read()?.control_enable; + let is_charging_at_home = state.car_state.read()?.is_charging_at_home(); + + Ok(Json(ControlState { + control_enable, + is_charging_at_home, + })) } #[post("/flash")] diff --git a/webapp/index.html b/webapp/index.html index 8c5033f..de1516e 100644 --- a/webapp/index.html +++ b/webapp/index.html @@ -25,6 +25,11 @@ cursor: progress; } + .disabled, + .disabled * { + cursor: not-allowed; + } + .selector { padding: 1em; background-color: gray; @@ -46,17 +51,39 @@ input[type=radio] { display: none; - } input[type=radio]:checked+label { background-color: white; + } + input[type=radio]:checked:disabled+label { + background-color: #ddd; + } + + input[type=radio]:disabled+label { + color: #666; }