-
-
Notifications
You must be signed in to change notification settings - Fork 720
/
Copy pathapi.go
251 lines (210 loc) Β· 6.61 KB
/
api.go
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package api
import (
"context"
"fmt"
"io"
"net/http"
"reflect"
"strings"
"time"
"github.com/fatih/structs"
)
//go:generate mockgen -package mock -destination ../mock/mock_api.go github.com/evcc-io/evcc/api Charger,ChargeState,PhaseSwitcher,Identifier,Meter,MeterEnergy,Vehicle,ChargeRater,Battery,Tariff
// ChargeMode is the charge operation mode. Valid values are off, now, minpv and pv
type ChargeMode string
// Charge modes
const (
ModeEmpty ChargeMode = ""
ModeOff ChargeMode = "off"
ModeNow ChargeMode = "now"
ModeMinPV ChargeMode = "minpv"
ModePV ChargeMode = "pv"
)
// String implements Stringer
func (c ChargeMode) String() string {
return string(c)
}
// ChargeStatus is the EV's charging status from A to F
type ChargeStatus string
// Charging states
const (
StatusNone ChargeStatus = ""
StatusA ChargeStatus = "A" // Fzg. angeschlossen: nein Laden aktiv: nein - Kabel nicht angeschlossen
StatusB ChargeStatus = "B" // Fzg. angeschlossen: ja Laden aktiv: nein - Kabel angeschlossen
StatusC ChargeStatus = "C" // Fzg. angeschlossen: ja Laden aktiv: ja - Laden
StatusD ChargeStatus = "D" // Fzg. angeschlossen: ja Laden aktiv: ja - Laden mit LΓΌfter
StatusE ChargeStatus = "E" // Fzg. angeschlossen: ja Laden aktiv: nein - Fehler (Kurzschluss)
StatusF ChargeStatus = "F" // Fzg. angeschlossen: ja Laden aktiv: nein - Fehler (Ausfall Wallbox)
)
// String implements Stringer
func (c ChargeStatus) String() string {
return string(c)
}
// ActionConfig defines an action to take on event
type ActionConfig struct {
Mode *ChargeMode `mapstructure:"mode,omitempty"` // Charge Mode
MinCurrent *float64 `mapstructure:"minCurrent,omitempty"` // Minimum Current
MaxCurrent *float64 `mapstructure:"maxCurrent,omitempty"` // Maximum Current
MinSoc *int `mapstructure:"minSoc,omitempty"` // Minimum Soc
TargetSoc *int `mapstructure:"targetSoc,omitempty"` // Target Soc
}
// Merge merges all non-nil properties of the additional config into the base config.
// The receiver's config remains immutable.
func (a ActionConfig) Merge(m ActionConfig) ActionConfig {
if m.Mode != nil {
a.Mode = m.Mode
}
if m.MinCurrent != nil {
a.MinCurrent = m.MinCurrent
}
if m.MaxCurrent != nil {
a.MaxCurrent = m.MaxCurrent
}
if m.MinSoc != nil {
a.MinSoc = m.MinSoc
}
if m.TargetSoc != nil {
a.TargetSoc = m.TargetSoc
}
return a
}
// String implements Stringer and returns the ActionConfig as comma-separated key:value string
func (a ActionConfig) String() string {
var s []string
for k, v := range structs.Map(a) {
val := reflect.ValueOf(v)
if v != nil && !val.IsNil() {
s = append(s, fmt.Sprintf("%s:%v", k, val.Elem()))
}
}
return strings.Join(s, ", ")
}
// Meter is able to provide current power in W
type Meter interface {
CurrentPower() (float64, error)
}
// MeterEnergy is able to provide current energy in kWh
type MeterEnergy interface {
TotalEnergy() (float64, error)
}
// MeterCurrent is able to provide per-line current A
type MeterCurrent interface {
Currents() (float64, float64, float64, error)
}
// Battery is able to provide battery Soc in %
type Battery interface {
Soc() (float64, error)
}
// ChargeState provides current charging status
type ChargeState interface {
Status() (ChargeStatus, error)
}
// CurrentLimiter provides current charging status
type CurrentLimiter interface {
MaxCurrent(current int64) error
}
// Charger is able to provide current charging status and enable/disable charging
type Charger interface {
ChargeState
Enabled() (bool, error)
Enable(enable bool) error
CurrentLimiter
}
// ChargerEx provides milli-amp precision charger current control
type ChargerEx interface {
MaxCurrentMillis(current float64) error
}
// PhaseSwitcher provides 1p3p switching
type PhaseSwitcher interface {
Phases1p3p(phases int) error
}
// Diagnosis is a helper interface that allows to dump diagnostic data to console
type Diagnosis interface {
Diagnose()
}
// ChargeTimer provides current charge cycle duration
type ChargeTimer interface {
ChargingTime() (time.Duration, error)
}
// ChargeRater provides charged energy amount in kWh
type ChargeRater interface {
ChargedEnergy() (float64, error)
}
// Identifier identifies a vehicle and is implemented by the charger
type Identifier interface {
Identify() (string, error)
}
// Authorizer authorizes a charging session by supplying RFID credentials
type Authorizer interface {
Authorize(key string) error
}
// Vehicle represents the EV and it's battery
type Vehicle interface {
Battery
Title() string
Icon() string
Capacity() float64
Phases() int
Identifiers() []string
OnIdentified() ActionConfig
}
// VehicleFinishTimer provides estimated charge cycle finish time.
// Finish time is normalized for charging to 100% and may deviate from vehicle display if soc limit is effective.
type VehicleFinishTimer interface {
FinishTime() (time.Time, error)
}
// VehicleRange provides the vehicles remaining km range
type VehicleRange interface {
Range() (int64, error)
}
// VehicleClimater provides climatisation data
type VehicleClimater interface {
Climater() (active bool, outsideTemp, targetTemp float64, err error)
}
// VehicleOdometer returns the vehicles milage
type VehicleOdometer interface {
Odometer() (float64, error)
}
// VehiclePosition returns the vehicles position in latitude and longitude
type VehiclePosition interface {
Position() (float64, float64, error)
}
// SocLimiter returns the vehicles charge limit
type SocLimiter interface {
TargetSoc() (float64, error)
}
// VehicleChargeController allows to start/stop the charging session on the vehicle side
type VehicleChargeController interface {
StartCharge() error
StopCharge() error
}
// Resurrector provides wakeup calls to the vehicle with an API call or a CP interrupt from the charger
type Resurrector interface {
WakeUp() error
}
// Rate is a grid tariff rate
type Rate struct {
Start, End time.Time
Price float64
}
// Rates is a slice of (future) tariff rates
type Rates []Rate
// Tariff is a tariff capable of retrieving tariff rates
type Tariff interface {
Rates() (Rates, error)
}
// AuthProvider is the ability to provide OAuth authentication through the ui
type AuthProvider interface {
SetCallbackParams(baseURL, redirectURL string, authenticated chan<- bool)
LoginHandler() http.HandlerFunc
LogoutHandler() http.HandlerFunc
}
// FeatureDescriber optionally provides a list of supported non-api features
type FeatureDescriber interface {
Features() []Feature
Has(Feature) bool
}
// CsvWriter converts to csv
type CsvWriter interface {
WriteCsv(context.Context, io.Writer) error
}