-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.go
146 lines (119 loc) · 3.75 KB
/
session.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
package smartcharge
import (
"fmt"
"net/http"
"strconv"
)
type SessionService struct {
client *Client
}
type LiveDataResult struct {
Result LiveData
}
type LiveData struct {
Currency string `json:"Currency"`
IsSuspended bool `json:"isSuspended"`
TotalWh float64 `json:"TotalWh"`
LiveKWH float64 `json:"LiveKWH"`
LiveAmps float64 `json:"LiveAmps"`
LiveKW float64 `json:"LiveKW"`
LiveVolts float64 `json:"LiveVolts"`
LiveAmps_L1 float64 `json:"LiveAmps_L1"`
LiveAmps_L2 float64 `json:"LiveAmps_L2"`
LiveAmps_L3 float64 `json:"LiveAmps_L3"`
CurrentCost float64 `json:"CurrentCost"`
CurrentCostCharging float64 `json:"CurrentCostCharging"`
CurrentCostChargingTime float64 `json:"CurrentCostChargingTime"`
CurrentCostOccupied float64 `json:"CurrentCostOccupied"`
StartupCost float64 `json:"StartupCost"`
IsFinished bool `json:"IsFinished"`
}
func (s *SessionService) GetLiveData(sessionId int) (*LiveDataResult, *http.Response, error) {
reqUrl := "v2/ServiceSessions/LiveData/" + strconv.Itoa(sessionId)
req, err := s.client.NewRequest("GET", reqUrl, nil)
if err != nil {
return nil, nil, err
}
liveData := &LiveDataResult{}
resp, err := s.client.Do(req, liveData)
if err != nil {
return nil, resp, err
}
return liveData, resp, err
}
type SessionsResult struct {
Result []Session
}
type SessionResult struct {
Result Session
}
type Session struct {
SessionId int `json:"PK_ServiceSessionID"`
SessionStart string `json:"SessionStart"`
SessionEnd string `json:"SessionEnd"`
DurationCharging int `json:"DurationCharging"`
ChargingBoxID int `json:"ChargingBoxID"`
ChargingPointID int `json:"ChargingPointID"`
CustomerID int `json:"FK_CustomerID"`
TotalkWh float64 `json:"TotalkWh"`
LivekW float64 `json:"LivekW"`
PointName string `json:"PointName"`
MaxKWH float64 `json:"MaxKWH"`
StartMethod string `json:"StartMethod"`
}
func (s *SessionService) GetSession(sessionId int) (*SessionResult, *http.Response, error) {
reqUrl := "v2/ServiceSessions/" + strconv.Itoa(sessionId)
req, err := s.client.NewRequest("GET", reqUrl, nil)
if err != nil {
return nil, nil, err
}
session := &SessionResult{}
resp, err := s.client.Do(req, session)
if err != nil {
return nil, resp, err
}
return session, resp, err
}
func (s *SessionService) GetActiveSessions() (*SessionsResult, *http.Response, error) {
if s.client.Auth == nil {
return nil, nil, fmt.Errorf("not authenticated")
}
reqUrl := "v2/ServiceSessions/Active/" + strconv.Itoa(s.client.Auth.UserId)
req, err := s.client.NewRequest("GET", reqUrl, nil)
if err != nil {
return nil, nil, err
}
sessions := &SessionsResult{}
resp, err := s.client.Do(req, sessions)
if err != nil {
return nil, resp, err
}
return sessions, resp, err
}
type MeterValuesResult struct {
Result MeterValues
}
type MeterValues struct {
Items []Item `json:"Items"`
TotalLogs int `json:"TotalLogs"`
}
type Item struct {
Date string `json:"Date"`
KWh float64 `json:"kWh"`
Amps float64 `json:"Amps"`
Kw float64 `json:"kW"`
}
// Defaults to fetch last 60 values. /<num> can be added behind sessionId to fetch more
func (s *SessionService) GetMeterValues(sessionId int) (*MeterValuesResult, *http.Response, error) {
reqUrl := "v2/Metervalues/SessionResult/" + strconv.Itoa(sessionId)
req, err := s.client.NewRequest("GET", reqUrl, nil)
if err != nil {
return nil, nil, err
}
meterValues := &MeterValuesResult{}
resp, err := s.client.Do(req, meterValues)
if err != nil {
return nil, resp, err
}
return meterValues, resp, err
}