HydrawiseController.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @author Martijn Dierckx
  3. */
  4. import { Hydrawise, HydrawiseZone } from ".";
  5. /** Class representing a Hydrawise controller */
  6. export class HydrawiseController {
  7. public apiBinding: Hydrawise;
  8. public id: number;
  9. public name: string;
  10. public serialNumber: string;
  11. public lastContactWithCloud: Date;
  12. public status: string;
  13. /**
  14. * Create a new instance of a HydrawiseController
  15. * @param {object} options - Options object containing all parameters
  16. * @param {Hydrawise} options.apiBinding - The API binding which can be used to execute commands on the zone
  17. * @param {number} options.id - The unique identifier of the controller
  18. * @param {string} options.name - The name of the controller
  19. * @param {string} options.serialNumber - The serial number of the controller
  20. * @param {Date} options.lastContactWithCloud - The last date time the controller was able to contact/sync with the cloud
  21. * @param {string} options.status - The status as returned by the Hydrawise cloud
  22. */
  23. constructor(options: any) {
  24. this.apiBinding = options.apiBinding;
  25. this.id = options.id;
  26. this.name = options.name;
  27. this.serialNumber = options.serialNumber;
  28. this.lastContactWithCloud = options.lastContactWithCloud;
  29. this.status = options.status;
  30. }
  31. /**
  32. * Retrieves all zones/relays known to the server for this controller
  33. * @return {Promise} A Promise which will be resolved when all zones have been retrieved
  34. */
  35. public getZones(): Promise<HydrawiseZone[]> {
  36. return this.apiBinding.getZones(this);
  37. }
  38. /**
  39. * Sends the run command to all the zones/relays of the controller
  40. * @param {number} [duration] - How long should the command be executed
  41. * @return {Promise} A Promise which will be resolved when the command has been executed.
  42. */
  43. public runAllZones(duration?: number): Promise<any> {
  44. return this.apiBinding.commandAllZones('runall', this, duration);
  45. }
  46. /**
  47. * Sends the stop command to all the zones/relays of the controller
  48. * @return {Promise} A Promise which will be resolved when the command has been executed.
  49. */
  50. public stopAllZones(): Promise<any> {
  51. return this.apiBinding.commandAllZones('stopall', this);
  52. }
  53. /**
  54. * Sends the suspend command to all the zones/relays of the controller
  55. * @param {number} [duration] - How long should the command be executed
  56. * @return {Promise} A Promise which will be resolved when the command has been executed.
  57. */
  58. public suspendAllZones(duration?: number): Promise<any> {
  59. return this.apiBinding.commandAllZones('suspendall', this, duration);
  60. }
  61. }