-
Notifications
You must be signed in to change notification settings - Fork 4
/
devices.clj
168 lines (140 loc) · 4.71 KB
/
devices.clj
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
(ns happygapi.homegraph.devices
"HomeGraph API: devices.
See: https://developers.google.com/actions/smarthome/create-app#request-syncapi/reference/rest/v1/devices"
(:require [cheshire.core :as json]
[clj-http.client :as http]
[happy.util :as util]))
(defn sync$
"https://developers.google.com/actions/smarthome/create-app#request-syncapi/reference/rest/v1/devices/sync
Required parameters: none
Optional parameters: none
Body:
{:requestId string, :agentUserId string}
Gets all the devices associated with the given third-party user.
The third-party user's identity is passed in as `agent_user_id`. The agent
is identified by the JWT signed by the third-party partner's service
account."
{:scopes nil}
[auth args body]
{:pre [(util/has-keys? args #{})]}
(util/get-response
(http/post
(util/get-url
"https://homegraph.googleapis.com/"
"v1/devices:sync"
#{}
args)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn reportStateAndNotification$
"https://developers.google.com/actions/smarthome/create-app#request-syncapi/reference/rest/v1/devices/reportStateAndNotification
Required parameters: none
Optional parameters: none
Body:
{:followUpToken string,
:eventId string,
:agentUserId string,
:payload {:devices ReportStateAndNotificationDevice},
:requestId string}
Reports device state and optionally sends device notifications. Called by
an agent when the device state of a third-party changes or the agent wants
to send a notification about the device. See
[Implement Report State](/actions/smarthome/report-state) for more
information.
This method updates a predefined set of states for a device, which all
devices have according to their prescribed traits (for example, a light
will have the [OnOff](/actions/smarthome/traits/onoff) trait that reports
the state `on` as a boolean value).
A new state may not be created and an INVALID_ARGUMENT code will be thrown
if so. It also optionally takes in a list of Notifications that may be
created, which are associated to this state change.
The third-party user's identity is passed in as `agent_user_id`.
The agent is identified by the JWT signed by the partner's service account."
{:scopes nil}
[auth args body]
{:pre [(util/has-keys? args #{})]}
(util/get-response
(http/post
(util/get-url
"https://homegraph.googleapis.com/"
"v1/devices:reportStateAndNotification"
#{}
args)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn requestSync$
"https://developers.google.com/actions/smarthome/create-app#request-syncapi/reference/rest/v1/devices/requestSync
Required parameters: none
Optional parameters: none
Body:
{:agentUserId string, :async boolean}
Requests a `SYNC` call from Google to a 3p partner's home control agent for
a user.
The third-party user's identity is passed in as `agent_user_id`
(see RequestSyncDevicesRequest) and forwarded back to the agent.
The agent is identified by the API key or JWT signed by the partner's
service account."
{:scopes nil}
[auth args body]
{:pre [(util/has-keys? args #{})]}
(util/get-response
(http/post
(util/get-url
"https://homegraph.googleapis.com/"
"v1/devices:requestSync"
#{}
args)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn query$
"https://developers.google.com/actions/smarthome/create-app#request-syncapi/reference/rest/v1/devices/query
Required parameters: none
Optional parameters: none
Body:
{:requestId string,
:inputs [{:payload QueryRequestPayload}],
:agentUserId string}
Gets the device states for the devices in QueryRequest.
The third-party user's identity is passed in as `agent_user_id`. The agent
is identified by the JWT signed by the third-party partner's service
account."
{:scopes nil}
[auth args body]
{:pre [(util/has-keys? args #{})]}
(util/get-response
(http/post
(util/get-url
"https://homegraph.googleapis.com/"
"v1/devices:query"
#{}
args)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))