fix: treat yutong mqtt mileage as meters
This commit is contained in:
@@ -197,8 +197,5 @@ func looksLikeVIN(value string) bool {
|
||||
}
|
||||
|
||||
func normalizeTotalMileageKM(value float64) float64 {
|
||||
if value > 1_000_000 {
|
||||
return value / 1000
|
||||
}
|
||||
return value
|
||||
return value / 1000
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestParseMessageMapsYutongPayloadToEnvelope(t *testing.T) {
|
||||
t.Fatalf("plate = %q", env.Plate)
|
||||
}
|
||||
assertFloatField(t, env, envelope.FieldSpeedKMH, 52.3)
|
||||
assertFloatField(t, env, envelope.FieldTotalMileageKM, 123456.7)
|
||||
assertFloatField(t, env, envelope.FieldTotalMileageKM, 123.4567)
|
||||
assertFloatField(t, env, envelope.FieldSOCPercent, 70)
|
||||
assertFloatField(t, env, envelope.FieldLongitude, 116.397128)
|
||||
assertFloatField(t, env, envelope.FieldLatitude, 39.916527)
|
||||
@@ -80,6 +80,19 @@ func TestParseMessageNormalizesProductionMileageMeters(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMessageTreatsSmallYutongMileageAsMeters(t *testing.T) {
|
||||
payload := []byte(`{
|
||||
"device":"LMRKH9AC3R1004101",
|
||||
"time":"2026-07-02 01:02:04.085",
|
||||
"data":{"TOTAL_MILEAGE":1024,"METER_SPEED":19}
|
||||
}`)
|
||||
env, err := ParseMessage("yutong", "/ytforward/shln/1", payload, 1782940000000)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseMessage() error = %v", err)
|
||||
}
|
||||
assertFloatField(t, env, envelope.FieldTotalMileageKM, 1.024)
|
||||
}
|
||||
|
||||
func TestParseMessageRejectsMalformedJSON(t *testing.T) {
|
||||
_, err := ParseMessage("endpoint-a", "/bad", []byte("{bad-json"), 1782745114999)
|
||||
if !errors.Is(err, ErrInvalidJSON) {
|
||||
|
||||
Reference in New Issue
Block a user