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; }