Zaptec: detect cable swap between vehicles via session identifier

This commit is contained in:
andig 2026-07-15 14:59:41 +02:00 • committed by GitHub
parent 8fe199dc26
commit 75cb289a61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -55,6 +55,9 @@ type Zaptec struct {
priority bool
passive bool
lastStatus int
session string // last seen SessionIdentifier
sessionStart time.Time // start of the current session
}
func init() {
@ -325,6 +328,33 @@ func (c *Zaptec) ChargedEnergy() (float64, error) {
return res.ObservationByID(zaptec.TotalChargePowerSession).Float64()
}
var _ api.ConnectionTimer = (*Zaptec)(nil)
// ConnectionDuration implements the api.ConnectionTimer interface.
// Derived from SessionIdentifier: a session change drops the duration, so the loadpoint detects a cable swap as reconnect.
func (c *Zaptec) ConnectionDuration() (time.Duration, error) {
res, err := c.statusG.Get()
if err != nil {
return 0, err
}
var session string
if o := res.ObservationByID(zaptec.SessionIdentifier); o != nil {
session = o.ValueAsString
}
if session != c.session {
c.session = session
c.sessionStart = time.Now()
}
if session == "" {
return 0, nil
}
return time.Since(c.sessionStart), nil
}
var _ api.PhaseCurrents = (*Zaptec)(nil)
// Currents implements the api.PhaseCurrents interface