-
Notifications
You must be signed in to change notification settings - Fork 16
/
netatmoNodes.html
403 lines (366 loc) · 17.7 KB
/
netatmoNodes.html
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
<!--
Copyright 2016 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- ************************************************************* -->
<!-- * Generic Functions * -->
<!-- ************************************************************* -->
<script type="text/javascript">
/* global $ RED */
// eslint-disable-next-line no-unused-vars
function oneditprepareDeviceId(required, typeFilter = null) {
$('#node-input-deviceId-scan').click(function()
{
const nodeIdCred = $('#node-input-creds option:selected').val();
const current = $('#node-input-deviceId').val();
$('#node-input-deviceId').replaceWith('<select id="node-input-deviceId" style="width: 100%"></select>');
$('#node-input-deviceId').append('<option selected="selected" value="null">Searching for devices...</option>');
$.get('netatmo/homes', {nodeIdCred:nodeIdCred})
.done( function(body) {
const data = JSON.parse(body);
if(data.error) {
RED.notify(data.error, { type: "error" });
}
const homes = data.homes;
// RESET OPTIONS
$('#node-input-deviceId').empty();
if(homes.length <= 0) {
// Create input
$('#node-input-deviceId').replaceWith('<input type="text" id="node-input-deviceId" placeholder="5bXXXXXXXXXXXXXXXXXXXXXX" style="width: 100%"/>');
$('#node-input-deviceId').val(current);
RED.notify("no homes found", { type: "error" });
} else {
// Create select
$('#node-input-deviceId').replaceWith('<select required id="node-input-deviceId" style="width: 100%"></select>');
if (!required) {
$('#node-input-deviceId').append('<option value="">(blank)</option>');
}
// SET modules AS OPTIONS
homes.forEach(function(home) {
if (home.modules.length >= 0) {
home.modules.forEach(function(module) {
if (!typeFilter || typeFilter === module.type) {
$('#node-input-deviceId').append('<option value="' + module.id + '">' + module.name + ' (' + module.type + ') - ' + module.id + '</option>');
}
});
}
});
$('#node-input-deviceId').val(current);
}
});
});
}
// eslint-disable-next-line no-unused-vars
function oneditprepareHomeId(required) {
$('#node-input-homeId-scan').click(function()
{
const nodeIdCred = $('#node-input-creds option:selected').val();
const current = $('#node-input-homeId').val();
$('#node-input-homeId').replaceWith('<select id="node-input-homeId" style="width: 100%"></select>');
$('#node-input-homeId').append('<option selected="selected" value="null">Searching for homes...</option>');
$.get('netatmo/homes', {nodeIdCred:nodeIdCred})
.done( function(body) {
const data = JSON.parse(body);
if(data.error) {
RED.notify(data.error, { type: "error" });
}
const homes = data.homes;
// RESET OPTIONS
$('#node-input-homeId').empty();
if(homes.length <= 0) {
// Create input
$('#node-input-homeId').replaceWith('<input type="text" id="node-input-homeId" placeholder="5bXXXXXXXXXXXXXXXXXXXXXX" style="width: 100%"/>');
$('#node-input-homeId').val(current);
RED.notify("no home found", { type: "error" });
} else {
// Create select
$('#node-input-homeId').replaceWith('<select id="node-input-homeId" style="width: 100%"></select>');
if (!required) {
$('#node-input-homeId').append('<option value="">(blank)</option>');
} // SET homes AS OPTIONS
homes.forEach(function(home) {
$('#node-input-homeId').append('<option value="' + home.id + '">' + home.name + '</option>');
});
$('#node-input-homeId').val(current);
}
});
});
}
// eslint-disable-next-line no-unused-vars
function oneditprepareRooms(required) {
$('#node-input-roomId-scan').click(function()
{
const nodeIdCred = $('#node-input-creds option:selected').val();
const current = $('#node-input-roomId').val();
const currentHomeId = $('#node-input-homeId').val();
$('#node-input-roomId').replaceWith('<select id="node-input-roomId" style="width: 100%"></select>');
$('#node-input-roomId').append('<option selected="selected" value="null">Searching for rooms...</option>');
$.get('netatmo/homes', {nodeIdCred:nodeIdCred})
.done( function(body) {
const data = JSON.parse(body);
if(data.error) {
RED.notify(data.error, { type: "error" });
}
const homes = data.homes;
// RESET OPTIONS
$('#node-input-roomId').empty();
if(homes.length <= 0) {
// Create input
$('#node-input-roomId').replaceWith('<input type="text" id="node-input-roomId" placeholder="xxxxxxxxxx" style="width: 100%"/>');
$('#node-input-roomId').val(current);
RED.notify("no rooms found", { type: "error" });
} else {
// Create select
$('#node-input-roomId').replaceWith('<select id="node-input-roomId" style="width: 100%"></select>');
if (!required) {
$('#node-input-roomId').append('<option value="">(blank)</option>');
}
// SET rooms AS OPTIONS
homes.forEach(function(home) {
if((currentHomeId === '' || home.id === currentHomeId) && home.rooms) {
home.rooms.forEach(function(room) {
$('#node-input-roomId').append('<option value="' + room.id + '">' + room.name + ' (' + room.type + ') - ' + room.id + '</option>');
});
}
});
$('#node-input-roomId').val(current);
}
});
});
}
// eslint-disable-next-line no-unused-vars
function oneditpreparePersonId(required) {
$('#node-input-personId-scan').click(function()
{
const nodeIdCred = $('#node-input-creds option:selected').val();
const current = $('#node-input-personId').val();
const currentHomeId = $('#node-input-homeId').val();
$('#node-input-personId').replaceWith('<select id="node-input-personId" style="width: 100%"></select>');
$('#node-input-personId').append('<option selected="selected" value="null">Searching for persons...</option>');
$.get('netatmo/homes', {nodeIdCred:nodeIdCred})
.done( function(body) {
const data = JSON.parse(body);
if(data.error) {
RED.notify(data.error, { type: "error" });
}
const homes = data.homes;
// RESET OPTIONS
$('#node-input-personId').empty();
if(homes.length <= 0) {
// Create input
$('#node-input-personId').replaceWith('<input type="text" id="node-input-personId" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" style="width: 100%"/>');
$('#node-input-personId').val(current);
RED.notify("no rooms found", { type: "error" });
} else {
// Create select
$('#node-input-personId').replaceWith('<select id="node-input-personId" style="width: 100%"></select>');
if (!required) {
$('#node-input-personId').append('<option value="">(blank)</option>');
}
// SET rooms AS OPTIONS
homes.forEach(function(home) {
if((currentHomeId === '' || home.id === currentHomeId) && home.persons) {
home.persons.forEach(function(person) {
$('#node-input-personId').append('<option value="' + person.id + '">' + person.pseudo + ' - ' + person.id + '</option>');
});
}
});
$('#node-input-personId').val(current);
}
});
});
}
</script>
<!-- *************************************************************
* Api is marked as deprecated by netatmo
************************************************************* -->
<script type="text/javascript">
console.log("registering netatmo get next events");
/* global RED */
RED.nodes.registerType('get next events',{
category: 'Netatmo',
color: '#87A980',
defaults: {
name: {value:""},
creds: {value:"",type:"configNode"},
home_id: {value:""},
event_id: {value:""}
},
inputs:1,
outputs:1,
icon: "font-awesome/fa-video-camera",
label: function() {
return this.name||"get next events";
}
});
</script>
<script type="text/html" data-template-name="get next events">
<div class="form-row">
<label for="node-input-creds"><i class="fa fa-server"></i> Creds</label>
<input type="text" id="node-input-creds" placeholder="Add netatmo creds">
</div>
<div class="form-row">
<label for="node-input-home_id"><i class="icon-tag"></i> Home ID:</label>
<input type="text" id="node-input-home_id" placeholder="577fff...">
</div>
<div class="form-row">
<label for="node-input-event_id"><i class="icon-tag"></i> Event ID:</label>
<input type="text" id="node-input-event_id" placeholder="57816...">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="get next events">
<p><b>Api is marked as deprecated by netatmo.</b></p>
<p>This node returns information about the netatmo welcome next events with these credentials.</p>
<p>Parameters:</p>
<ul>
<li>Home ID: something like 577fff842baa3c18948b4571</li>
<li>Event ID: something like 5781611045a1e322938b458f</li>
</ul>
<p>Outputs an object called <b>msg</b> containing <b>msg.topic</b> and
<b>msg.payload</b>. msg.payload is JSON.</p>
<p>See <a href="https://dev.netatmo.com/dev/resources/technical/reference/welcome/getnextevents" target=_blank>https://dev.netatmo.com/dev/resources/technical/reference/welcome/getnextevents</a> for details on format</p>
</script>
<!-- *************************************************************
* Api is marked as deprecated by netatmo
************************************************************* -->
<script type="text/javascript">
console.log("registering netatmo get camera picture");
RED.nodes.registerType('get camera picture',{
category: 'Netatmo',
color: '#87A980',
defaults: {
name: {value:""},
creds: {value:"",type:"configNode"},
image_id: {value:""},
key: {value:""}
},
inputs:1,
outputs:1,
icon: "font-awesome/fa-video-camera",
label: function() {
return this.name||"get camera picture";
}
});
</script>
<script type="text/html" data-template-name="get camera picture">
<div class="form-row">
<label for="node-input-creds"><i class="fa fa-server"></i> Creds</label>
<input type="text" id="node-input-creds" placeholder="Add netatmo creds">
</div>
<div class="form-row">
<label for="node-input-image_id"><i class="icon-tag"></i> Image ID</label>
<input type="text" id="node-input-image_id" placeholder="56c89c83...">
</div>
<div class="form-row">
<label for="node-input-key"><i class="icon-tag"></i> Security Key</label>
<input type="text" id="node-input-key" placeholder="8627b4...">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="get camera picture">
<p><b>Api is marked as deprecated by netatmo.</b></p>
<p>This node returns information about the netatmo welcome camera picture with these credentials.</p>
<p>Outputs an object called <b>msg</b> containing <b>msg.topic</b> and
<b>msg.payload</b>. msg.payload is JSON.</p>
<p>See <a href="https://dev.netatmo.com/dev/resources/technical/reference/welcome/getcamerapicture" target=_blank>https://dev.netatmo.com/dev/resources/technical/reference/welcome/getcamerapicturer</a> for details on format</p>
</script>
<!-- *************************************************************
* Api is marked as deprecated by netatmo
************************************************************* -->
<script type="text/javascript">
console.log("registering netatmo get home data");
RED.nodes.registerType('get home data',{
category: 'Netatmo',
color: '#87A980',
defaults: {
name: {value:""},
creds: {value:"",type:"configNode"}
},
inputs:1,
outputs:1,
icon: "font-awesome/fa-video-camera",
label: function() {
return this.name||"get home data";
}
});
</script>
<script type="text/html" data-template-name="get home data">
<div class="form-row">
<label for="node-input-creds"><i class="fa fa-server"></i> Creds</label>
<input type="text" id="node-input-creds" placeholder="Add netatmo creds">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="get home data">
<p><b>Api is marked as deprecated by netatmo!</b></p>
<p>This node returns information about the netatmo welcome home data with these credentials.</p>
<p>Outputs an object called <b>msg</b> containing <b>msg.topic</b> and
<b>msg.payload</b>. msg.payload is JSON.</p>
<p>See <a href="https://dev.netatmo.com/dev/resources/technical/reference/welcome/gethomedata" target=_blank>https://dev.netatmo.com/dev/resources/technical/reference/welcome/gethomedata</a> for details on format</p>
</script>
<!-- ************************************************************* -->
<!-- * Configuration Node * -->
<!-- ************************************************************* -->
<script type="text/javascript">
RED.nodes.registerType('configNode',{
category: 'config',
credentials: {
client_id: {type:"text"},
client_secret: {type:"text"},
username: {type:"text"},
password: {type:"password"}
},
defaults: {
name: {value:""}
},
label: function() {
return this.name||"netatmo configNode";
},
oneditprepare: function() {
}
});
</script>
<script type="text/html" data-template-name="configNode">
<div class="form-row">
<label for="node-config-input-client_id"><i class="fa fa-tag"></i> Client ID</label>
<input required type="text" id="node-config-input-client_id" placeholder="56e984c449c7...">
</div>
<div class="form-tips"><b>Tip:</b> Client ID from App information page in your Netatmo connect Account</div><br/>
<div class="form-row">
<label for="node-config-input-client_secret"><i class="fa fa-tag"></i> Client Secret</label>
<input required type="text" id="node-config-input-client_secret" placeholder="X4l1Ct9G....">
</div>
<div class="form-tips"><b>Tip:</b> Client secret from App information page in your Netatmo connect Account</div><br/>
<div class="form-row">
<label for="node-config-input-username"><i class="fa fa-user"></i> User name</label>
<input required type="text" id="node-config-input-username" placeholder="[email protected]">
</div>
<div class="form-tips"><b>Tip:</b> User of your Netatmo connect Account</div><br/>
<div class="form-row">
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
<input required type="password" id="node-config-input-password" placeholder="yourPassword">
</div>
<div class="form-tips"><b>Tip:</b> Password of your Netatmo connect Account</div><br/>
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
</script>