Skip to content

Commit

Permalink
[web/]eco: Add service life and charger state to API
Browse files Browse the repository at this point in the history
The API should now be ready for first release
(except for changes in naming)
  • Loading branch information
borg42 committed Nov 27, 2024
1 parent 6f81cc6 commit 8d6d14b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
21 changes: 20 additions & 1 deletion software/src/modules/eco/eco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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)},
Expand All @@ -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<Config::ConfObject>()
)}
});
}

Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions software/src/modules/eco/eco.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 9 additions & 1 deletion software/web/src/modules/eco/api.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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[],
}
23 changes: 19 additions & 4 deletions software/web/src/modules/eco/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Eco extends ConfigComponent<'eco/config', {status_ref?: RefObject<E
</FormRow>
<FormRow label="Modus nach Ablauf des Ladeplans">
<InputSelect
disabled={!state.charge_plan_active}
disabled={!day_ahead_prices_enabled || !state.charge_plan_active}
items={[
["0", "Schnell"],
["1", "Eco+PV"],
Expand All @@ -102,6 +102,21 @@ export class Eco extends ConfigComponent<'eco/config', {status_ref?: RefObject<E
onValue={(v) => this.setState({mode_after_charge_plan: parseInt(v)})}
/>
</FormRow>
<FormRow label="Maximale Standzeit" help="">
<SwitchableInputNumber
disabled={!day_ahead_prices_enabled || !state.charge_plan_active}
switch_label_active={__("eco.content.active")}
switch_label_inactive={__("eco.content.inactive")}
unit="h"
checked={state.service_life_active && day_ahead_prices_enabled && state.charge_plan_active}
onClick={this.toggle('service_life_active')}
value={state.service_life}
onValue={this.set("service_life")}
min={1}
max={48}
switch_label_min_width="100px"
/>
</FormRow>
<FormRow label="Immer laden wenn Preis unter" help="">
<SwitchableInputNumber
disabled={!day_ahead_prices_enabled}
Expand Down Expand Up @@ -196,7 +211,7 @@ export class EcoStatus extends Component<{}, EcoStatusState> {

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 <StatusSection name="eco">
Expand Down Expand Up @@ -233,8 +248,8 @@ export class EcoStatus extends Component<{}, EcoStatusState> {
<InputNumber
disabled={state.charge_plan.enabled}
unit="h"
value={state.charge_plan.hours}
onValue={(v) => 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}
/>
Expand Down

0 comments on commit 8d6d14b

Please sign in to comment.