getStatusChanges checks charger status and returns a chronological list of status changes
()
| 1183 | |
| 1184 | // getStatusChanges checks charger status and returns a chronological list of status changes |
| 1185 | func (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 |
| 1221 | func (lp *Loadpoint) needsWelcomeCharge() bool { |
no test coverage detected