1
0

HydrawiseZone.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. /**
  3. * @author Martijn Dierckx
  4. */
  5. /** Class representing a Hydrawise zone */
  6. class HydrawiseZone {
  7. /**
  8. * Create a new instance of a HydrawiseZone
  9. * @param {object} options - Options object containing all parameters
  10. * @param {Hydrawise} options.apiBinding - The API binding which can be used to execute commands on the zone
  11. * @param {number} options.relayID - The unique relay number known to the Hydrawise cloud
  12. * @param {number} options.zone - The local zone/relay number
  13. * @param {string} options.name - The name of the zone
  14. * @param {Date} options.nextRunAt - The date & time of the next scheduled run
  15. * @param {number} options.nextRunDuration - Run time in seconds of the next run defined by nextRunAt
  16. * @param {boolean} options.isSuspended - Returns true when the zoneis currently suspended
  17. * @param {boolean} options.isRunning - Returns true when the zone is actively running
  18. * @param {number} options.remainingRunningTime - Remaining run time in seconds when isRunning = true
  19. */
  20. constructor(options) {
  21. this.apiBinding = options.apiBinding;
  22. this.relayID = options.relayID;
  23. this.zone = options.zone;
  24. this.name = options.name;
  25. this.nextRunAt = options.nextRunAt;
  26. this.nextRunDuration = options.nextRunDuration;
  27. this.isSuspended = options.isSuspended;
  28. this.isRunning = options.isRunning;
  29. this.remainingRunningTime = options.remainingRunningTime;
  30. }
  31. /**
  32. * Sends the run command to the zone/relay
  33. * @param {number} [duration] - How long should the command be executed
  34. * @return {Promise} A Promise which will be resolved when the command has been executed.
  35. */
  36. run(duration) {
  37. return this.apiBinding.commandZone('run', this, duration);
  38. }
  39. /**
  40. * Sends the stop command to the zone/relay
  41. * @return {Promise} A Promise which will be resolved when the command has been executed.
  42. */
  43. stop() {
  44. return this.apiBinding.commandZone('stop', this);
  45. }
  46. /**
  47. * Sends the suspend command to the zone/relay
  48. * @param {number} [duration] - How long should the command be executed
  49. * @return {Promise} A Promise which will be resolved when the command has been executed.
  50. */
  51. suspend(duration) {
  52. return this.apiBinding.commandZone('suspend', this, duration);
  53. }
  54. }
  55. module.exports = options => {
  56. return new HydrawiseZone(options);
  57. };