Bugfix: running sensor's data should be null if not connected.
Fixes
@@ -57,15 +57,16 @@ public final class SensorDataRunning extends SensorData<SensorDataRunning.Data>
@Override
protected Data getNoneValue() {
if (value != null) {
- return new Data(Speed.zero(), 0f, ((Data) value).distance);
+ return new Data(Speed.zero(), 0f, value.distance);
} else {
return new Data(Speed.zero(), 0f, Distance.of(0));
}
}
public void compute(SensorDataRunning previous) {
+ if (speed != null && hasTotalDistance()) {
Distance overallDistance = null;
- if (hasTotalDistance() && previous != null && previous.hasTotalDistance()) {
+ if (previous != null && previous.hasTotalDistance()) {
overallDistance = this.totalDistance.minus(previous.totalDistance);
if (previous.hasValue() && previous.getValue().getDistance() != null) {
overallDistance = overallDistance.plus(previous.getValue().getDistance());
@@ -74,6 +75,7 @@ public final class SensorDataRunning extends SensorData<SensorDataRunning.Data>
value = new Data(speed, cadence, overallDistance);
}
+ }
@Override
public void reset() {
