From 80c7aac21ad237b39752c3d9789d8d1297b9502d Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 20 Apr 2022 18:04:31 +0200 Subject: [PATCH] HardyBarth cPH2: update api and require sponsorship (#3197) --- charger/echarge/salia/types.go | 4 +++- charger/hardybarth-salia.go | 19 ++++++++++++------- .../definition/charger/hardybarth-ecb1.yaml | 2 +- .../definition/charger/hardybarth-salia.yaml | 4 +++- templates/docs/charger/hardybarth-ecb1_0.yaml | 2 +- .../docs/charger/hardybarth-salia_0.yaml | 3 ++- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/charger/echarge/salia/types.go b/charger/echarge/salia/types.go index e6f3794bb..e03b1eef7 100644 --- a/charger/echarge/salia/types.go +++ b/charger/echarge/salia/types.go @@ -3,6 +3,7 @@ package salia const ( HeartBeat = "salia/heartbeat" ChargeMode = "salia/chargemode" + PauseCharging = "salia/pausecharging" GridCurrentLimit = "grid_current_limit" ) @@ -32,7 +33,8 @@ type Port struct { } } Salia struct { - ChargeMode string + ChargeMode string + PauseCharging int `json:"pausecharging,string"` } Metering struct { Meter struct { diff --git a/charger/hardybarth-salia.go b/charger/hardybarth-salia.go index fcd57bc23..39dfd0d05 100644 --- a/charger/hardybarth-salia.go +++ b/charger/hardybarth-salia.go @@ -29,6 +29,7 @@ import ( "github.com/evcc-io/evcc/charger/echarge/salia" "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/request" + "github.com/evcc-io/evcc/util/sponsor" ) // http://apidoc.ecb1.de @@ -51,7 +52,7 @@ func init() { //go:generate go run ../cmd/tools/decorate.go -f decorateSalia -b *Salia -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)" -// NewSaliaFromConfig creates a Salia cPH1 charger from generic config +// NewSaliaFromConfig creates a Salia cPH2 charger from generic config func NewSaliaFromConfig(other map[string]interface{}) (api.Charger, error) { cc := struct { URI string @@ -84,9 +85,9 @@ func NewSalia(uri string, cache time.Duration) (api.Charger, error) { cache: cache, } - // if !sponsor.IsAuthorized() { - // return nil, api.ErrSponsorRequired - // } + if !sponsor.IsAuthorized() { + return nil, api.ErrSponsorRequired + } err := wb.post(salia.ChargeMode, echarge.ModeManual) if err == nil { @@ -102,8 +103,7 @@ func NewSalia(uri string, cache time.Duration) (api.Charger, error) { } func (wb *Salia) heartbeat() { - _ = wb.post(salia.HeartBeat, "alive") - for range time.NewTicker(30 * time.Second).C { + for ; true; <-time.NewTicker(30 * time.Second).C { if err := wb.post(salia.HeartBeat, "alive"); err != nil { wb.log.ERROR.Println("heartbeat:", err) } @@ -164,7 +164,7 @@ func (wb *Salia) Enabled() (bool, error) { if err == nil && res.Secc.Port0.Salia.ChargeMode != echarge.ModeManual { err = fmt.Errorf("invalid mode: %s", res.Secc.Port0.Salia.ChargeMode) } - return res.Secc.Port0.GridCurrentLimit > 0, err + return res.Secc.Port0.GridCurrentLimit > 0 && res.Secc.Port0.Salia.PauseCharging == 0, err } // Enable implements the api.Charger interface @@ -175,6 +175,11 @@ func (wb *Salia) Enable(enable bool) error { } err := wb.setCurrent(current) + if err == nil { + // ignore error for FW <1.52 + var offOn = map[bool]string{false: "1", true: "0"} + _ = wb.post(salia.PauseCharging, offOn[enable]) + } if err == nil { wb.updated = time.Time{} } diff --git a/templates/definition/charger/hardybarth-ecb1.yaml b/templates/definition/charger/hardybarth-ecb1.yaml index d09f278e5..b11c9154c 100644 --- a/templates/definition/charger/hardybarth-ecb1.yaml +++ b/templates/definition/charger/hardybarth-ecb1.yaml @@ -2,7 +2,7 @@ template: hardybarth-ecb1 products: - brand: HardyBarth description: - generic: cPH1 eCB1 Controller + generic: cPH1 (eCB1 Controller) requirements: evcc: ["sponsorship"] params: diff --git a/templates/definition/charger/hardybarth-salia.yaml b/templates/definition/charger/hardybarth-salia.yaml index 7660430c9..c95e39878 100644 --- a/templates/definition/charger/hardybarth-salia.yaml +++ b/templates/definition/charger/hardybarth-salia.yaml @@ -2,7 +2,9 @@ template: hardybarth-salia products: - brand: HardyBarth description: - generic: Salia PLCC Controller + generic: cPH2 (Salia PLCC Controller) +requirements: + evcc: ["sponsorship"] params: - name: host render: | diff --git a/templates/docs/charger/hardybarth-ecb1_0.yaml b/templates/docs/charger/hardybarth-ecb1_0.yaml index 1862879e0..1116b7415 100644 --- a/templates/docs/charger/hardybarth-ecb1_0.yaml +++ b/templates/docs/charger/hardybarth-ecb1_0.yaml @@ -1,6 +1,6 @@ product: brand: HardyBarth - description: cPH1 eCB1 Controller + description: cPH1 (eCB1 Controller) requirements: ["sponsorship"] render: - default: | diff --git a/templates/docs/charger/hardybarth-salia_0.yaml b/templates/docs/charger/hardybarth-salia_0.yaml index 718f7dd24..5c4b0b49d 100644 --- a/templates/docs/charger/hardybarth-salia_0.yaml +++ b/templates/docs/charger/hardybarth-salia_0.yaml @@ -1,6 +1,7 @@ product: brand: HardyBarth - description: Salia PLCC Controller + description: cPH2 (Salia PLCC Controller) +requirements: ["sponsorship"] render: - default: | type: template