Vehicle: accept lat/lon parkingposition keys for VW weconnect (#29981)

This commit is contained in:
andig 2026-05-17 16:22:14 +02:00 • committed by GitHub
parent 5506053dd3
commit fed967856f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
package weconnect
import (
"encoding/json"
"errors"
"fmt"
"strings"
@ -322,9 +323,43 @@ type EngineRangeStatus struct {
// ParkingPosition is the /parkingposition api response
type ParkingPosition struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"`
Latitude float64
Longitude float64
CarCapturedTimestamp Timestamp
}
// UnmarshalJSON accepts both the latitude/longitude and the shorter lat/lon
// key variants the parkingposition endpoint may return.
func (p *ParkingPosition) UnmarshalJSON(data []byte) error {
var res struct {
Latitude *float64 `json:"latitude"`
Longitude *float64 `json:"longitude"`
Lat *float64 `json:"lat"`
Lon *float64 `json:"lon"`
CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"`
}
if err := json.Unmarshal(data, &res); err != nil {
return err
}
p.CarCapturedTimestamp = res.CarCapturedTimestamp
switch {
case res.Latitude != nil:
p.Latitude = *res.Latitude
case res.Lat != nil:
p.Latitude = *res.Lat
}
switch {
case res.Longitude != nil:
p.Longitude = *res.Longitude
case res.Lon != nil:
p.Longitude = *res.Lon
}
return nil
}
// Timestamp implements JSON unmarshal