-
Notifications
You must be signed in to change notification settings - Fork 4
/
devices.go
156 lines (139 loc) · 4.75 KB
/
devices.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
package emporia
import (
"encoding/json"
"fmt"
"net/url"
)
type (
DeviceResponse struct {
CustomerGID int `json:"customerGid"`
Email string `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
CreatedAt string `json:"createdAt"`
Devices []Device `json:"devices"`
}
Device struct {
DeviceGID uint64 `json:"deviceGid"`
ManufacturerDeviceID string `json:"manufacturerDeviceId"`
Model string `json:"model"`
Firmware string `json:"firmware"`
Channels []Channel `json:"channels"`
Devices []Device `json:"devices"`
LocationProperties LocationProperty `json:"locationProperties"`
}
LocationProperty struct {
DeviceGID uint64 `json:"deviceGid"`
DeviceName string `json:"deviceName"`
ZipCode string `json:"zipCode"`
TimeZone string `json:"timeZone"`
BillingCycleStartDay int `json:"billingCycleStartDay"`
UsageCentPerKwHour float64 `json:"usageCentPerKwHour"`
PeakDemandDollarPerKw float64 `json:"peakDemandDollarPerKw"`
LocationInformation LocationInformation `json:"locationInformation"`
LatitudeLongitude LatitudeLongitude `json:"latitudeLongitude"`
}
LatitudeLongitude struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}
Channel struct {
DeviceGID int `json:"deviceGid"`
Name string `json:"name"`
ChannelNum string `json:"channelNum"`
ChannelMultiplier float64 `json:"channelMultiplier"`
ChannelTypeGID int `json:"channelTypeGid"`
}
LocationInformation struct {
AirConditioning bool `json:"airConditioning"`
HeatSource string `json:"heatSource"`
LocationSqFt string `json:"locationSqFt"`
NumElectricCars string `json:"numElectricCars"`
LocationType string `json:"locationType"`
NumPeople string `json:"numPeople"`
SwimmingPool bool `json:"swimmingPool"`
HotTub bool `json:"hotTub"`
}
)
type ChannelType uint8
const (
AirConditioner ChannelType = 1
Battery ChannelType = 2
Boiler ChannelType = 3
ClothesDryer ChannelType = 4
ClothesWasher ChannelType = 5
Computer ChannelType = 6
Cooktop ChannelType = 7
Dishwasher ChannelType = 8
ElectricVehicle ChannelType = 9
Fridge ChannelType = 10
Furnace ChannelType = 11
Garage ChannelType = 12
Solar ChannelType = 13
HotTub ChannelType = 14
Humidifier ChannelType = 15
Kitchen ChannelType = 16
Microwave ChannelType = 17
Other ChannelType = 18
Pump ChannelType = 19
Room ChannelType = 20
SubPanel ChannelType = 21
WaterHeater ChannelType = 22
HeatPump ChannelType = 24
Lights ChannelType = 26
)
var ChannelTypeLookup = map[string]ChannelType{
"Air Conditioner": AirConditioner,
"Battery": Battery,
"Boiler": Boiler,
"Clothes Dryer": ClothesDryer,
"Clothes Washer": ClothesWasher,
"Computer/Network": Computer,
"Cooktop/Range/Oven/Stove": Cooktop,
"Dishwasher": Dishwasher,
"Electric Vehicle/RV": ElectricVehicle,
"Fridge/Freezer": Fridge,
"Furnace": Furnace,
"Garage/Shop/Barn/Shed": Garage,
"Solar/Generation": Solar,
"Hot Tub/Spa": HotTub,
"Humidifier/Dehumidifier": Humidifier,
"Kitchen": Kitchen,
"Microwave": Microwave,
"Other": Other,
"Pump": Pump,
"Room/Multi-use Circuit": Room,
"Sub Panel": SubPanel,
"Water Heater": WaterHeater,
"Heat Pump": HeatPump,
"Lights": Lights,
}
func (c *Client) GetDevices() (*DeviceResponse, error) {
url, err := url.Parse(fmt.Sprintf("%s/customers/devices", apiBaseURL))
if err != nil {
return nil, err
}
var deviceResponse DeviceResponse
resp, err := c.get(url)
if err != nil {
return nil, fmt.Errorf("failed to get devices: %v", err)
}
defer resp.Body.Close()
if err := json.NewDecoder(resp.Body).Decode(&deviceResponse); err != nil {
return nil, fmt.Errorf("failed to decode devices: %v", err)
}
return &deviceResponse, nil
}
func (c *Client) GetSolar() (*[]Device, error) {
devices, err := c.GetDevices()
if err != nil {
return nil, err
}
var solarDevices []Device
for _, device := range devices.Devices {
if device.Model == "Solar" {
solarDevices = append(solarDevices, device)
}
}
return &solarDevices, nil
}