actually improved webapp!!
This commit is contained in:
parent
dc4db5e5f9
commit
23f4871084
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1991,7 +1991,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tesla-charge-controller"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "tesla-charge-controller"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
edition = "2021"
|
||||
license = "MITNFA"
|
||||
description = "Controls Tesla charge rate based on solar charge data"
|
||||
|
|
|
@ -5,9 +5,11 @@ pub struct ChargeState {
|
|||
pub battery_level: i64,
|
||||
pub battery_range: f64,
|
||||
pub charge_amps: i64,
|
||||
pub charge_rate: f64,
|
||||
pub charge_current_request: i64,
|
||||
pub charge_current_request_max: i64,
|
||||
pub charge_enable_request: bool,
|
||||
pub charge_limit_soc: i64,
|
||||
}
|
||||
|
||||
impl ChargeState {
|
||||
|
@ -23,9 +25,11 @@ impl From<teslatte::vehicles::ChargeState> for ChargeState {
|
|||
battery_level: value.battery_level,
|
||||
battery_range: value.battery_range,
|
||||
charge_amps: value.charge_amps,
|
||||
charge_rate: value.charge_rate,
|
||||
charge_current_request: value.charge_current_request,
|
||||
charge_current_request_max: value.charge_current_request_max,
|
||||
charge_enable_request: value.charge_enable_request,
|
||||
charge_limit_soc: value.charge_limit_soc,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,37 +4,70 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Tesla Charge Control</title>
|
||||
<link id="favicon" rel="icon"
|
||||
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>⏳</text></svg>">
|
||||
|
||||
<script type="text/javascript">
|
||||
const api_url = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port;
|
||||
|
||||
function register() {
|
||||
refresh();
|
||||
setInterval(refresh, 15000);
|
||||
}
|
||||
|
||||
function flash() {
|
||||
fetch(api_url + "/flash", { method: "POST" })
|
||||
.then((response) => console.log(response));
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
let favicon = document.getElementById("favicon");
|
||||
|
||||
favicon.setAttribute("href", "data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>" + "⏳" + "</text></svg>");
|
||||
fetch(api_url + "/charge-state")
|
||||
.then((response) => response.json())
|
||||
.then((json) => update_charge_state(json));
|
||||
}
|
||||
|
||||
function update_charge_state(charge_state) {
|
||||
let favicon = document.getElementById("favicon");
|
||||
|
||||
favicon.setAttribute("href", "data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>" + get_emoji(charge_state) + "</text></svg>");
|
||||
|
||||
|
||||
var info_div = document.getElementById("info");
|
||||
while (info_div.childElementCount > 0) { info_div.removeChild(info_div.firstChild) }
|
||||
var arr = ["Battery " + charge_state.battery_level + "%", "Range: " + (charge_state.battery_range * 1.60934).toFixed(1) + "km", "Charging at " + charge_state.charge_amps + " amps"];
|
||||
|
||||
var arr = ["Battery " + charge_state.battery_level + "%", "Range: " + (charge_state.battery_range * 1.60934).toFixed(1) + "km", "Charging at " + charge_state.charge_rate.toFixed(1) + " amps", "Charging until battery at " + charge_state.charge_limit_soc + "%",
|
||||
];
|
||||
for (line in arr) {
|
||||
el = document.createElement('p');
|
||||
el.appendChild(document.createTextNode(arr[line]));
|
||||
info_div.appendChild(el)
|
||||
}
|
||||
|
||||
|
||||
el = document.createElement('p');
|
||||
el.appendChild(document.createTextNode("Full charge state:"));
|
||||
|
||||
state_json = document.createElement('pre');
|
||||
state_json.appendChild(document.createTextNode(JSON.stringify(charge_state, null, '\t')));
|
||||
el.appendChild(state_json);
|
||||
info_div.appendChild(el);
|
||||
}
|
||||
|
||||
function get_emoji(charge_state) {
|
||||
if (charge_state.charge_rate > 0) {
|
||||
return "🔌";
|
||||
} else if (charge_state.battery_level < 60) {
|
||||
return "🪫"
|
||||
} else return "🔋";
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body></body>
|
||||
<button onclick="refresh()">refresh</button>
|
||||
<div id="info"></div>
|
||||
<body onload="register()"></body>
|
||||
<button onclick="flash()">flash</button>
|
||||
<div id="info"></div>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue