Repository: evcc-io/evcc
Pull request #13561 (2024-04-23 16:47:51)

chore: rename api.ChargeTimer


Patch:
diff --git a/api/api.go b/api/api.go
index 6dab022f..77500df0 100644
--- a/api/api.go
+++ b/api/api.go
@@ -93,7 +93,7 @@ type Diagnosis interface {
 
 // ChargeTimer provides current charge cycle duration
 type ChargeTimer interface {
-	ChargingTime() (time.Duration, error)
+	ChargeDuration() (time.Duration, error)
 }
 
 // ChargeRater provides charged energy amount in kWh
diff --git a/charger/bender.go b/charger/bender.go
index d50bc12e..1267103a 100644
--- a/charger/bender.go
+++ b/charger/bender.go
@@ -203,8 +203,8 @@ func (wb *BenderCC) MaxCurrent(current int64) error {
 
 var _ api.ChargeTimer = (*BenderCC)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *BenderCC) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *BenderCC) ChargeDuration() (time.Duration, error) {
 	if wb.legacy {
 		b, err := wb.conn.ReadHoldingRegisters(bendRegChargingDurationLegacy, 1)
 		if err != nil {
diff --git a/charger/em2go-home.go b/charger/em2go-home.go
index c65acb8b..d0a185c6 100644
--- a/charger/em2go-home.go
+++ b/charger/em2go-home.go
@@ -233,8 +233,8 @@ func (wb *Em2GoHome) ChargedEnergy() (float64, error) {
 
 var _ api.ChargeTimer = (*Em2GoHome)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *Em2GoHome) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *Em2GoHome) ChargeDuration() (time.Duration, error) {
 	b, err := wb.conn.ReadHoldingRegisters(em2GoHomeRegChargeDuration, 2)
 	if err != nil {
 		return 0, err
diff --git a/charger/em2go.go b/charger/em2go.go
index 501b2da2..23cef988 100644
--- a/charger/em2go.go
+++ b/charger/em2go.go
@@ -221,8 +221,8 @@ func (wb *Em2Go) ChargedEnergy() (float64, error) {
 
 var _ api.ChargeTimer = (*Em2Go)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *Em2Go) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *Em2Go) ChargeDuration() (time.Duration, error) {
 	b, err := wb.conn.ReadHoldingRegisters(em2GoRegChargeDuration, 2)
 	if err != nil {
 		return 0, err
diff --git a/charger/etrel.go b/charger/etrel.go
index 92ac23bb..0e5e807b 100644
--- a/charger/etrel.go
+++ b/charger/etrel.go
@@ -221,8 +221,8 @@ func (wb *Etrel) Currents() (float64, float64, float64, error) {
 
 // var _ api.ChargeTimer = (*Etrel)(nil)
 //
-// // ChargingTime implements the api.ChargeTimer interface
-// func (wb *Etrel) ChargingTime() (time.Duration, error) {
+// // ChargeDuration implements the api.ChargeTimer interface
+// func (wb *Etrel) ChargeDuration() (time.Duration, error) {
 // 	b, err := wb.conn.ReadInputRegisters(wb.base+etrelRegChargeTime, 4)
 // 	if err != nil {
 // 		return 0, err
diff --git a/charger/hesotec.go b/charger/hesotec.go
index 1b591087..9a6b913e 100644
--- a/charger/hesotec.go
+++ b/charger/hesotec.go
@@ -154,8 +154,8 @@ func (wb *Hesotec) CurrentPower() (float64, error) {
 
 var _ api.ChargeTimer = (*Hesotec)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *Hesotec) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *Hesotec) ChargeDuration() (time.Duration, error) {
 	b, err := wb.conn.ReadHoldingRegisters(hesotecRegDuration, 2)
 	if err != nil {
 		return 0, err
diff --git a/charger/mcc.go b/charger/mcc.go
index 4dc7cca0..d3784247 100644
--- a/charger/mcc.go
+++ b/charger/mcc.go
@@ -340,8 +340,8 @@ func (mcc *MobileConnect) ChargedEnergy() (float64, error) {
 
 var _ api.ChargeTimer = (*MobileConnect)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (mcc *MobileConnect) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (mcc *MobileConnect) ChargeDuration() (time.Duration, error) {
 	var currentSession MCCCurrentSession
 	if err := mcc.getEscapedJSON(mcc.apiURL(mccAPICurrentSession), &currentSession); err != nil {
 		return 0, err
diff --git a/charger/mennekes-compact.go b/charger/mennekes-compact.go
index b713d0cc..36415328 100644
--- a/charger/mennekes-compact.go
+++ b/charger/mennekes-compact.go
@@ -248,8 +248,8 @@ func (wb *MennekesCompact) ChargedEnergy() (float64, error) {
 
 var _ api.ChargeTimer = (*MennekesCompact)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *MennekesCompact) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *MennekesCompact) ChargeDuration() (time.Duration, error) {
 	b, err := wb.conn.ReadHoldingRegisters(mennekesRegDurationSession, 2)
 	if err != nil {
 		return 0, err
diff --git a/charger/openevse.go b/charger/openevse.go
index 9aacdc0c..a0cab295 100644
--- a/charger/openevse.go
+++ b/charger/openevse.go
@@ -205,7 +205,7 @@ func (c *OpenEVSE) ChargedEnergy() (float64, error) {
 
 var _ api.ChargeTimer = (*OpenEVSE)(nil)
 
-func (c *OpenEVSE) ChargingTime() (time.Duration, error) {
+func (c *OpenEVSE) ChargeDuration() (time.Duration, error) {
 	res, err := c.statusG.Get()
 	if err != nil {
 		return 0, err
diff --git a/charger/phoenix-charx.go b/charger/phoenix-charx.go
index 7b3357cb..4aa61a07 100644
--- a/charger/phoenix-charx.go
+++ b/charger/phoenix-charx.go
@@ -180,8 +180,8 @@ func (wb *PhoenixCharx) MaxCurrent(current int64) error {
 
 var _ api.ChargeTimer = (*PhoenixCharx)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *PhoenixCharx) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *PhoenixCharx) ChargeDuration() (time.Duration, error) {
 	b, err := wb.conn.ReadHoldingRegisters(wb.register(charxRegChargeTime), 2)
 	if err != nil {
 		return 0, err
diff --git a/charger/phoenix-em-eth.go b/charger/phoenix-em-eth.go
index 7000834f..7d02b531 100644
--- a/charger/phoenix-em-eth.go
+++ b/charger/phoenix-em-eth.go
@@ -128,8 +128,8 @@ func (wb *PhoenixEMEth) MaxCurrent(current int64) error {
 
 var _ api.ChargeTimer = (*PhoenixEMEth)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *PhoenixEMEth) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *PhoenixEMEth) ChargeDuration() (time.Duration, error) {
 	b, err := wb.conn.ReadInputRegisters(phxEMEthRegChargeTime, 2)
 	if err != nil {
 		return 0, err
diff --git a/charger/schneider-v3.go b/charger/schneider-v3.go
index f743b064..569a8b5a 100644
--- a/charger/schneider-v3.go
+++ b/charger/schneider-v3.go
@@ -227,8 +227,8 @@ func (wb *Schneider) getPhaseValues(reg uint16) (float64, float64, float64, erro
 
 var _ api.ChargeTimer = (*Schneider)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *Schneider) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *Schneider) ChargeDuration() (time.Duration, error) {
 	b, err := wb.conn.ReadHoldingRegisters(schneiderRegSessionChargingTime, 2)
 	if err != nil {
 		return 0, err
diff --git a/charger/twc3.go b/charger/twc3.go
index 416e8848..9cb49ae3 100644
--- a/charger/twc3.go
+++ b/charger/twc3.go
@@ -168,8 +168,8 @@ func (v *Twc3) ChargedEnergy() (float64, error) {
 
 var _ api.ChargeTimer = (*Twc3)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (v *Twc3) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (v *Twc3) ChargeDuration() (time.Duration, error) {
 	res, err := v.vitalsG()
 	return time.Duration(res.SessionS) * time.Second, err
 }
diff --git a/charger/vestel.go b/charger/vestel.go
index 210b7d5d..f67be0d4 100644
--- a/charger/vestel.go
+++ b/charger/vestel.go
@@ -182,8 +182,8 @@ func (wb *Vestel) MaxCurrent(current int64) error {
 
 var _ api.ChargeTimer = (*Vestel)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *Vestel) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *Vestel) ChargeDuration() (time.Duration, error) {
 	b, err := wb.conn.ReadInputRegisters(vestelRegChargeTime, 2)
 	if err != nil {
 		return 0, err
diff --git a/charger/webasto-next.go b/charger/webasto-next.go
index d827ec90..4f009df3 100644
--- a/charger/webasto-next.go
+++ b/charger/webasto-next.go
@@ -181,8 +181,8 @@ func (wb *WebastoNext) MaxCurrent(current int64) error {
 
 var _ api.ChargeTimer = (*WebastoNext)(nil)
 
-// ChargingTime implements the api.ChargeTimer interface
-func (wb *WebastoNext) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (wb *WebastoNext) ChargeDuration() (time.Duration, error) {
 	b, err := wb.conn.ReadHoldingRegisters(tqRegChargingTime, 2)
 	if err != nil {
 		return 0, err
diff --git a/cmd/dumper.go b/cmd/dumper.go
index 3b82d1f4..afc0e525 100644
--- a/cmd/dumper.go
+++ b/cmd/dumper.go
@@ -133,7 +133,7 @@ func (d *dumper) Dump(name string, v interface{}) {
 	}
 
 	if v, ok := v.(api.ChargeTimer); ok {
-		if duration, err := v.ChargingTime(); err != nil {
+		if duration, err := v.ChargeDuration(); err != nil {
 			fmt.Fprintf(w, "Duration:\t%v\n", err)
 		} else {
 			fmt.Fprintf(w, "Duration:\t%v\n", duration.Truncate(time.Second))
diff --git a/core/loadpoint.go b/core/loadpoint.go
index 7f9aba93..3a2c6508 100644
--- a/core/loadpoint.go
+++ b/core/loadpoint.go
@@ -1394,7 +1394,7 @@ func (lp *Loadpoint) publishChargeProgress() {
 		lp.log.ERROR.Printf("charge rater: %v", err)
 	}
 
-	if d, err := lp.chargeTimer.ChargingTime(); err == nil {
+	if d, err := lp.chargeTimer.ChargeDuration(); err == nil {
 		lp.chargeDuration = d.Round(time.Second)
 	} else {
 		lp.log.ERROR.Printf("charge timer: %v", err)
diff --git a/core/wrapper/chargetimer.go b/core/wrapper/chargetimer.go
index bf3f44ce..8279fe88 100644
--- a/core/wrapper/chargetimer.go
+++ b/core/wrapper/chargetimer.go
@@ -48,8 +48,8 @@ func (m *ChargeTimer) StopCharge() {
 	m.duration += m.clck.Since(m.start)
 }
 
-// ChargingTime implements the api.ChargeTimer interface
-func (m *ChargeTimer) ChargingTime() (time.Duration, error) {
+// ChargeDuration implements the api.ChargeTimer interface
+func (m *ChargeTimer) ChargeDuration() (time.Duration, error) {
 	m.Lock()
 	defer m.Unlock()
 


Test patch:
diff --git a/charger/mcc_test.go b/charger/mcc_test.go
index 9720f6a7..1cfa41ba 100644
--- a/charger/mcc_test.go
+++ b/charger/mcc_test.go
@@ -369,13 +369,13 @@ func TestMobileConnectChargingTime(t *testing.T) {
 		t.Run(tc.name, func(t *testing.T) {
 			mcc := NewTestMobileConnect(t, tc.responses)
 
-			got, err := mcc.ChargingTime()
+			got, err := mcc.ChargeDuration()
 			if (err != nil) != tc.wantErr {
-				t.Errorf("MobileConnect.ChargingTime() error = %v, wantErr %v", err, tc.wantErr)
+				t.Errorf("MobileConnect.ChargeDuration() error = %v, wantErr %v", err, tc.wantErr)
 				return
 			}
 			if got != tc.want {
-				t.Errorf("MobileConnect.ChargingTime() = %v, want %v", got, tc.want)
+				t.Errorf("MobileConnect.ChargeDuration() = %v, want %v", got, tc.want)
 			}
 		})
 	}
diff --git a/core/loadpoint_test.go b/core/loadpoint_test.go
index ecd6e472..92ecbaf1 100644
--- a/core/loadpoint_test.go
+++ b/core/loadpoint_test.go
@@ -29,7 +29,7 @@ func (n *Null) ChargedEnergy() (float64, error) {
 	return 0, nil
 }
 
-func (n *Null) ChargingTime() (time.Duration, error) {
+func (n *Null) ChargeDuration() (time.Duration, error) {
 	return 0, nil
 }
 
diff --git a/core/wrapper/chargetimer_test.go b/core/wrapper/chargetimer_test.go
index a75192ca..f9746166 100644
--- a/core/wrapper/chargetimer_test.go
+++ b/core/wrapper/chargetimer_test.go
@@ -17,7 +17,7 @@ func TestTimer(t *testing.T) {
 	ct.StopCharge()
 	clck.Add(time.Hour)
 
-	if d, err := ct.ChargingTime(); d != 1*time.Hour || err != nil {
+	if d, err := ct.ChargeDuration(); d != 1*time.Hour || err != nil {
 		t.Error(d, err)
 	}
 
@@ -26,7 +26,7 @@ func TestTimer(t *testing.T) {
 	clck.Add(2 * time.Hour)
 	ct.StopCharge()
 
-	if d, err := ct.ChargingTime(); d != 3*time.Hour || err != nil {
+	if d, err := ct.ChargeDuration(); d != 3*time.Hour || err != nil {
 		t.Error(d, err)
 	}
 }