ID: add error message and timestamp decoding to api (#1256)
This commit is contained in:
parent
0e42540c37
commit
edbc31501b
3 changed files with 41 additions and 11 deletions
|
|
@ -83,19 +83,27 @@ type Status struct {
|
|||
ClimatisationSettings ClimatisationSettings
|
||||
ClimatisationStatus ClimatisationStatus // may be currently not available
|
||||
}
|
||||
Error map[string]Error
|
||||
}
|
||||
|
||||
// Error is the error status
|
||||
type Error struct {
|
||||
Code int
|
||||
Message, Info string
|
||||
}
|
||||
|
||||
// BatteryStatus is the /status.batteryStatus api
|
||||
type BatteryStatus struct {
|
||||
CarCapturedTimestamp string
|
||||
CarCapturedTimestamp Timestamp
|
||||
CurrentSOCPercent int `json:"currentSOC_pct"`
|
||||
CruisingRangeElectricKm int `json:"cruisingRangeElectric_km"`
|
||||
}
|
||||
|
||||
// ChargingStatus is the /status.chargingStatus api
|
||||
type ChargingStatus struct {
|
||||
CarCapturedTimestamp string
|
||||
ChargingState string // readyForCharging
|
||||
CarCapturedTimestamp Timestamp
|
||||
ChargingState string // readyForCharging/off
|
||||
ChargeMode string // invalid
|
||||
RemainingChargingTimeToCompleteMin int `json:"remainingChargingTimeToComplete_min"`
|
||||
ChargePowerKW float64 `json:"chargePower_kW"`
|
||||
ChargeRateKmph int `json:"chargeRate_kmph"`
|
||||
|
|
@ -103,7 +111,7 @@ type ChargingStatus struct {
|
|||
|
||||
// ChargingSettings is the /status.chargingSettings api
|
||||
type ChargingSettings struct {
|
||||
CarCapturedTimestamp string
|
||||
CarCapturedTimestamp Timestamp
|
||||
MaxChargeCurrentAC string // reduced, maximum
|
||||
AutoUnlockPlugWhenCharged string
|
||||
TargetSOCPercent int `json:"targetSOC_pct"`
|
||||
|
|
@ -111,21 +119,21 @@ type ChargingSettings struct {
|
|||
|
||||
// PlugStatus is the /status.plugStatus api
|
||||
type PlugStatus struct {
|
||||
CarCapturedTimestamp string
|
||||
CarCapturedTimestamp Timestamp
|
||||
PlugConnectionState string // connected, disconnected
|
||||
PlugLockState string
|
||||
PlugLockState string // locked, unlocked
|
||||
}
|
||||
|
||||
// ClimatisationStatus is the /status.climatisationStatus api
|
||||
type ClimatisationStatus struct {
|
||||
CarCapturedTimestamp string
|
||||
CarCapturedTimestamp Timestamp
|
||||
RemainingClimatisationTimeMin int `json:"remainingClimatisationTime_min"`
|
||||
ClimatisationState string // off
|
||||
}
|
||||
|
||||
// ClimatisationSettings is the /status.climatisationSettings api
|
||||
type ClimatisationSettings struct {
|
||||
CarCapturedTimestamp string
|
||||
CarCapturedTimestamp Timestamp
|
||||
TargetTemperatureK float64 `json:"targetTemperature_K"`
|
||||
TargetTemperatureC float64 `json:"targetTemperature_C"`
|
||||
ClimatisationWithoutExternalPower bool
|
||||
|
|
@ -139,7 +147,7 @@ type ClimatisationSettings struct {
|
|||
|
||||
// RangeStatus is the /status.rangeStatus api
|
||||
type RangeStatus struct {
|
||||
CarCapturedTimestamp string
|
||||
CarCapturedTimestamp Timestamp
|
||||
CarType string
|
||||
PrimaryEngine struct {
|
||||
Type string
|
||||
|
|
|
|||
|
|
@ -65,8 +65,7 @@ func (v *Provider) FinishTime() (time.Time, error) {
|
|||
res, err := v.statusG()
|
||||
if res, ok := res.(Status); err == nil && ok {
|
||||
cst := res.Data.ChargingStatus
|
||||
timestamp, err := time.Parse(time.RFC3339, cst.CarCapturedTimestamp)
|
||||
return timestamp.Add(time.Duration(cst.RemainingChargingTimeToCompleteMin) * time.Minute), err
|
||||
return cst.CarCapturedTimestamp.Add(time.Duration(cst.RemainingChargingTimeToCompleteMin) * time.Minute), err
|
||||
}
|
||||
|
||||
return time.Time{}, err
|
||||
|
|
|
|||
23
vehicle/id/types.go
Normal file
23
vehicle/id/types.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package id
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Timestamp implements JSON unmarshal for RFC3339 string timestamp
|
||||
type Timestamp struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes RFC3339 string timestamp into time.Time
|
||||
func (ct *Timestamp) UnmarshalJSON(data []byte) error {
|
||||
s := strings.Trim(string(data), "\"")
|
||||
|
||||
t, err := time.Parse(time.RFC3339, s)
|
||||
if err == nil {
|
||||
(*ct).Time = t
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue