Parcourir la source

Fix setcontroller; add setzone endpoint and tests

Paul Molluzzo il y a 9 ans
Parent
commit
54e0b10bc3
2 fichiers modifiés avec 24 ajouts et 5 suppressions
  1. 6 2
      src/hydrawise.js
  2. 18 3
      test/index.js

+ 6 - 2
src/hydrawise.js

@@ -27,8 +27,12 @@ class Hydrawise {
     return this.request('GET', 'statusschedule', {tag, hours});
   }
 
-  setcontroller(controller_id) {
-    return this.request('GET', 'setcontroller', {controller_id, json: true});
+  setcontroller(controllerid) {
+    return this.request('GET', 'setcontroller', {controllerid, json: true});
+  }
+
+  setzone(action, params) {
+    return this.request('GET', 'setzone', {action, ...params});
   }
 }
 

+ 18 - 3
test/index.js

@@ -31,9 +31,24 @@ test('Status Schedule All', t => {
 });
 
 test('Set Controller', t => {
-  return hydrawise.setcontroller('11742').then(data => {
-    if (data.error_msg) {
-      t.fail(`Error: ${data.error_msg}`);
+  return hydrawise.setcontroller('11774').then(() => {
+    t.pass();
+  });
+});
+
+test('Stop Zones', t => {
+  return hydrawise.setzone('stopall').then(data => {
+    if (data.message_type === 'error') {
+      t.fail(`Error: ${data.message}`);
+    }
+    t.pass();
+  });
+});
+
+test('Run All Zones', t => {
+  return hydrawise.setzone('runall', {period_id: '999', custom: '60'}).then(data => {
+    if (data.message_type === 'error') {
+      t.fail(`Error: ${data.message}`);
     }
     t.pass();
   });