-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharging.go
More file actions
81 lines (69 loc) · 3.08 KB
/
charging.go
File metadata and controls
81 lines (69 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package skoda
import (
"context"
"fmt"
"time"
)
// ChargingState represents the current state of charging.
type ChargingState string
const (
ChargingStateReadyForCharging ChargingState = "READY_FOR_CHARGING"
ChargingStateConnectCable ChargingState = "CONNECT_CABLE"
ChargingStateConserving ChargingState = "CONSERVING"
ChargingStateCharging ChargingState = "CHARGING"
ChargingStateChargingInterrupted ChargingState = "CHARGING_INTERRUPTED"
ChargingStateError ChargingState = "ERROR"
)
// ChargeType represents the type of charging connection.
type ChargeType string
const (
ChargeTypeAC ChargeType = "AC"
ChargeTypeDC ChargeType = "DC"
ChargeTypeOff ChargeType = "OFF"
)
// MaxChargeCurrent represents the maximum charge current setting.
type MaxChargeCurrent string
const (
MaxChargeCurrentMaximum MaxChargeCurrent = "MAXIMUM"
MaxChargeCurrentReduced MaxChargeCurrent = "REDUCED"
)
// ChargingBattery contains the current battery state.
type ChargingBattery struct {
StateOfChargeInPercent *int `json:"stateOfChargeInPercent"`
RemainingCruisingRangeInMeters *int64 `json:"remainingCruisingRangeInMeters"`
}
// ChargingStatus contains the current charging status.
type ChargingStatus struct {
Battery ChargingBattery `json:"battery"`
State ChargingState `json:"state,omitempty"`
ChargePowerInKW *float64 `json:"chargePowerInKw,omitempty"`
ChargingRateInKilometersPerHour *float64 `json:"chargingRateInKilometersPerHour,omitempty"`
ChargeType ChargeType `json:"chargeType,omitempty"`
RemainingTimeToFullyChargedInMinutes *int64 `json:"remainingTimeToFullyChargedInMinutes,omitempty"`
}
// ChargingSettings contains the charging configuration.
type ChargingSettings struct {
AutoUnlockPlugWhenCharged string `json:"autoUnlockPlugWhenCharged,omitempty"`
MaxChargeCurrentAC string `json:"maxChargeCurrentAc,omitempty"`
TargetStateOfChargeInPercent *int `json:"targetStateOfChargeInPercent,omitempty"`
PreferredChargeMode string `json:"preferredChargeMode,omitempty"`
ChargingCareMode string `json:"chargingCareMode,omitempty"`
BatterySupport string `json:"batterySupport,omitempty"`
}
// Charging contains the full charging information for a vehicle.
type Charging struct {
IsVehicleInSavedLocation bool `json:"isVehicleInSavedLocation"`
Status *ChargingStatus `json:"status,omitempty"`
Settings ChargingSettings `json:"settings"`
CarCapturedTimestamp *time.Time `json:"carCapturedTimestamp,omitempty"`
}
// Charging retrieves the current charging state for a vehicle.
// This is a safe read-only endpoint that does not wake the car.
func (c *Client) Charging(ctx context.Context, vin string) (*Charging, error) {
var res Charging
url := fmt.Sprintf("%s/v1/charging/%s", c.apiURL, vin)
if err := c.doGet(ctx, url, &res); err != nil {
return nil, fmt.Errorf("charging: %w", err)
}
return &res, nil
}