-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.go
501 lines (484 loc) · 20.1 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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
package sense
import (
"encoding/json"
"sync"
"time"
"github.com/golang-jwt/jwt"
"github.com/gorilla/websocket"
)
type AuthRes struct {
MfaToken string `json:"mfa_token"`
MfaType string `json:"mfa_type"`
Status string `json:"status"`
ErrorReason string `json:"error_reason"`
Authorized bool `json:"authorized"`
AccountId int `json:"account_id"`
UserId int `json:"user_id"`
AccessToken string `json:"access_token"`
Settings struct {
UserId int `json:"user_id"`
Settings struct {
Notifications struct {
Field1 struct {
NewNamedDevicePush bool `json:"new_named_device_push"`
NewNamedDeviceEmail bool `json:"new_named_device_email"`
MonitorOfflinePush bool `json:"monitor_offline_push"`
MonitorOfflineEmail bool `json:"monitor_offline_email"`
MonitorMonthlyEmail bool `json:"monitor_monthly_email"`
AlwaysOnChangePush bool `json:"always_on_change_push"`
ComparisonChangePush bool `json:"comparison_change_push"`
NewPeakPush bool `json:"new_peak_push"`
NewPeakEmail bool `json:"new_peak_email"`
MonthlyChangePush bool `json:"monthly_change_push"`
WeeklyChangePush bool `json:"weekly_change_push"`
DailyChangePush bool `json:"daily_change_push"`
GeneratorOnPush bool `json:"generator_on_push"`
GeneratorOffPush bool `json:"generator_off_push"`
TimeOfUse bool `json:"time_of_use"`
} `json:"187899"`
Field2 struct {
NewNamedDevicePush bool `json:"new_named_device_push"`
NewNamedDeviceEmail bool `json:"new_named_device_email"`
MonitorOfflinePush bool `json:"monitor_offline_push"`
MonitorOfflineEmail bool `json:"monitor_offline_email"`
MonitorMonthlyEmail bool `json:"monitor_monthly_email"`
AlwaysOnChangePush bool `json:"always_on_change_push"`
ComparisonChangePush bool `json:"comparison_change_push"`
NewPeakPush bool `json:"new_peak_push"`
NewPeakEmail bool `json:"new_peak_email"`
MonthlyChangePush bool `json:"monthly_change_push"`
WeeklyChangePush bool `json:"weekly_change_push"`
DailyChangePush bool `json:"daily_change_push"`
GeneratorOnPush bool `json:"generator_on_push"`
GeneratorOffPush bool `json:"generator_off_push"`
TimeOfUse bool `json:"time_of_use"`
} `json:"188074"`
} `json:"notifications"`
LabsEnabled bool `json:"labs_enabled"`
} `json:"settings"`
Version int `json:"version"`
} `json:"settings"`
Monitors []struct {
Id int `json:"id"`
SerialNumber string `json:"serial_number"`
TimeZone string `json:"time_zone"`
SolarConnected bool `json:"solar_connected"`
SolarConfigured bool `json:"solar_configured"`
Online bool `json:"online"`
Attributes struct {
Id int `json:"id"`
Name string `json:"name"`
State string `json:"state"`
Cost float64 `json:"cost"`
SellBackRate float64 `json:"sell_back_rate"`
UserSetCost bool `json:"user_set_cost"`
CycleStart int `json:"cycle_start"`
BasementType string `json:"basement_type"`
HomeSizeType string `json:"home_size_type"`
HomeType string `json:"home_type"`
NumberOfOccupants string `json:"number_of_occupants"`
OccupancyType string `json:"occupancy_type"`
YearBuiltType string `json:"year_built_type"`
PostalCode string `json:"postal_code"`
ElectricityCost interface{} `json:"electricity_cost"`
ShowCost bool `json:"show_cost"`
TouEnabled bool `json:"tou_enabled"`
SolarTouEnabled bool `json:"solar_tou_enabled"`
PowerRegion interface{} `json:"power_region"`
UserSetSellBackRate bool `json:"user_set_sell_back_rate"`
} `json:"attributes"`
SignalCheckCompletedTime time.Time `json:"signal_check_completed_time"`
DataSharing []interface{} `json:"data_sharing"`
EthernetSupported bool `json:"ethernet_supported"`
AuxIgnore bool `json:"aux_ignore"`
AuxPort string `json:"aux_port"`
HardwareType string `json:"hardware_type"`
} `json:"monitors"`
BridgeServer string `json:"bridge_server"`
DateCreated time.Time `json:"date_created"`
TotpEnabled bool `json:"totp_enabled"`
AbCohort string `json:"ab_cohort"`
RefreshToken string `json:"refresh_token"`
}
type SenseApi struct {
ws *websocket.Conn
wssEndpoint string
refreshToken string
authRes AuthRes
mutex sync.RWMutex
messages []RealTime
readingAsync bool
}
type AlwaysOn struct {
Alerts struct {
Allowed bool `json:"allowed"`
Enabled bool `json:"enabled"`
} `json:"alerts"`
Device struct {
Id string `json:"id"`
MonitorId int `json:"monitorId"`
Name string `json:"name"`
Icon string `json:"icon"`
Tags struct {
DefaultUserDeviceType string `json:"DefaultUserDeviceType"`
DeviceListAllowed string `json:"DeviceListAllowed"`
SSIEnabled string `json:"SSIEnabled"`
TimelineAllowed string `json:"TimelineAllowed"`
UserEditable string `json:"UserEditable"`
UserDeviceTypeDisplayString string `json:"UserDeviceTypeDisplayString"`
UserDeviceType string `json:"UserDeviceType"`
} `json:"tags"`
} `json:"device"`
LastState interface{} `json:"last_state"`
Notes interface{} `json:"notes"`
Info string `json:"info"`
LastStateTime interface{} `json:"last_state_time"`
Usage struct {
AvgMonthlyKWH float64 `json:"avg_monthly_KWH"`
AvgMonthlyPct float64 `json:"avg_monthly_pct"`
AvgWatts float64 `json:"avg_watts"`
YearlyKWH float64 `json:"yearly_KWH"`
YearlyText string `json:"yearly_text"`
YearlyCost int `json:"yearly_cost"`
AvgMonthlyCost int `json:"avg_monthly_cost"`
CurrentAoWattage int `json:"current_ao_wattage"`
Comparison struct {
ComparisonText string `json:"comparison_text"`
TercileStrings []string `json:"tercile_strings"`
CohortMarker int `json:"cohort_marker"`
Cohort struct {
Id int `json:"id"`
PostalCode string `json:"postal_code"`
AreaCode string `json:"area_code"`
State string `json:"state"`
HomeSize string `json:"home_size"`
Location string `json:"location"`
} `json:"cohort"`
Title string `json:"title"`
W float64 `json:"w"`
CohortAvgW float64 `json:"cohort_avg_w"`
} `json:"comparison"`
} `json:"usage"`
AlwaysOn struct {
Description string `json:"description"`
TotalWatts float64 `json:"total_watts"`
UnknownWatts float64 `json:"unknown_watts"`
Devices []struct {
Id string `json:"id"`
W float64 `json:"w"`
} `json:"devices"`
} `json:"always_on"`
Timeline struct {
Visible bool `json:"visible"`
Allowed bool `json:"allowed"`
} `json:"timeline"`
Blurb struct {
Type string `json:"type"`
Content string `json:"content"`
} `json:"blurb"`
}
type TimeLineRes struct {
MoreItems bool `json:"more_items"`
StickyItems []interface{} `json:"sticky_items"`
UserId int `json:"user_id"`
Items []struct {
Time time.Time `json:"time"`
Type string `json:"type"`
Icon string `json:"icon"`
Body string `json:"body"`
Destination string `json:"destination"`
DeviceId string `json:"device_id"`
DeviceState string `json:"device_state"`
ShowAction bool `json:"show_action"`
AllowSticky bool `json:"allow_sticky"`
UserDeviceType string `json:"user_device_type"`
StartTime time.Time `json:"start_time,omitempty"`
Children []struct {
Time time.Time `json:"time"`
Type string `json:"type"`
Body string `json:"body"`
DeviceId string `json:"device_id"`
ShowAction bool `json:"show_action"`
AllowSticky bool `json:"allow_sticky"`
StartTime time.Time `json:"start_time,omitempty"`
Children []struct {
Time time.Time `json:"time"`
Type string `json:"type"`
DeviceId string `json:"device_id"`
ShowAction bool `json:"show_action"`
AllowSticky bool `json:"allow_sticky"`
} `json:"children,omitempty"`
} `json:"children,omitempty"`
Count int `json:"count,omitempty"`
} `json:"items"`
}
type DevicesOverview struct {
Devices []struct {
Id string `json:"id"`
Name string `json:"name"`
Make string `json:"make,omitempty"`
Model string `json:"model,omitempty"`
Icon string `json:"icon"`
Tags struct {
Alertable string `json:"Alertable,omitempty"`
AlwaysOn string `json:"AlwaysOn,omitempty"`
DateCreated time.Time `json:"DateCreated,omitempty"`
DateFirstUsage string `json:"DateFirstUsage,omitempty"`
DefaultUserDeviceType string `json:"DefaultUserDeviceType,omitempty"`
DeployToMonitor string `json:"DeployToMonitor,omitempty"`
DeviceListAllowed string `json:"DeviceListAllowed"`
ModelCreatedVersion string `json:"ModelCreatedVersion,omitempty"`
ModelUpdatedVersion string `json:"ModelUpdatedVersion,omitempty"`
NameUseredit string `json:"name_useredit,omitempty"`
OriginalName string `json:"OriginalName,omitempty"`
PeerNames []struct {
Name string `json:"Name"`
UserDeviceType string `json:"UserDeviceType"`
Percent float64 `json:"Percent"`
Icon string `json:"Icon"`
UserDeviceTypeDisplayString string `json:"UserDeviceTypeDisplayString"`
Make string `json:"Make,omitempty"`
Model string `json:"Model,omitempty"`
} `json:"PeerNames,omitempty"`
Pending string `json:"Pending,omitempty"`
Revoked string `json:"Revoked,omitempty"`
SSIEnabled string `json:"SSIEnabled,omitempty"`
TimelineAllowed string `json:"TimelineAllowed"`
TimelineDefault string `json:"TimelineDefault,omitempty"`
Type string `json:"Type,omitempty"`
UserDeletable string `json:"UserDeletable,omitempty"`
UserDeviceType string `json:"UserDeviceType"`
UserDeviceTypeDisplayString string `json:"UserDeviceTypeDisplayString"`
UserEditable string `json:"UserEditable"`
UserEditableMeta string `json:"UserEditableMeta,omitempty"`
UserMergeable string `json:"UserMergeable,omitempty"`
ExpectedAOWattage int `json:"ExpectedAOWattage,omitempty"`
UserAdded string `json:"UserAdded,omitempty"`
MergeId string `json:"MergeId,omitempty"`
PreselectionIndex int `json:"PreselectionIndex,omitempty"`
NameUserGuess string `json:"NameUserGuess,omitempty"`
MergedDevices string `json:"MergedDevices,omitempty"`
Virtual string `json:"Virtual,omitempty"`
DefaultMake string `json:"DefaultMake,omitempty"`
DefaultModel string `json:"DefaultModel,omitempty"`
UserDeleted string `json:"UserDeleted,omitempty"`
} `json:"tags"`
GivenMake string `json:"given_make,omitempty"`
GivenModel string `json:"given_model,omitempty"`
Location string `json:"location,omitempty"`
GivenLocation string `json:"given_location,omitempty"`
} `json:"devices"`
DeviceDataChecksum string `json:"device_data_checksum"`
}
type RateZones struct {
Historic []struct {
Id int `json:"id"`
Name string `json:"name"`
Monitor interface{} `json:"monitor"`
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
DaysEnabledBitValue int `json:"days_enabled_bit_value"`
Cost float64 `json:"cost"`
Alert bool `json:"alert"`
Rollover bool `json:"rollover"`
RolledOver interface{} `json:"rolled_over"`
Status string `json:"status"`
DaysEnabled string `json:"days_enabled"`
} `json:"historic"`
Future []struct {
Id int `json:"id"`
Name string `json:"name"`
Monitor int `json:"monitor"`
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
DaysEnabledBitValue int `json:"days_enabled_bit_value"`
Cost float64 `json:"cost"`
Alert bool `json:"alert"`
Rollover bool `json:"rollover"`
RolledOver interface{} `json:"rolled_over"`
Status string `json:"status"`
DaysEnabled string `json:"days_enabled"`
} `json:"future"`
Present []struct {
Id int `json:"id"`
Name string `json:"name"`
Monitor int `json:"monitor"`
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
DaysEnabledBitValue int `json:"days_enabled_bit_value"`
Cost float64 `json:"cost"`
Alert bool `json:"alert"`
Rollover bool `json:"rollover"`
RolledOver interface{} `json:"rolled_over"`
Status string `json:"status"`
DaysEnabled string `json:"days_enabled"`
} `json:"present"`
}
type jwtClaims struct {
Iss string `json:"iss"`
Exp int `json:"exp"`
UserId int `json:"userId"`
AccountId int `json:"accountId"`
Roles string `json:"roles"`
Dhash string `json:"dhash"`
jwt.StandardClaims
}
type TrendType struct {
Steps int `json:"steps"`
Start time.Time `json:"start"`
End time.Time `json:"end"`
Consumption struct {
Total float64 `json:"total"`
Totals []float64 `json:"totals"`
Devices []struct {
Id string `json:"id"`
MonitorId int `json:"monitorId"`
Name string `json:"name"`
Icon string `json:"icon"`
Tags struct {
UserDeviceTypeDisplayString string `json:"UserDeviceTypeDisplayString"`
} `json:"tags"`
History []float64 `json:"history"`
Avgw float64 `json:"avgw"`
TotalKwh float64 `json:"total_kwh"`
TotalCost int `json:"total_cost"`
CostHistory []int `json:"cost_history"`
} `json:"devices"`
TotalCost int `json:"total_cost"`
TotalCosts []int `json:"total_costs"`
} `json:"consumption"`
Production struct {
Total float64 `json:"total"`
Totals []float64 `json:"totals"`
Devices []interface{} `json:"devices"`
TotalCost int `json:"total_cost"`
TotalCosts []int `json:"total_costs"`
} `json:"production"`
ToGrid float64 `json:"to_grid"`
FromGrid float64 `json:"from_grid"`
ConsumptionPercentChange interface{} `json:"consumption_percent_change"`
ProductionPercentChange interface{} `json:"production_percent_change"`
ToGridCost int `json:"to_grid_cost"`
FromGridCost int `json:"from_grid_cost"`
TrendText interface{} `json:"trend_text"`
UsageText interface{} `json:"usage_text"`
Scale string `json:"scale"`
SolarPowered int `json:"solar_powered"`
NetProduction float64 `json:"net_production"`
ProductionPct int `json:"production_pct"`
}
type PayloadType string
func (p PayloadType) String() string {
return string(p)
}
const (
PayloadRealTimeUpdate PayloadType = "realtime_update"
PayloadDataChange PayloadType = "data_change"
PayloadMonitorInfo PayloadType = "monitor_info"
PayloadHello PayloadType = "hello"
PayloadErr PayloadType = "error"
)
type RealTime struct {
Payload struct {
Online bool `json:"online"`
Voltage []float64 `json:"voltage"`
Frame int `json:"frame"`
Devices []struct {
Id string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
Tags struct {
DefaultUserDeviceType string `json:"DefaultUserDeviceType"`
DeviceListAllowed string `json:"DeviceListAllowed"`
SSIEnabled string `json:"SSIEnabled,omitempty"`
TimelineAllowed string `json:"TimelineAllowed"`
UserDeviceType string `json:"UserDeviceType"`
UserDeviceTypeDisplayString string `json:"UserDeviceTypeDisplayString"`
UserEditable string `json:"UserEditable"`
UserDeleted string `json:"UserDeleted,omitempty"`
UserMergeable string `json:"UserMergeable,omitempty"`
} `json:"tags"`
Attrs []interface{} `json:"attrs"`
W float64 `json:"w"`
} `json:"devices"`
Deltas []interface{} `json:"deltas"`
DefaultCost int `json:"defaultCost"`
Channels []float64 `json:"channels"`
Hz float64 `json:"hz"`
W float64 `json:"w"`
C int `json:"c"`
TouAlert struct {
EndTime time.Time `json:"end_time"`
CostMultiplier float64 `json:"cost_multiplier"`
TouCost int `json:"tou_cost"`
Name string `json:"name"`
} `json:"tou_alert"`
SolarW float64 `json:"solar_w"`
SolarC int `json:"solar_c"`
Stats struct {
Brcv float64 `json:"brcv"`
Mrcv float64 `json:"mrcv"`
Msnd float64 `json:"msnd"`
} `json:"_stats"`
Aux struct {
Solar []float64 `json:"solar"`
} `json:"aux"`
DW int `json:"d_w"`
DSolarW int `json:"d_solar_w"`
GridW int `json:"grid_w"`
SolarPct int `json:"solar_pct"`
Epoch int `json:"epoch"`
Features string `json:"features"`
UserVersion int `json:"user_version"`
PartnerChecksum string `json:"partner_checksum"`
MonitorOverviewChecksum string `json:"monitor_overview_checksum"`
DeviceDataChecksum string `json:"device_data_checksum"`
SettingsVersion int `json:"settings_version"`
PendingEvents struct {
Type string `json:"type"`
NewDeviceFound struct {
DeviceId interface{} `json:"device_id"`
Guid string `json:"guid"`
Timestamp interface{} `json:"timestamp"`
} `json:"new_device_found"`
MonitorId int `json:"monitor_id"`
Goal struct {
Guid string `json:"guid"`
Timestamp interface{} `json:"timestamp"`
NotificationId interface{} `json:"notification_id"`
} `json:"goal"`
} `json:"pending_events"`
} `json:"payload"`
Type PayloadType `json:"type"`
}
func (r RealTime) String() string {
b, _ := json.Marshal(r)
return string(b)
}
type HistoryCompare struct {
PeriodTitle string `json:"period_title"`
SummaryCohortMarker int `json:"summary_cohort_marker"`
Comparisons []struct {
ComparisonText string `json:"comparison_text"`
TercileStrings []string `json:"tercile_strings"`
CohortMarker int `json:"cohort_marker"`
Cohort struct {
Id int `json:"id"`
PostalCode string `json:"postal_code"`
AreaCode string `json:"area_code"`
State string `json:"state"`
HomeSize string `json:"home_size"`
Location string `json:"location"`
} `json:"cohort"`
Title string `json:"title"`
W float64 `json:"w"`
CohortAvgW float64 `json:"cohort_avg_w"`
} `json:"comparisons"`
AvgW float64 `json:"avg_w"`
}