Skip to content

Commit

Permalink
Loadpoint: cleanup phase configuration and drop deprecations (#18638)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Feb 9, 2025
1 parent f93ceff commit 07fb01d
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 184 deletions.
14 changes: 7 additions & 7 deletions assets/js/components/Config/LoadpointModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
>
<SelectGroup
id="loadpointParamPhases"
v-model="values.phases"
v-model="values.phasesConfigured"
class="w-100"
:options="[
{ value: 1, name: $t('config.loadpoint.phases1p') },
Expand Down Expand Up @@ -559,7 +559,7 @@ const nsPerMin = 60 * 1e9;
const defaultValues = {
title: "",
phases: 3,
phasesConfigured: 3,
minCurrent: 6,
maxCurrent: 16,
priority: 0,
Expand Down Expand Up @@ -813,17 +813,17 @@ export default {
}
},
updatePhases() {
const { phases } = this.values;
const { phasesConfigured } = this.values;
if (this.chargerIsSinglePhase) {
this.values.phases = 1;
this.values.phasesConfigured = 1;
return;
}
if (this.chargerSupports1p3p && this.isNew) {
this.values.phases = 0; // automatic
this.values.phasesConfigured = 0; // automatic
return;
}
if (!this.chargerSupports1p3p && phases === 0) {
this.values.phases = 3; // no automatic switching, default to 3-phase
if (!this.chargerSupports1p3p && phasesConfigured === 0) {
this.values.phasesConfigured = 3; // no automatic switching, default to 3-phase
return;
}
},
Expand Down
1 change: 0 additions & 1 deletion assets/js/components/Loadpoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export default {
chargeRemainingDuration: Number,
// other information
phases: Number,
phasesConfigured: Number,
phasesActive: Number,
chargerPhases1p3p: Boolean,
Expand Down
5 changes: 2 additions & 3 deletions assets/js/components/LoadpointSettingsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ export default {
props: {
id: [String, Number],
phasesConfigured: Number,
phasesActive: Number,
chargerPhases1p3p: Boolean,
chargerSinglePhase: Boolean,
batteryBoost: Boolean,
Expand Down Expand Up @@ -237,7 +236,7 @@ export default {
return this.maxPowerPhases(this.phasesConfigured);
}
}
return this.fmtW(this.maxCurrent * V * this.phasesActive);
return this.fmtW(this.maxCurrent * V * this.phasesConfigured);
},
minPower() {
if (this.chargerPhases1p3p) {
Expand All @@ -248,7 +247,7 @@ export default {
return this.minPowerPhases(this.phasesConfigured);
}
}
return this.fmtW(this.minCurrent * V * this.phasesActive);
return this.fmtW(this.minCurrent * V * this.phasesConfigured);
},
minCurrentOptions() {
const opt1 = [...range(Math.floor(this.maxCurrent), 1), 0.5, 0.25, 0.125];
Expand Down
1 change: 1 addition & 0 deletions assets/js/views/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
:key="loadpoint.name"
:name="loadpoint.title"
:editable="!!loadpoint.id"
:error="deviceError('loadpoint', loadpoint.name)"
data-testid="loadpoint"
@edit="editLoadpoint(loadpoint.id)"
>
Expand Down
12 changes: 8 additions & 4 deletions cmd/class_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
ClassInflux
ClassMessenger
ClassSponsorship
ClassLoadpoint
)

// FatalError is an error that can be marshaled
Expand Down Expand Up @@ -57,7 +58,7 @@ type DeviceError struct {
}

func (e *DeviceError) Error() string {
return e.err.Error()
return "[" + e.Name + "] " + e.err.Error()
}

// ClassError indicates the class of devices that failed
Expand All @@ -67,7 +68,7 @@ type ClassError struct {
}

func (e *ClassError) Error() string {
return e.err.Error()
return e.Class.String() + " " + e.err.Error()
}

func (e ClassError) MarshalJSON() ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ func TestError(t *testing.T) {

b, err := res.MarshalJSON()
require.NoError(t, err)
require.Equal(t, `{"class":"meter","device":"0815","error":"foo"}`, string(b))
require.Equal(t, `{"class":"meter","device":"0815","error":"[0815] foo"}`, string(b))
}
18 changes: 9 additions & 9 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func configureSiteAndLoadpoints(conf *globalconfig.All) (*core.Site, error) {
}

if err := configureLoadpoints(*conf); err != nil {
return nil, fmt.Errorf("failed configuring loadpoints: %w", err)
return nil, &ClassError{ClassLoadpoint, err}
}

tariffs, err := configureTariffs(conf.Tariffs)
Expand Down Expand Up @@ -945,7 +945,7 @@ func configureLoadpoints(conf globalconfig.All) error {

instance, err := core.NewLoadpointFromConfig(log, settings, cc.Other)
if err != nil {
return fmt.Errorf("failed configuring loadpoint: %w", err)
return &DeviceError{cc.Name, err}
}

if err := config.Loadpoints().Add(config.NewStaticDevice(cc, loadpoint.API(instance))); err != nil {
Expand All @@ -970,21 +970,21 @@ func configureLoadpoints(conf globalconfig.All) error {

dynamic, static, err := loadpoint.SplitConfig(cc.Other)
if err != nil {
return fmt.Errorf("failed configuring loadpoint: %w", err)
return &DeviceError{cc.Name, err}
}

instance, err := core.NewLoadpointFromConfig(log, settings, static)
if err != nil {
return fmt.Errorf("failed configuring loadpoint: %w", err)
}

if err := dynamic.Apply(instance); err != nil {
return err
return &DeviceError{cc.Name, err}
}

dev := config.NewConfigurableDevice[loadpoint.API](&conf, instance)
if err := config.Loadpoints().Add(dev); err != nil {
return err
return &DeviceError{cc.Name, err}
}

if err := dynamic.Apply(instance); err != nil {
return &DeviceError{cc.Name, err}
}
}

Expand Down
4 changes: 1 addition & 3 deletions core/keys/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ const (
DisableDelay = "disableDelay"
BatteryBoost = "batteryBoost"

Phases = "phases" // configured phases (1/3, 0 for auto on 1p3p chargers, nil for plain chargers)
PhasesConfigured = "phasesConfigured" // TODO mirrors "phases" for UI purposes
PhasesEnabled = "phasesEnabled" // enabled phases (1/3)
PhasesConfigured = "phasesConfigured" // desired phase mode (0/1/3, 0 = automatic), user selection
PhasesActive = "phasesActive" // active phases as used by vehicle (1/2/3)

ChargerIcon = "chargerIcon" // charger icon for ui
Expand Down
Loading

0 comments on commit 07fb01d

Please sign in to comment.