Align handling of odometer and range

This commit is contained in:
andig 2021-10-23 15:05:29 +02:00
parent b672502e3e
commit 8edf0ae49a
2 changed files with 6 additions and 13 deletions

View file

@ -107,7 +107,7 @@ func configureDatabase(conf server.InfluxConfig, loadPoints []loadpoint.API, in
)
// eliminate duplicate values
dedupe := pipe.NewDeduplicator(30*time.Minute, "vehicleSoC")
dedupe := pipe.NewDeduplicator(30*time.Minute, "vehicleSoC", "vehicleRange", "vehicleOdometer")
in = dedupe.Pipe(in)
// reduce number of values written to influx

View file

@ -706,15 +706,16 @@ func (lp *LoadPoint) setActiveVehicle(vehicle api.Vehicle) {
lp.publish("vehiclePresent", true)
lp.publish("vehicleTitle", lp.vehicle.Title())
lp.publish("vehicleCapacity", lp.vehicle.Capacity())
lp.publish("vehicleOdometer", 0.0)
} else {
lp.socEstimator = nil
lp.publish("vehiclePresent", false)
lp.publish("vehicleTitle", "")
lp.publish("vehicleCapacity", int64(0))
lp.publish("vehicleOdometer", 0.0)
}
lp.publish("vehicleRange", int64(0))
lp.publish("vehicleOdometer", 0.0)
}
// startVehicleDetection resets connection timer and starts api refresh timer
@ -1189,9 +1190,10 @@ func (lp *LoadPoint) publishSoCAndRange() {
}
// odometer
// TODO read only once after connect
if vs, ok := lp.vehicle.(api.VehicleOdometer); ok {
if odo, err := vs.Odometer(); err == nil {
lp.log.DEBUG.Printf("vehicle odometer: %vkm", odo)
lp.log.DEBUG.Printf("vehicle odometer: %.0fkm", odo)
lp.publish("vehicleOdometer", odo)
}
}
@ -1205,15 +1207,6 @@ func (lp *LoadPoint) publishSoCAndRange() {
return
}
// reset if poll: connected/charging and not connected
if lp.SoC.Poll.Mode != pollAlways && !lp.connected() {
lp.publish("vehicleSoC", -1)
lp.publish("chargeRemainingDuration", time.Duration(-1))
// range
lp.publish("vehicleRange", -1)
}
}
// Update is the main control function. It reevaluates meters and charger state