diff --git a/software/src/modules/eco/eco.cpp b/software/src/modules/eco/eco.cpp index 3fc62b33a..1d339fdd3 100644 --- a/software/src/modules/eco/eco.cpp +++ b/software/src/modules/eco/eco.cpp @@ -25,6 +25,8 @@ #include "module_dependencies.h" #include "build.h" +// TODO get MAX_CONTROLLED_CHARGERS from charge manager +#define MAX_CONTROLLED_CHARGERS 65 void Eco::pre_setup() { @@ -33,6 +35,8 @@ void Eco::pre_setup() config = ConfigRoot{Config::Object({ {"charge_plan_active", Config::Bool(false)}, {"mode_after_charge_plan", Config::Uint(3, 0, 3)}, + {"service_life_active", Config::Bool(false)}, + {"service_life", Config::Uint(8)}, {"charge_below_active", Config::Bool(false)}, {"charge_below", Config::Int32(0)}, // in ct {"block_above_active", Config::Bool(false)}, @@ -48,12 +52,22 @@ void Eco::pre_setup() {"enabled",Config::Bool(false)}, {"day", Config::Uint(0, 0, 2)}, {"time", Config::Int(8*60)}, // localtime in minutes since 00:00 - {"hours", Config::Uint(4, 1, 48)} + {"amount", Config::Uint(4)} // h or kWh depending on configuration (currently only h supported) }); charge_plan_update = charge_plan; + state_chargers_prototype = Config::Object({ + {"start", Config::Uint(0)}, // Start of charge + {"amount", Config::Uint(0)} // Amount of charge since start (h or kWh depending on configuration) + }); + state = Config::Object({ {"last_charge_plan_save", Config::Uint(0)}, + {"chargers", Config::Array( + {}, + &state_chargers_prototype, + 0, MAX_CONTROLLED_CHARGERS, Config::type_id() + )} }); } @@ -62,6 +76,11 @@ void Eco::setup() api.restorePersistentConfig("eco/config", &config); // TODO: Set user defined default charge_plan? + // TODO: Add number of chargers depending on charge manager configuration + for (size_t i = 0; i < MAX_CONTROLLED_CHARGERS; i++) { + state.get("chargers")->add(); + } + initialized = true; } diff --git a/software/src/modules/eco/eco.h b/software/src/modules/eco/eco.h index 919365cfc..1d99a7b05 100644 --- a/software/src/modules/eco/eco.h +++ b/software/src/modules/eco/eco.h @@ -32,6 +32,7 @@ class Eco final : public IModule ConfigRoot charge_plan; ConfigRoot charge_plan_update; ConfigRoot state; + ConfigRoot state_chargers_prototype; size_t trace_buffer_index; diff --git a/software/web/src/modules/eco/api.ts b/software/web/src/modules/eco/api.ts index 473f9c9f4..a033ca208 100644 --- a/software/web/src/modules/eco/api.ts +++ b/software/web/src/modules/eco/api.ts @@ -1,6 +1,13 @@ +interface ChargerState { + start: number, + amount: number +} + export interface config { charge_plan_active: boolean; mode_after_charge_plan: number; + service_life_active: boolean; + service_life: number; charge_below_active: boolean; charge_below: number; block_above_active: boolean; @@ -11,9 +18,10 @@ export interface charge_plan { enabled: boolean; day: number; time: number; - hours: number; + amount: number; } export interface state { last_charge_plan_save: number; + chargers: ChargerState[], } diff --git a/software/web/src/modules/eco/main.tsx b/software/web/src/modules/eco/main.tsx index 36c38a8a4..35380b751 100644 --- a/software/web/src/modules/eco/main.tsx +++ b/software/web/src/modules/eco/main.tsx @@ -91,7 +91,7 @@ export class Eco extends ConfigComponent<'eco/config', {status_ref?: RefObject this.setState({mode_after_charge_plan: parseInt(v)})} /> + + + { const active = state.charge_plan.enabled ? "aktiv" : "nicht aktiv"; const time = this.get_date_from_minutes(state.charge_plan.time).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'}); - return `Aktueller Ladeplan: Nutze die günstigsten ${state.charge_plan.hours} Stunden ${day} ${time} Uhr. Der Ladeplan ist ${active}.`; + return `Aktueller Ladeplan: Nutze die günstigsten ${state.charge_plan.amount} Stunden ${day} ${time} Uhr. Der Ladeplan ist ${active}.`; }; return @@ -233,8 +248,8 @@ export class EcoStatus extends Component<{}, EcoStatusState> { this.setState({charge_plan: {...state.charge_plan, hours: v}}, () => this.update_charge_plan({...state.charge_plan, hours: v}))} + value={state.charge_plan.amount} + onValue={(v) => this.setState({charge_plan: {...state.charge_plan, amount: v}}, () => this.update_charge_plan({...state.charge_plan, amount: v}))} min={1} max={48} />