forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
98 lines (88 loc) · 2.42 KB
/
types.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
package goe
// CloudResponse is the cloud API response
type CloudResponse struct {
Success *bool // only valid for cloud payload commands
Age int
Error string // only valid for cloud payload commands
Data StatusResponse
}
// StatusResponse is the API response if status not OK
type StatusResponse struct {
Fwv string `json:"fwv"` // firmware version
Car int `json:"car,string"` // car status
Alw int `json:"alw,string"` // allow charging
Amp int `json:"amp,string"` // current [A]
Err int `json:"err,string"` // error
Eto int `json:"eto,string"` // energy total [0.1kWh]
Stp int `json:"stp,string"` // stop state
Tmp int `json:"tmp,string"` // temperature [°C]
Dws int `json:"dws,string"` // energy [Ws]
Nrg []float64 `json:"nrg"` // voltage, current, power
Uby int `json:"uby,string"` // unlocked_by
Rna string `json:"rna"` // RFID 1
Rnm string `json:"rnm"` // RFID 2
Rne string `json:"rne"` // RFID 3
Rn4 string `json:"rn4"` // RFID 4
Rn5 string `json:"rn5"` // RFID 5
Rn6 string `json:"rn6"` // RFID 6
Rn7 string `json:"rn7"` // RFID 7
Rn8 string `json:"rn8"` // RFID 8
Rn9 string `json:"rn9"` // RFID 9
Rn1 string `json:"rn1"` // RFID 10
}
func (g *StatusResponse) Status() int {
return g.Car
}
func (g *StatusResponse) Enabled() bool {
return g.Alw == 1
}
func (g *StatusResponse) CurrentPower() float64 {
if len(g.Nrg) == 16 {
return g.Nrg[11] * 10
}
return 0
}
func (g *StatusResponse) ChargedEnergy() float64 {
return float64(g.Dws) / 3.6e5 // Deka-Watt-Seconds to kWh (100.000 == 0,277kWh)
}
func (g *StatusResponse) TotalEnergy() float64 {
return float64(g.Eto) / 1e1 // 0.1kWh to kWh (130 == 13kWh)
}
func (g *StatusResponse) Currents() (float64, float64, float64) {
if len(g.Nrg) == 16 {
return g.Nrg[4] / 10, g.Nrg[5] / 10, g.Nrg[6] / 10
}
return 0, 0, 0
}
func (g *StatusResponse) Voltages() (float64, float64, float64) {
if len(g.Nrg) == 16 {
return g.Nrg[0], g.Nrg[1], g.Nrg[2]
}
return 0, 0, 0
}
func (g *StatusResponse) Identify() string {
switch g.Uby {
case 1:
return g.Rna
case 2:
return g.Rnm
case 3:
return g.Rne
case 4:
return g.Rn4
case 5:
return g.Rn5
case 6:
return g.Rn6
case 7:
return g.Rn7
case 8:
return g.Rn8
case 9:
return g.Rn9
case 10:
return g.Rn1
default:
return ""
}
}