-
Notifications
You must be signed in to change notification settings - Fork 1
/
devices.go
80 lines (64 loc) · 2.33 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
package flumewater
import (
"fmt"
"log"
"github.com/google/go-querystring/query"
)
type FlumeWaterFetchDeviceResponse struct {
*ResponseBase
Data []FlumeWaterDevice `json:"data"`
}
type FlumeWaterDevice struct {
ID string `json:"id"`
BridgeID string `json:"bridge_id"`
Type FlumeWaterDeviceType `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
AddedDatetime string `json:"added_datetime"`
UserID int `json:"user_id"`
Registered bool `json:"registered"`
Oriented bool `json:"oriented"`
LastSeen string `json:"last_seen"`
Location FlumeWaterLocation `json:"location"`
User FlumeWaterUser `json:"user"`
}
type FlumeWaterDeviceType int
const (
FlumeWaterDeviceTypeBridge FlumeWaterDeviceType = 1
FlumeWaterDeviceTypeSensor FlumeWaterDeviceType = 2
)
type FlumeWaterUsageProfile struct {
ID int `json:"id"`
Score int `json:"score"`
Residents string `json:"residents"`
Bathrooms string `json:"bathrooms"`
Irrigation string `json:"irrigation"`
IrrigationFreq string `json:"irrigation_freq"`
IrrigationMaxCycle int `json:"irrigation_max_cycle"`
}
type FlumeWaterFetchDeviceRequest struct {
IncludeUser bool `url:"user,omitempty"`
IncludeLocation bool `url:"location,omitempty"`
}
func (fw *Client) FetchUserDevices(queryParams FlumeWaterFetchDeviceRequest) (devices []FlumeWaterDevice, err error) {
v, _ := query.Values(queryParams)
fetchURL := baseURL + "/users/" + fmt.Sprint(fw.UserID()) + "/devices?" + v.Encode()
var flumeResp FlumeWaterFetchDeviceResponse
err = fw.FlumeGet(fetchURL, &flumeResp)
if err != nil {
log.Fatal(err)
}
devices = flumeResp.Data
return devices, nil
}
func (fw *Client) FetchUserDevice(deviceID string, queryParams FlumeWaterFetchDeviceRequest) (device FlumeWaterDevice, err error) {
v, _ := query.Values(queryParams)
fetchURL := baseURL + "/users/" + fmt.Sprint(fw.UserID()) + "/devices/" + deviceID + "?" + v.Encode()
var flumeResp FlumeWaterFetchDeviceResponse
err = fw.FlumeGet(fetchURL, &flumeResp)
if err != nil {
log.Fatal(err)
}
device = flumeResp.Data[0]
return device, nil
}