Ocpp: fix connector not de-registered (#22113)

This commit is contained in:
andig 2025-08-03 14:24:33 +02:00 • committed by GitHub
parent 241f336247
commit 6f65584e87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 23 additions and 7 deletions

View file

@ -252,10 +252,10 @@ export default defineComponent({
);
},
normalParams() {
return this.templateParams.filter((p) => !p.Advanced);
return this.templateParams.filter((p) => !p.Advanced && !p.Deprecated);
},
advancedParams() {
return this.templateParams.filter((p) => p.Advanced);
return this.templateParams.filter((p) => p.Advanced || p.Deprecated);
},
modbus() {
const params = this.template?.Params || [];

View file

@ -76,7 +76,7 @@ export default {
case "phasePowers":
return value.map((v) => this.fmtW(v, POWER_UNIT.KW, false)).join(" · ") + " kW";
case "chargeStatus":
return this.$t(`config.deviceValue.chargeStatus${value}`);
return value ? this.$t(`config.deviceValue.chargeStatus${value}`) : "-";
case "gridPrice":
case "feedinPrice":
return this.fmtPricePerKWh(value, options.currency, true);

View file

@ -30,6 +30,7 @@ export const performTest = async (
state.isSuccess = false;
state.isError = false;
state.isRunning = true;
state.error = null;
state.errorLine = null;
try {
const res = await api();

View file

@ -178,7 +178,7 @@ func NewOCPP(ctx context.Context,
idTag = lo.CoalesceOrEmpty(idTag, cp.IdTag, defaultIdTag)
}
conn, err := ocpp.NewConnector(log, connector, cp, idTag, meterInterval)
conn, err := ocpp.NewConnector(ctx, log, connector, cp, idTag, meterInterval)
if err != nil {
return nil, err
}

View file

@ -36,7 +36,7 @@ type Connector struct {
meterInterval time.Duration
}
func NewConnector(log *util.Logger, id int, cp *CP, idTag string, meterInterval time.Duration) (*Connector, error) {
func NewConnector(ctx context.Context, log *util.Logger, id int, cp *CP, idTag string, meterInterval time.Duration) (*Connector, error) {
conn := &Connector{
log: log,
cp: cp,
@ -53,6 +53,12 @@ func NewConnector(log *util.Logger, id int, cp *CP, idTag string, meterInterval
return nil, err
}
go func() {
// deregister connector when the context is cancelled
<-ctx.Done()
cp.deregisterConnector(conn.id)
}()
// trigger status for all connectors
var ok bool

View file

@ -1,6 +1,7 @@
package ocpp
import (
"context"
"testing"
"time"
@ -26,7 +27,7 @@ func (suite *connTestSuite) SetupTest() {
// setup instance
Instance()
suite.cp = NewChargePoint(util.NewLogger("foo"), "abc")
suite.conn, _ = NewConnector(util.NewLogger("foo"), 1, suite.cp, "", Timeout)
suite.conn, _ = NewConnector(context.TODO(), util.NewLogger("foo"), 1, suite.cp, "", Timeout)
suite.clock = clock.NewMock()
suite.conn.clock = suite.clock

View file

@ -67,6 +67,13 @@ func (cp *CP) registerConnector(id int, conn *Connector) error {
return nil
}
func (cp *CP) deregisterConnector(id int) {
cp.mu.Lock()
defer cp.mu.Unlock()
delete(cp.connectors, id)
}
func (cp *CP) connectorByID(id int) *Connector {
cp.mu.RLock()
defer cp.mu.RUnlock()

View file

@ -601,8 +601,9 @@ func testConfigHandler(w http.ResponseWriter, r *http.Request) {
return
}
// prevent context from being cancelled
// prevent context from being cancelled during test
close(done)
defer cancel()
jsonWrite(w, testInstance(instance))
}