Zaptec: detect cable swap between vehicles via session identifier
This commit is contained in:
parent
8fe199dc26
commit
75cb289a61
1 changed files with 30 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue