| ... | ... |
@@ -275,6 +275,46 @@ function get_status() {
|
| 275 | 275 |
} |
| 276 | 276 |
|
| 277 | 277 |
|
| 278 |
+function timed_switch_home(duration) {
|
|
| 279 |
+ var response; |
|
| 280 |
+ console.log('---- authenticate');
|
|
| 281 |
+ if (sid != "") {
|
|
| 282 |
+ var epoch = Math.round(new Date().getTime() / 1000.0); |
|
| 283 |
+ var start_ts = epoch //+ 10 |
|
| 284 |
+ var end_ts = duration + start_ts |
|
| 285 |
+ console.log('---- switching home mode for ' + duration + 'seconds');
|
|
| 286 |
+ url_path = "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=SaveOneTimeSwitch&onetime_enable_on=true&onetime_disable_on=true&onetime_enable_time=" + start_ts + "&onetime_disable_time=" + end_ts + "&_sid=" + sid; |
|
| 287 |
+ method = "GET" |
|
| 288 |
+ onload_switch_function = function (xhr) {
|
|
| 289 |
+ response = JSON.parse(xhr.responseText); |
|
| 290 |
+ if (response.success == true) {
|
|
| 291 |
+ message = "Home mode is ON for "+duration+" seconds"; |
|
| 292 |
+ }else{
|
|
| 293 |
+ message = "something happened, try again ! (S200)"; |
|
| 294 |
+ } |
|
| 295 |
+ // Build message |
|
| 296 |
+ dict = {
|
|
| 297 |
+ 'status': message, |
|
| 298 |
+ }; |
|
| 299 |
+ |
|
| 300 |
+ // Send the message Home mode is ON for 900 seconds |
|
| 301 |
+ Pebble.sendAppMessage(dict, function (e) {
|
|
| 302 |
+ console.log('sent \"'+message+'\"');
|
|
| 303 |
+ }, function () {
|
|
| 304 |
+ console.log('failed');
|
|
| 305 |
+ }); |
|
| 306 |
+ } |
|
| 307 |
+ max_retry = 10; |
|
| 308 |
+ xhr_to_syno(method, url_path, onload_switch_function, max_retry); |
|
| 309 |
+ |
|
| 310 |
+ |
|
| 311 |
+ } else {
|
|
| 312 |
+ authenticate(); |
|
| 313 |
+ switch_home(bool); |
|
| 314 |
+ } |
|
| 315 |
+ |
|
| 316 |
+} |
|
| 317 |
+ |
|
| 278 | 318 |
function switch_home(bool) {
|
| 279 | 319 |
var response; |
| 280 | 320 |
console.log('---- authenticate');
|
| ... | ... |
@@ -343,7 +383,8 @@ Pebble.addEventListener('appmessage', function (e) {
|
| 343 | 383 |
get_status(); |
| 344 | 384 |
break; |
| 345 | 385 |
case 'home_on': |
| 346 |
- switch_home(true); |
|
| 386 |
+ //switch_home(true); |
|
| 387 |
+ timed_switch_home(15*60) |
|
| 347 | 388 |
break; |
| 348 | 389 |
case 'home_off': |
| 349 | 390 |
switch_home(false); |