Repository: evcc-io/evcc
Pull request #2719 (2022-02-26 17:40:03)

Warn when other phases than L1 are active
Refs https://github.com/evcc-io/evcc/discussions/2716

premultiply: Wenn dann sollte das auch für 2p funktionieren.
andig: Das sollte es aktuell schon- auch bei 2p müsste L1 aktiv sein und nicht erst L2! Ok?
premultiply: Ich meinte damit dass bei 1p genau nur L1 und nicht L2 und nicht L3 aktiv sein dürfen,
bei 2p genau L1 und L2 aktiv und L3 nicht aktiv sein dürfen.
andig: Der Code testet, dass bei Aktivität von L2 oder L3 auch L1 aktiv sein muss- er testet nicht auf Vertauschung von L2/L3. Brauchen wir das auch? Dann wirds wieder komplexer...
premultiply: Wenn schon, denn schon:
![grafik](https://user-images.githubusercontent.com/4681172/155881102-e423e62f-33cf-49b8-9564-2c28c242f621.png)


Patch:
diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml
index 6a20e6e4..f86e5982 100644
--- a/.github/workflows/default.yml
+++ b/.github/workflows/default.yml
@@ -29,7 +29,7 @@ jobs:
       uses: actions/cache@v2
       with:
         path: |
-          ~/go/pkg/mod
+          ~/go/pkg
           ~/.cache/go-build
         key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
         restore-keys: |
@@ -62,7 +62,6 @@ jobs:
       uses: golangci/golangci-lint-action@v3
       with:
         version: latest
-        skip-go-installation: true
         skip-pkg-cache: true
         skip-build-cache: true
     - name: Test
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index 6d54b9ed..68947b6e 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -74,7 +74,7 @@ jobs:
       uses: actions/cache@v2
       with:
         path: |
-          ~/go/pkg/mod
+          ~/go/pkg
           ~/.cache/go-build
         key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
         restore-keys: |
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 5517469c..3bc4edbf 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -54,7 +54,7 @@ jobs:
       uses: actions/cache@v2
       with:
         path: |
-          ~/go/pkg/mod
+          ~/go/pkg
           ~/.cache/go-build
         key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
         restore-keys: |
diff --git a/charger/go-e.go b/charger/go-e.go
index 60cfa18c..73921221 100644
--- a/charger/go-e.go
+++ b/charger/go-e.go
@@ -74,7 +74,7 @@ func NewGoE(uri, token string, cache time.Duration) (api.Charger, error) {
 	if token != "" {
 		c.api = goe.NewCloud(log, token, cache)
 	} else {
-		c.api = goe.NewLocal(log, util.DefaultScheme(uri, "http"))
+		c.api = goe.NewLocal(log, util.DefaultScheme(uri, "http"), cache)
 	}
 
 	if c.api.IsV2() {
diff --git a/charger/go-e/api.go b/charger/go-e/api.go
index df2c7a5b..9be034e3 100644
--- a/charger/go-e/api.go
+++ b/charger/go-e/api.go
@@ -32,19 +32,23 @@ type API interface {
 
 type LocalAPI struct {
 	*request.Helper
-	uri string
-	v2  bool
+	uri     string
+	v2      bool
+	status  Response
+	updated time.Time
+	cache   time.Duration
 }
 
 var _ API = (*LocalAPI)(nil)
 
-func NewLocal(log *util.Logger, uri string) *LocalAPI {
+func NewLocal(log *util.Logger, uri string, cache time.Duration) *LocalAPI {
 	uri = strings.TrimRight(uri, "/")
 	uri = strings.TrimSuffix(uri, "/api")
 
 	api := &LocalAPI{
 		Helper: request.NewHelper(log),
 		uri:    uri,
+		cache:  cache,
 	}
 
 	api.upgradeV2()
@@ -78,20 +82,25 @@ func (c *LocalAPI) response(partial string, res interface{}) error {
 }
 
 // Status reads a v1/v2 api response
-func (c *LocalAPI) Status() (Response, error) {
-	if c.v2 {
-		res := new(StatusResponse2)
-		err := c.response("status?filter=alw,car,eto,nrg,wh,trx,cards", &res)
-		return res, err
+func (c *LocalAPI) Status() (res Response, err error) {
+	if time.Since(c.updated) > c.cache {
+		if c.v2 {
+			c.status = new(StatusResponse2)
+			err = c.response("status?filter=alw,car,eto,nrg,wh,trx,cards", &c.status)
+		} else {
+			c.status = new(StatusResponse)
+			err = c.response("status", &c.status)
+		}
+		if err == nil {
+			c.updated = time.Now()
+		}
 	}
-
-	res := new(StatusResponse)
-	err := c.response("status", &res)
-	return res, err
+	return c.status, err
 }
 
 // Update executes a v1/v2 api update and returns the response
 func (c *LocalAPI) Update(payload string) error {
+	c.updated = time.Time{}
 	res := new(UpdateResponse)
 
 	if c.v2 {
diff --git a/cmd/demo.yaml b/cmd/demo.yaml
index 8cee36c3..bb7abeac 100644
--- a/cmd/demo.yaml
+++ b/cmd/demo.yaml
@@ -21,7 +21,7 @@ meters:
 - name: grid
   type: custom
   power:
-    type: js
+    source: js
     vm: shared
     script: |
       state.pvpower += 200*(Math.random()-0.5);
@@ -45,28 +45,28 @@ meters:
 - name: pv
   type: custom
   power:
-    type: js
+    source: js
     vm: shared
     script: state.pvpower
 
 - name: battery
   type: custom
   power:
-    type: js
+    source: js
     vm: shared
     script: state.batterypower;
   soc:
-    type: js
+    source: js
     vm: shared
     script: "30"
 - name: charge
   type: custom
   power:
-    type: js
+    source: js
     vm: shared
     script: state.chargepower;
   soc:
-    type: js
+    source: js
     vm: shared
     script: "30"
 
@@ -74,21 +74,21 @@ chargers:
 - name: demo
   type: custom
   enable:
-    type: js
+    source: js
     vm: shared
     script: state.enabled = val;
   enabled:
-    type: js
+    source: js
     vm: shared
     script: |
       state.enabled;
   status:
-    type: js
+    source: js
     vm: shared
     script: |
       if (state.enabled) "C"; else "B";
   maxcurrent:
-    type: js
+    source: js
     vm: shared
     script: state.maxcurrent = val;
 
@@ -97,7 +97,7 @@ vehicles:
   title: e-Golf
   type: custom
   soc:
-    type: js
+    source: js
     vm: shared
     script: |
       if (state.chargepower > 0) state.battery++; else state.battery--;
diff --git a/core/loadpoint.go b/core/loadpoint.go
index d3384981..80ff7ae4 100644
--- a/core/loadpoint.go
+++ b/core/loadpoint.go
@@ -1327,8 +1327,11 @@ func (lp *LoadPoint) updateChargeCurrents() {
 
 	if lp.charging() {
 		var phases int
-		for _, i := range lp.chargeCurrents {
+		for l, i := range lp.chargeCurrents {
 			if i >= minActiveCurrent {
+				if l > 0 && phases == 0 {
+					lp.log.WARN.Printf("invalid wiring: phase %d observed active should be first phase", l+1)
+				}
 				phases++
 			}
 		}
diff --git a/util/goversion/constraint.go b/util/goversion/constraint.go
index a6b7a7c2..7aee559a 100644
--- a/util/goversion/constraint.go
+++ b/util/goversion/constraint.go
@@ -1,8 +1,8 @@
 // Approach from https://github.com/theckman/goconstraint/
 
 // Package goversion should only be used as a blank import. If imported, it
-// will only compile if the Go runtime version is >= 1.16.
+// will only compile if the Go runtime version is >= 1.17.
 package goversion
 
-// This will fail to compile if the Go runtime version isn't >= 1.16.
-var _ = __EVCC_REQUIRES_GO_VERSION_1_16__
+// This will fail to compile if the Go runtime version isn't >= 1.17.
+var _ = __EVCC_REQUIRES_GO_VERSION_1_17__
diff --git a/util/goversion/version.go b/util/goversion/version.go
index 441eced4..637a8029 100644
--- a/util/goversion/version.go
+++ b/util/goversion/version.go
@@ -1,6 +1,6 @@
-//go:build go1.16
-// +build go1.16
+//go:build go1.17
+// +build go1.17
 
 package goversion
 
-const __EVCC_REQUIRES_GO_VERSION_1_16__ = uint8(0)
+const __EVCC_REQUIRES_GO_VERSION_1_17__ = uint8(0)


Test patch:
diff --git a/charger/go-e/api_test.go b/charger/go-e/api_test.go
index b96ebc9c..e92363d7 100644
--- a/charger/go-e/api_test.go
+++ b/charger/go-e/api_test.go
@@ -37,7 +37,7 @@ func TestLocalV1(t *testing.T) {
 	srv := httptest.NewServer(h)
 
 	// h.expect("/api/status?filter=alw")
-	local := NewLocal(util.NewLogger("foo"), srv.URL)
+	local := NewLocal(util.NewLogger("foo"), srv.URL, 0)
 
 	h.expect("/status")
 	if _, err := local.Status(); err != nil {
@@ -54,7 +54,7 @@ func TestLocalV2(t *testing.T) {
 	srv := httptest.NewServer(h)
 
 	h.expect("/api/status?filter=alw")
-	local := NewLocal(util.NewLogger("foo"), srv.URL)
+	local := NewLocal(util.NewLogger("foo"), srv.URL, 0)
 
 	h.expect("/api/status?filter=alw,car,eto,nrg,wh,trx,cards")
 	if _, err := local.Status(); err != nil {