diff --git a/meter/usage_battery_test.go b/meter/usage_battery_test.go new file mode 100644 index 000000000..7590b5afd --- /dev/null +++ b/meter/usage_battery_test.go @@ -0,0 +1,69 @@ +package meter + +import ( + "testing" + + "github.com/evcc-io/evcc/util" + "github.com/stretchr/testify/require" +) + +func TestBatterySocLimits(t *testing.T) { + other := map[string]any{ + "minsoc": 1, + "maxsoc": 99, + } + + expected := batterySocLimits{ + MinSoc: 1, + MaxSoc: 99, + } + + { + var res batterySocLimits + require.NoError(t, util.DecodeOther(other, &res)) + require.Equal(t, expected, res) + } + + { + var res struct { + batterySocLimits `mapstructure:",squash"` + } + require.NoError(t, util.DecodeOther(other, &res)) + require.Equal(t, expected, res.batterySocLimits) + } + + { + var res struct { + BatterySocLimits batterySocLimits `mapstructure:",squash"` + } + require.NoError(t, util.DecodeOther(other, &res)) + require.Equal(t, expected, res.BatterySocLimits) + } + + { + res := struct { + batterySocLimits `mapstructure:",squash"` + }{ + batterySocLimits: batterySocLimits{ + MinSoc: 20, + MaxSoc: 95, + }, + } + require.NoError(t, util.DecodeOther(other, &res)) + require.Equal(t, expected, res.batterySocLimits) + } + + { + res := struct { + pvMaxACPower `mapstructure:",squash"` + batterySocLimits `mapstructure:",squash"` + }{ + batterySocLimits: batterySocLimits{ + MinSoc: 20, + MaxSoc: 95, + }, + } + require.NoError(t, util.DecodeOther(other, &res)) + require.Equal(t, expected, res.batterySocLimits) + } +}