MCPcopy Create free account
hub / github.com/evcc-io/evcc / getStatusChanges

Method getStatusChanges

core/loadpoint.go:1185–1218  ·  view source on GitHub ↗

getStatusChanges checks charger status and returns a chronological list of status changes

()

Source from the content-addressed store, hash-verified

1183
1184// getStatusChanges checks charger status and returns a chronological list of status changes
1185func (lp *Loadpoint) getStatusChanges() ([]api.ChargeStatus, error) {
1186 var res []api.ChargeStatus
1187
1188 status, err := lp.charger.Status()
1189 if err != nil {
1190 return nil, fmt.Errorf("charger status: %w", err)
1191 }
1192
1193 lp.log.DEBUG.Printf("charger status: %s", status)
1194
1195 // detect if charger status changed
1196 prevStatus := lp.GetStatus()
1197 if status != prevStatus {
1198 res = []api.ChargeStatus{status}
1199 }
1200
1201 // check charger connection duration
1202 if ct, ok := api.Cap[api.ConnectionTimer](lp.charger); ok {
1203 d, err := ct.ConnectionDuration()
1204 if err != nil {
1205 return nil, fmt.Errorf("connection duration: %w", err)
1206 }
1207
1208 defer func() { lp.connectedDuration = d }()
1209
1210 // connection duration dropped without disconnect status, indicates intermediate disconnect
1211 if status != api.StatusA && prevStatus != api.StatusA && d < lp.connectedDuration {
1212 lp.log.DEBUG.Printf("connection duration drop detected (%s -> %v)", lp.connectedDuration.Round(time.Second), d.Round(time.Second))
1213 res = []api.ChargeStatus{api.StatusA, status}
1214 }
1215 }
1216
1217 return res, nil
1218}
1219
1220// needsWelcomeCharge checks if either the charger or a vehicle requires a welcome charge
1221func (lp *Loadpoint) needsWelcomeCharge() bool {

Callers 1

updateChargerStatusMethod · 0.95

Calls 5

GetStatusMethod · 0.95
PrintfMethod · 0.80
StatusMethod · 0.65
ConnectionDurationMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected