From b01b1830d24d27aa61950b0bf2bad628a140fc8c Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 10 Nov 2022 16:02:42 +0100 Subject: [PATCH] Enyaq: add soc limit --- vehicle/skoda/provider.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/vehicle/skoda/provider.go b/vehicle/skoda/provider.go index d05c084d7..4002aa803 100644 --- a/vehicle/skoda/provider.go +++ b/vehicle/skoda/provider.go @@ -9,9 +9,10 @@ import ( // Provider implements the evcc vehicle api type Provider struct { - statusG func() (StatusResponse, error) - chargerG func() (ChargerResponse, error) - action func(action, value string) error + statusG func() (StatusResponse, error) + chargerG func() (ChargerResponse, error) + settingsG func() (SettingsResponse, error) + action func(action, value string) error } // NewProvider provides the evcc vehicle api provider @@ -26,6 +27,9 @@ func NewProvider(api *API, vin string, cache time.Duration) *Provider { // climateG: provider.Cached(func() (interface{}, error) { // return api.Climater(vin) // }, cache), + settingsG: provider.Cached(func() (SettingsResponse, error) { + return api.Settings(vin) + }, cache), action: func(action, value string) error { return api.Action(vin, action, value) }, @@ -121,6 +125,18 @@ func (v *Provider) Odometer() (odo float64, err error) { // return active, outsideTemp, targetTemp, err // } +var _ api.SocLimiter = (*Provider)(nil) + +// TargetSoC implements the api.SocLimiter interface +func (v *Provider) TargetSoC() (float64, error) { + res, err := v.settingsG() + if err == nil { + return float64(res.TargetStateOfChargeInPercent), nil + } + + return 0, err +} + var _ api.VehicleChargeController = (*Provider)(nil) // StartCharge implements the api.VehicleChargeController interface