bring charge rate back down if it's changed from the webui
All checks were successful
Build .deb on release / Build-Deb (push) Successful in 1m49s

This commit is contained in:
Alex Janka 2024-01-21 18:00:06 +11:00
parent 1cec64dc62
commit 7bbd0ed6f7
3 changed files with 6 additions and 5 deletions

2
Cargo.lock generated
View file

@ -2567,7 +2567,7 @@ dependencies = [
[[package]] [[package]]
name = "tesla-charge-controller" name = "tesla-charge-controller"
version = "1.0.14" version = "1.0.15"
dependencies = [ dependencies = [
"async-channel", "async-channel",
"chrono", "chrono",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "tesla-charge-controller" name = "tesla-charge-controller"
version = "1.0.14" version = "1.0.15"
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

@ -105,13 +105,14 @@ fn get_control(pl_state: &PlState, charge_state: &ChargeState) -> Option<Interfa
return valid_rate(rate, charge_state.charge_amps).map(InterfaceRequest::SetChargeRate); return valid_rate(rate, charge_state.charge_amps).map(InterfaceRequest::SetChargeRate);
} }
None valid_rate(charge_state.charge_amps, charge_state.charge_amps)
.map(InterfaceRequest::SetChargeRate)
} }
fn valid_rate(rate: i64, other: i64) -> Option<i64> { fn valid_rate(rate: i64, previous: i64) -> Option<i64> {
let config = access_config(); let config = access_config();
let new = rate.clamp(config.min_rate, config.max_rate); let new = rate.clamp(config.min_rate, config.max_rate);
if new == other { if new == previous {
None None
} else { } else {
Some(new) Some(new)