From c1fa49fc0a0b8fd28fae760eafd07c27ad161a28 Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 6 Jan 2023 10:01:42 +0100 Subject: [PATCH] VW ID: re-add odometer --- vehicle/vw/id/api.go | 4 +- vehicle/vw/id/provider.go | 27 +++++------ vehicle/vw/id/types.go | 98 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 108 insertions(+), 21 deletions(-) diff --git a/vehicle/vw/id/api.go b/vehicle/vw/id/api.go index 51263a7eb..8c6c1c8db 100644 --- a/vehicle/vw/id/api.go +++ b/vehicle/vw/id/api.go @@ -75,8 +75,8 @@ func (v *API) Vehicles() (res []string, err error) { // Status implements the /status response. // It is callers responsibility to check for embedded (partial) errors. func (v *API) Status(vin string) (res Status, err error) { - // NOTE use `all` to retrieve entire status - uri := fmt.Sprintf("%s/vehicles/%s/selectivestatus?jobs=charging,fuelStatus,climatisation", BaseURL, vin) + // NOTE use `all` to retrieve entire status (or charging,fuelStatus,climatisation) + uri := fmt.Sprintf("%s/vehicles/%s/selectivestatus?jobs=all", BaseURL, vin) req, err := request.New(http.MethodGet, uri, nil, request.AcceptJSON) diff --git a/vehicle/vw/id/provider.go b/vehicle/vw/id/provider.go index 521562039..7e94e9721 100644 --- a/vehicle/vw/id/provider.go +++ b/vehicle/vw/id/provider.go @@ -103,24 +103,21 @@ func (v *Provider) Range() (int64, error) { return 0, err } -// var _ api.VehicleOdometer = (*Provider)(nil) +var _ api.VehicleOdometer = (*Provider)(nil) -// // Odometer implements the api.VehicleOdometer interface -// func (v *Provider) Odometer() (float64, error) { -// res, err := v.statusG() -// if err == nil { -// err = res.Error.Extract("maintenanceStatus") -// } +// Odometer implements the api.VehicleOdometer interface +func (v *Provider) Odometer() (float64, error) { + res, err := v.statusG() + if err == nil && res.Measurements == nil { + err = errors.New("missing measurements") + } -// if err == nil { -// if res.Data.MaintenanceStatus == nil { -// return 0, api.ErrNotAvailable -// } -// return float64(res.Data.MaintenanceStatus.MileageKm), nil -// } + if err == nil { + return res.Measurements.OdometerStatus.Value.Odometer, nil + } -// return 0, err -// } + return 0, err +} var _ api.VehicleClimater = (*Provider)(nil) diff --git a/vehicle/vw/id/types.go b/vehicle/vw/id/types.go index c9887b47a..65d33cbfa 100644 --- a/vehicle/vw/id/types.go +++ b/vehicle/vw/id/types.go @@ -9,6 +9,23 @@ import ( // Status is the /status api type Status struct { + Access *struct { + AccessStatus struct { + Value struct { + OverallStatus string `json:"overallStatus"` + CarCapturedTimestamp time.Time `json:"carCapturedTimestamp"` + Doors []struct { + Name string `json:"name"` + Status []string `json:"status"` + } `json:"doors"` + Windows []struct { + Name string `json:"name"` + Status []string `json:"status"` + } `json:"windows"` + DoorLockStatus string `json:"doorLockStatus"` + } `json:"value"` + } `json:"accessStatus"` + } `json:"access"` Automation *struct { ClimatisationTimer struct { Value struct { @@ -97,6 +114,11 @@ type Status struct { AvailableChargeModes []string `json:"availableChargeModes"` } `json:"value"` } `json:"chargeMode"` + ChargingCareSettings struct { + Value struct { + BatteryCareMode string `json:"batteryCareMode"` + } `json:"value"` + } `json:"chargingCareSettings"` } `json:"charging"` Climatisation *struct { ClimatisationStatus struct { @@ -148,13 +170,38 @@ type Status struct { } `json:"recurringTimer,omitempty"` SingleTimer struct { StartDateTime Timestamp `json:"startDateTime"` - } `json:"singleTimer,omitempty"` + } `json:"singleTimer"` } `json:"timers"` CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` TimeInCar Timestamp `json:"timeInCar"` } `json:"value"` } `json:"climatisationTimersStatus"` } `json:"climatisationTimers"` + VehicleLights *struct { + LightsStatus struct { + Value struct { + CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` + Lights []struct { + Name string `json:"name"` + Status string `json:"status"` + } `json:"lights"` + } `json:"value"` + } `json:"lightsStatus"` + } `json:"vehicleLights"` + Measurements *struct { + RangeStatus struct { + Value struct { + CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` + ElectricRange float64 `json:"electricRange"` + } `json:"value"` + } `json:"rangeStatus"` + OdometerStatus struct { + Value struct { + CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` + Odometer float64 `json:"odometer"` + } `json:"value"` + } `json:"odometerStatus"` + } `json:"measurements"` FuelStatus *FuelStatus `json:"fuelStatus"` Readiness *struct { ReadinessStatus struct { @@ -172,12 +219,55 @@ type Status struct { } `json:"value"` } `json:"readinessStatus"` } `json:"readiness"` + VehicleHealthWarnings *struct { + WarningLights struct { + Value struct { + CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` + MileageKm int `json:"mileage_km"` + WarningLights []interface{} `json:"warningLights"` + } `json:"value"` + } `json:"warningLights"` + } `json:"vehicleHealthWarnings"` + ChargingTimers *struct { + ChargingTimersStatus struct { + Value struct { + CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` + TimeInCar Timestamp `json:"timeInCar"` + Timers []struct { + ID int `json:"id"` + Enabled bool `json:"enabled"` + Climatisation bool `json:"climatisation"` + RecurringTimer struct { + DepartureTime string `json:"departureTime"` + RepetitionDays []string `json:"repetitionDays"` + } `json:"recurringTimer"` + } `json:"timers"` + } `json:"value"` + } `json:"chargingTimersStatus"` + } `json:"chargingTimers"` ChargingProfiles *struct { ChargingProfilesStatus struct { Value struct { - CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` - TimeInCar Timestamp `json:"timeInCar"` - Profiles []interface{} `json:"profiles"` + CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` + TimeInCar Timestamp `json:"timeInCar"` + Profiles []struct { + ID int `json:"id"` + Name string `json:"name"` + MaxChargingCurrent string `json:"maxChargingCurrent"` + MinSOCPct int `json:"minSOC_pct"` + TargetSOCPct int `json:"targetSOC_pct"` + Options struct { + AutoUnlockPlugWhenCharged string `json:"autoUnlockPlugWhenCharged"` + } `json:"options"` + PreferredChargingTimes []struct { + ID int `json:"id"` + Enabled bool `json:"enabled"` + StartTime string `json:"startTime"` + EndTime string `json:"endTime"` + } `json:"preferredChargingTimes"` + Timers []interface{} `json:"timers"` + MinSOCEnabled bool `json:"minSOC_enabled"` + } `json:"profiles"` } `json:"value"` } `json:"chargingProfilesStatus"` } `json:"chargingProfiles"`