From 146c88112d2d836fa5bf4ad70cc1f197e132850c Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 4 Aug 2023 17:12:52 +0200 Subject: [PATCH] OpenWB-Pro: support reading initial soc (#9247) --- charger/openwb-pro.go | 18 +++++++++++++++++- charger/openwb/pro/types.go | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/charger/openwb-pro.go b/charger/openwb-pro.go index f79868e74..5f6db894f 100644 --- a/charger/openwb-pro.go +++ b/charger/openwb-pro.go @@ -151,7 +151,7 @@ func (wb *OpenWBPro) TotalEnergy() (float64, error) { var _ api.PhaseCurrents = (*OpenWBPro)(nil) -// Currents implements the api.PhaseCurrentss interface +// Currents implements the api.PhaseCurrents interface func (wb *OpenWBPro) Currents() (float64, float64, float64, error) { res, err := wb.statusCache.Get() if err != nil { @@ -165,6 +165,22 @@ func (wb *OpenWBPro) Currents() (float64, float64, float64, error) { return res.Currents[0], res.Currents[1], res.Currents[2], err } +var _ api.Battery = (*OpenWBPro)(nil) + +// Soc implements the api.Battery interface +func (wb *OpenWBPro) Soc() (float64, error) { + res, err := wb.statusCache.Get() + if err != nil { + return 0, err + } + + if time.Since(time.Unix(res.SocTimestamp, 0)) > 5*time.Minute { + return 0, api.ErrNotAvailable + } + + return float64(res.Soc), nil +} + var _ api.PhaseSwitcher = (*OpenWBPro)(nil) // Phases1p3p implements the api.PhaseSwitcher interface diff --git a/charger/openwb/pro/types.go b/charger/openwb/pro/types.go index 92441570f..5c211f1ba 100644 --- a/charger/openwb/pro/types.go +++ b/charger/openwb/pro/types.go @@ -18,5 +18,7 @@ type Status struct { OfferedCurrent float64 `json:"offered_current"` EvseSignaling string `json:"evse_signaling"` VehicleID string `json:"vehicle_id"` + Soc int `json:"soc_value"` + SocTimestamp int64 `json:"soc_timestamp"` Serial string }