@switchbot/homebridge-switchbot 3.7.1-beta.12 → 3.7.1-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/device/blindtilt.d.ts +8 -8
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +34 -66
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +9 -9
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +61 -97
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +13 -13
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +38 -73
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +12 -12
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +41 -79
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +5 -5
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +20 -42
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +5 -5
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +36 -71
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/device.d.ts +18 -18
  26. package/dist/device/device.d.ts.map +1 -1
  27. package/dist/device/device.js +33 -36
  28. package/dist/device/device.js.map +1 -1
  29. package/dist/device/fan.d.ts +8 -8
  30. package/dist/device/fan.d.ts.map +1 -1
  31. package/dist/device/fan.js +43 -75
  32. package/dist/device/fan.js.map +1 -1
  33. package/dist/device/hub.d.ts +5 -5
  34. package/dist/device/hub.d.ts.map +1 -1
  35. package/dist/device/hub.js +18 -39
  36. package/dist/device/hub.js.map +1 -1
  37. package/dist/device/humidifier.d.ts +5 -5
  38. package/dist/device/humidifier.d.ts.map +1 -1
  39. package/dist/device/humidifier.js +38 -78
  40. package/dist/device/humidifier.js.map +1 -1
  41. package/dist/device/iosensor.d.ts +5 -5
  42. package/dist/device/iosensor.d.ts.map +1 -1
  43. package/dist/device/iosensor.js +21 -40
  44. package/dist/device/iosensor.js.map +1 -1
  45. package/dist/device/lightstrip.d.ts +6 -6
  46. package/dist/device/lightstrip.d.ts.map +1 -1
  47. package/dist/device/lightstrip.js +34 -73
  48. package/dist/device/lightstrip.js.map +1 -1
  49. package/dist/device/lock.d.ts +9 -9
  50. package/dist/device/lock.d.ts.map +1 -1
  51. package/dist/device/lock.js +37 -52
  52. package/dist/device/lock.js.map +1 -1
  53. package/dist/device/meter.d.ts +5 -5
  54. package/dist/device/meter.d.ts.map +1 -1
  55. package/dist/device/meter.js +21 -39
  56. package/dist/device/meter.js.map +1 -1
  57. package/dist/device/meterplus.d.ts +5 -5
  58. package/dist/device/meterplus.d.ts.map +1 -1
  59. package/dist/device/meterplus.js +21 -38
  60. package/dist/device/meterplus.js.map +1 -1
  61. package/dist/device/motion.d.ts +5 -5
  62. package/dist/device/motion.d.ts.map +1 -1
  63. package/dist/device/motion.js +14 -32
  64. package/dist/device/motion.js.map +1 -1
  65. package/dist/device/plug.d.ts +12 -12
  66. package/dist/device/plug.d.ts.map +1 -1
  67. package/dist/device/plug.js +16 -25
  68. package/dist/device/plug.js.map +1 -1
  69. package/dist/device/robotvacuumcleaner.d.ts +11 -11
  70. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  71. package/dist/device/robotvacuumcleaner.js +42 -56
  72. package/dist/device/robotvacuumcleaner.js.map +1 -1
  73. package/dist/device/waterdetector.d.ts +5 -5
  74. package/dist/device/waterdetector.d.ts.map +1 -1
  75. package/dist/device/waterdetector.js +22 -37
  76. package/dist/device/waterdetector.js.map +1 -1
  77. package/dist/homebridge-ui/server.js +2 -2
  78. package/dist/homebridge-ui/server.js.map +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +0 -4
  81. package/dist/index.js.map +1 -1
  82. package/dist/irdevice/airconditioner.d.ts +8 -8
  83. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  84. package/dist/irdevice/airconditioner.js +64 -105
  85. package/dist/irdevice/airconditioner.js.map +1 -1
  86. package/dist/irdevice/airpurifier.d.ts +10 -10
  87. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  88. package/dist/irdevice/airpurifier.js +22 -42
  89. package/dist/irdevice/airpurifier.js.map +1 -1
  90. package/dist/irdevice/camera.d.ts +9 -9
  91. package/dist/irdevice/camera.d.ts.map +1 -1
  92. package/dist/irdevice/camera.js +15 -25
  93. package/dist/irdevice/camera.js.map +1 -1
  94. package/dist/irdevice/fan.d.ts +8 -8
  95. package/dist/irdevice/fan.d.ts.map +1 -1
  96. package/dist/irdevice/fan.js +21 -40
  97. package/dist/irdevice/fan.js.map +1 -1
  98. package/dist/irdevice/irdevice.d.ts +11 -11
  99. package/dist/irdevice/irdevice.d.ts.map +1 -1
  100. package/dist/irdevice/irdevice.js +14 -22
  101. package/dist/irdevice/irdevice.js.map +1 -1
  102. package/dist/irdevice/light.d.ts +9 -9
  103. package/dist/irdevice/light.d.ts.map +1 -1
  104. package/dist/irdevice/light.js +24 -47
  105. package/dist/irdevice/light.js.map +1 -1
  106. package/dist/irdevice/other.d.ts +9 -9
  107. package/dist/irdevice/other.d.ts.map +1 -1
  108. package/dist/irdevice/other.js +40 -83
  109. package/dist/irdevice/other.js.map +1 -1
  110. package/dist/irdevice/tv.d.ts +9 -9
  111. package/dist/irdevice/tv.d.ts.map +1 -1
  112. package/dist/irdevice/tv.js +29 -54
  113. package/dist/irdevice/tv.js.map +1 -1
  114. package/dist/irdevice/vacuumcleaner.d.ts +5 -5
  115. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  116. package/dist/irdevice/vacuumcleaner.js +11 -21
  117. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  118. package/dist/irdevice/waterheater.d.ts +5 -5
  119. package/dist/irdevice/waterheater.d.ts.map +1 -1
  120. package/dist/irdevice/waterheater.js +11 -22
  121. package/dist/irdevice/waterheater.js.map +1 -1
  122. package/dist/platform.d.ts +5 -6
  123. package/dist/platform.d.ts.map +1 -1
  124. package/dist/platform.js +141 -146
  125. package/dist/platform.js.map +1 -1
  126. package/dist/settings.d.ts +2 -2
  127. package/dist/settings.d.ts.map +1 -1
  128. package/dist/settings.js.map +1 -1
  129. package/dist/types/bledevicestatus.d.ts +9 -9
  130. package/dist/types/bledevicestatus.d.ts.map +1 -1
  131. package/dist/types/devicelist.d.ts +6 -6
  132. package/dist/types/devicelist.d.ts.map +1 -1
  133. package/dist/types/deviceresponse.d.ts +4 -4
  134. package/dist/types/deviceresponse.d.ts.map +1 -1
  135. package/dist/types/devicestatus.d.ts +2 -2
  136. package/dist/types/devicestatus.d.ts.map +1 -1
  137. package/dist/types/devicewebhookstatus.d.ts +5 -5
  138. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  139. package/dist/types/irdevicelist.d.ts +4 -4
  140. package/dist/types/irdevicelist.d.ts.map +1 -1
  141. package/dist/types/pushbody.d.ts +2 -2
  142. package/dist/types/pushbody.d.ts.map +1 -1
  143. package/dist/utils.d.ts +4 -4
  144. package/dist/utils.d.ts.map +1 -1
  145. package/dist/utils.js +9 -13
  146. package/dist/utils.js.map +1 -1
  147. package/eslint.config.js +48 -93
  148. package/package.json +54 -47
  149. package/src/device/blindtilt.ts +419 -456
  150. package/src/device/bot.ts +656 -693
  151. package/src/device/ceilinglight.ts +331 -364
  152. package/src/device/colorbulb.ts +412 -448
  153. package/src/device/contact.ts +200 -221
  154. package/src/device/curtain.ts +400 -435
  155. package/src/device/device.ts +206 -208
  156. package/src/device/fan.ts +307 -340
  157. package/src/device/hub.ts +184 -209
  158. package/src/device/humidifier.ts +297 -342
  159. package/src/device/iosensor.ts +182 -204
  160. package/src/device/lightstrip.ts +362 -399
  161. package/src/device/lock.ts +262 -276
  162. package/src/device/meter.ts +183 -205
  163. package/src/device/meterplus.ts +183 -204
  164. package/src/device/motion.ts +169 -185
  165. package/src/device/plug.ts +174 -177
  166. package/src/device/robotvacuumcleaner.ts +256 -269
  167. package/src/device/waterdetector.ts +169 -184
  168. package/src/homebridge-ui/server.ts +16 -15
  169. package/src/index.ts +5 -6
  170. package/src/irdevice/airconditioner.ts +280 -326
  171. package/src/irdevice/airpurifier.ts +124 -143
  172. package/src/irdevice/camera.ts +58 -64
  173. package/src/irdevice/fan.ts +106 -123
  174. package/src/irdevice/irdevice.ts +116 -119
  175. package/src/irdevice/light.ts +119 -143
  176. package/src/irdevice/other.ts +417 -461
  177. package/src/irdevice/tv.ts +155 -177
  178. package/src/irdevice/vacuumcleaner.ts +54 -60
  179. package/src/irdevice/waterheater.ts +56 -63
  180. package/src/platform.ts +1281 -1281
  181. package/src/settings.ts +170 -170
  182. package/src/types/bledevicestatus.ts +255 -255
  183. package/src/types/devicelist.ts +79 -79
  184. package/src/types/deviceresponse.ts +12 -13
  185. package/src/types/devicestatus.ts +124 -124
  186. package/src/types/devicewebhookstatus.ts +126 -127
  187. package/src/types/irdevicelist.ts +10 -10
  188. package/src/types/pushbody.ts +5 -5
  189. package/src/utils.ts +64 -65
  190. package/tsconfig.json +10 -9
@@ -2,12 +2,13 @@
2
2
  *
3
3
  * vacuumcleaner.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
- import { irdeviceBase } from './irdevice.js';
5
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
6
 
7
- import type { SwitchBotPlatform } from '../platform.js';
8
- import type { irDevicesConfig } from '../settings.js';
9
- import type { irdevice } from '../types/irdevicelist.js';
10
- import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
7
+ import type { SwitchBotPlatform } from '../platform.js'
8
+ import type { irDevicesConfig } from '../settings.js'
9
+ import type { irdevice } from '../types/irdevicelist.js'
10
+
11
+ import { irdeviceBase } from './irdevice.js'
11
12
 
12
13
  /**
13
14
  * Platform Accessory
@@ -17,118 +18,111 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
17
18
  export class VacuumCleaner extends irdeviceBase {
18
19
  // Services
19
20
  private Switch: {
20
- Name: CharacteristicValue;
21
- Service: Service;
22
- On: CharacteristicValue;
23
- };
21
+ Name: CharacteristicValue
22
+ Service: Service
23
+ On: CharacteristicValue
24
+ }
24
25
 
25
26
  constructor(
26
27
  readonly platform: SwitchBotPlatform,
27
28
  accessory: PlatformAccessory,
28
29
  device: irdevice & irDevicesConfig,
29
30
  ) {
30
- super(platform, accessory, device);
31
+ super(platform, accessory, device)
31
32
  // Set category
32
- accessory.category = this.hap.Categories.OTHER;
33
+ accessory.category = this.hap.Categories.OTHER
33
34
 
34
35
  // Initialize Switch Service
35
- accessory.context.Switch = accessory.context.Switch ?? {};
36
+ accessory.context.Switch = accessory.context.Switch ?? {}
36
37
  this.Switch = {
37
38
  Name: accessory.displayName,
38
39
  Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
39
40
  On: accessory.context.On ?? false,
40
- };
41
- accessory.context.Switch = this.Switch as object;
41
+ }
42
+ accessory.context.Switch = this.Switch as object
42
43
 
43
- this.Switch.Service
44
- .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
45
- .getCharacteristic(this.hap.Characteristic.On)
46
- .onGet(() => {
47
- return this.Switch.On;
48
- })
49
- .onSet(this.OnSet.bind(this));
44
+ this.Switch.Service.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
45
+ return this.Switch.On
46
+ }).onSet(this.OnSet.bind(this))
50
47
  }
51
48
 
52
49
  async OnSet(value: CharacteristicValue): Promise<void> {
53
- await this.debugLog(`On: ${value}`);
50
+ await this.debugLog(`On: ${value}`)
54
51
 
55
52
  // Set the requested state
56
- this.Switch.On = value;
53
+ this.Switch.On = value
57
54
  if (this.Switch.On) {
58
- await this.pushOnChanges();
55
+ await this.pushOnChanges()
59
56
  } else {
60
- await this.pushOffChanges();
57
+ await this.pushOffChanges()
61
58
  }
62
59
  }
63
60
 
64
61
  /**
65
62
  * Pushes the requested changes to the SwitchBot API
66
- * deviceType CommandType Command Parameter Description
67
- * Vacuum Cleaner "command" "turnOff" "default" set to OFF state
68
- * Vacuum Cleaner "command" "turnOn" "default" set to ON state
63
+ * deviceType CommandType Command Parameter Description
64
+ * Vacuum Cleaner "command" "turnOff" "default" set to OFF state
65
+ * Vacuum Cleaner "command" "turnOn" "default" set to ON state
69
66
  */
70
67
  async pushOnChanges(): Promise<void> {
71
- await this.debugLog('pushOnChanges'
72
- + ` On: ${this.Switch.On}, disablePushOn: ${this.disablePushOn}`);
68
+ await this.debugLog(`pushOnChanges On: ${this.Switch.On}, disablePushOn: ${this.disablePushOn}`)
73
69
  if (this.Switch.On && !this.disablePushOn) {
74
- const commandType: string = await this.commandType();
75
- const command: string = await this.commandOn();
70
+ const commandType: string = await this.commandType()
71
+ const command: string = await this.commandOn()
76
72
  const bodyChange = JSON.stringify({
77
- command: command,
73
+ command,
78
74
  parameter: 'default',
79
- commandType: commandType,
80
- });
81
- await this.pushChanges(bodyChange);
75
+ commandType,
76
+ })
77
+ await this.pushChanges(bodyChange)
82
78
  }
83
79
  }
84
80
 
85
81
  async pushOffChanges(): Promise<void> {
86
- await this.debugLog('pushOffChanges'
87
- + ` On: ${this.Switch.On}, disablePushOff: ${this.disablePushOff}`);
82
+ await this.debugLog(`pushOffChanges On: ${this.Switch.On}, disablePushOff: ${this.disablePushOff}`)
88
83
  if (!this.Switch.On && !this.disablePushOff) {
89
- const commandType: string = await this.commandType();
90
- const command: string = await this.commandOff();
84
+ const commandType: string = await this.commandType()
85
+ const command: string = await this.commandOff()
91
86
  const bodyChange = JSON.stringify({
92
- command: command,
87
+ command,
93
88
  parameter: 'default',
94
- commandType: commandType,
95
- });
96
- await this.pushChanges(bodyChange);
89
+ commandType,
90
+ })
91
+ await this.pushChanges(bodyChange)
97
92
  }
98
93
  }
99
94
 
100
95
  async pushChanges(bodyChange: any): Promise<void> {
101
- await this.debugLog('pushChanges');
96
+ await this.debugLog('pushChanges')
102
97
  if (this.device.connectionType === 'OpenAPI') {
103
- await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
98
+ await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
104
99
  try {
105
- const { body, statusCode } = await this.pushChangeRequest(bodyChange);
106
- const deviceStatus: any = await body.json();
107
- await this.pushStatusCodes(statusCode, deviceStatus);
100
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange)
101
+ const deviceStatus: any = await body.json()
102
+ await this.pushStatusCodes(statusCode, deviceStatus)
108
103
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
109
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
110
- await this.updateHomeKitCharacteristics();
104
+ await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
105
+ await this.updateHomeKitCharacteristics()
111
106
  } else {
112
- await this.statusCode(statusCode);
113
- await this.statusCode(deviceStatus.statusCode);
107
+ await this.statusCode(statusCode)
108
+ await this.statusCode(deviceStatus.statusCode)
114
109
  }
115
110
  } catch (e: any) {
116
- await this.apiError(e);
117
- await this.pushChangeError(e);
111
+ await this.apiError(e)
112
+ await this.pushChangeError(e)
118
113
  }
119
114
  } else {
120
- await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
115
+ await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
121
116
  }
122
117
  }
123
118
 
124
119
  async updateHomeKitCharacteristics(): Promise<void> {
125
- await this.debugLog('updateHomeKitCharacteristics');
120
+ await this.debugLog('updateHomeKitCharacteristics')
126
121
  // On
127
- await this.updateCharacteristic(this.Switch.Service, this.hap.Characteristic.On,
128
- this.Switch.On, 'On');
122
+ await this.updateCharacteristic(this.Switch.Service, this.hap.Characteristic.On, this.Switch.On, 'On')
129
123
  }
130
124
 
131
125
  async apiError(e: any): Promise<void> {
132
- this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e);
126
+ this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e)
133
127
  }
134
128
  }
@@ -2,12 +2,13 @@
2
2
  *
3
3
  * waterheater.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
- import { irdeviceBase } from './irdevice.js';
5
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
6
 
7
- import type { SwitchBotPlatform } from '../platform.js';
8
- import type { irDevicesConfig } from '../settings.js';
9
- import type { irdevice } from '../types/irdevicelist.js';
10
- import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
7
+ import type { SwitchBotPlatform } from '../platform.js'
8
+ import type { irDevicesConfig } from '../settings.js'
9
+ import type { irdevice } from '../types/irdevicelist.js'
10
+
11
+ import { irdeviceBase } from './irdevice.js'
11
12
 
12
13
  /**
13
14
  * Platform Accessory
@@ -17,120 +18,112 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
17
18
  export class WaterHeater extends irdeviceBase {
18
19
  // Services
19
20
  private Valve: {
20
- Name: CharacteristicValue;
21
- Service: Service;
22
- Active: CharacteristicValue;
23
- };
21
+ Name: CharacteristicValue
22
+ Service: Service
23
+ Active: CharacteristicValue
24
+ }
24
25
 
25
26
  constructor(
26
27
  readonly platform: SwitchBotPlatform,
27
28
  accessory: PlatformAccessory,
28
29
  device: irdevice & irDevicesConfig,
29
30
  ) {
30
- super(platform, accessory, device);
31
+ super(platform, accessory, device)
31
32
  // Set category
32
- accessory.category = this.hap.Categories.FAUCET;
33
+ accessory.category = this.hap.Categories.FAUCET
33
34
 
34
35
  // Initialize Switch Service
35
- accessory.context.Valve = accessory.context.Valve ?? {};
36
+ accessory.context.Valve = accessory.context.Valve ?? {}
36
37
  this.Valve = {
37
38
  Name: accessory.displayName,
38
39
  Service: accessory.getService(this.hap.Service.Valve) ?? accessory.addService(this.hap.Service.Valve) as Service,
39
40
  Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
40
- };
41
- accessory.context.Valve = this.Valve as object;
41
+ }
42
+ accessory.context.Valve = this.Valve as object
42
43
 
43
- this.Valve.Service
44
- .setCharacteristic(this.hap.Characteristic.Name, this.Valve.Name)
45
- .setCharacteristic(this.hap.Characteristic.ValveType, this.hap.Characteristic.ValveType.GENERIC_VALVE)
46
- .getCharacteristic(this.hap.Characteristic.Active)
47
- .onGet(() => {
48
- return this.Valve.Active;
49
- })
50
- .onSet(this.ActiveSet.bind(this));
44
+ this.Valve.Service.setCharacteristic(this.hap.Characteristic.Name, this.Valve.Name).setCharacteristic(this.hap.Characteristic.ValveType, this.hap.Characteristic.ValveType.GENERIC_VALVE).getCharacteristic(this.hap.Characteristic.Active).onGet(() => {
45
+ return this.Valve.Active
46
+ }).onSet(this.ActiveSet.bind(this))
51
47
  }
52
48
 
53
49
  async ActiveSet(value: CharacteristicValue): Promise<void> {
54
- await this.debugLog(`Active: ${value}`);
50
+ await this.debugLog(`Active: ${value}`)
55
51
 
56
- this.Valve.Active = value;
52
+ this.Valve.Active = value
57
53
  if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE) {
58
- await this.pushWaterHeaterOnChanges();
59
- this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.IN_USE);
54
+ await this.pushWaterHeaterOnChanges()
55
+ this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.IN_USE)
60
56
  } else {
61
- await this.pushWaterHeaterOffChanges();
62
- this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.NOT_IN_USE);
57
+ await this.pushWaterHeaterOffChanges()
58
+ this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.NOT_IN_USE)
63
59
  }
64
60
  }
65
61
 
66
62
  /**
67
63
  * Pushes the requested changes to the SwitchBot API
68
- * deviceType Command Type Command Parameter Description
69
- * WaterHeater "command" "turnOff" "default" set to OFF state
70
- * WaterHeater "command" "turnOn" "default" set to ON state
64
+ * deviceType Command Type Command Parameter Description
65
+ * WaterHeater "command" "turnOff" "default" set to OFF state
66
+ * WaterHeater "command" "turnOn" "default" set to ON state
71
67
  */
72
68
  async pushWaterHeaterOnChanges(): Promise<void> {
73
- await this.debugLog(`pushWaterHeaterOnChanges Active: ${this.Valve.Active},`
74
- + ` disablePushOn: ${this.disablePushOn}`);
69
+ await this.debugLog(`pushWaterHeaterOnChanges Active: ${this.Valve.Active}, disablePushOn: ${this.disablePushOn}`)
75
70
  if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
76
- const commandType: string = await this.commandType();
77
- const command: string = await this.commandOn();
71
+ const commandType: string = await this.commandType()
72
+ const command: string = await this.commandOn()
78
73
  const bodyChange = JSON.stringify({
79
- command: command,
74
+ command,
80
75
  parameter: 'default',
81
- commandType: commandType,
82
- });
83
- await this.pushChanges(bodyChange);
76
+ commandType,
77
+ })
78
+ await this.pushChanges(bodyChange)
84
79
  }
85
80
  }
86
81
 
87
82
  async pushWaterHeaterOffChanges(): Promise<void> {
88
- await this.debugLog(`pushWaterHeaterOffChanges Active: ${this.Valve.Active},`
89
- + ` disablePushOff: ${this.disablePushOff}`);
83
+ await this.debugLog(`pushWaterHeaterOffChanges Active: ${this.Valve.Active}, disablePushOff: ${this.disablePushOff}`)
90
84
  if (this.Valve.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
91
- const commandType: string = await this.commandType();
92
- const command: string = await this.commandOff();
85
+ const commandType: string = await this.commandType()
86
+ const command: string = await this.commandOff()
93
87
  const bodyChange = JSON.stringify({
94
- command: command,
88
+ command,
95
89
  parameter: 'default',
96
- commandType: commandType,
97
- });
98
- await this.pushChanges(bodyChange);
90
+ commandType,
91
+ })
92
+ await this.pushChanges(bodyChange)
99
93
  }
100
94
  }
101
95
 
102
96
  async pushChanges(bodyChange: any): Promise<void> {
103
- await this.debugLog('pushChanges');
97
+ await this.debugLog('pushChanges')
104
98
  if (this.device.connectionType === 'OpenAPI') {
105
- this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
99
+ this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
106
100
  try {
107
- const { body, statusCode } = await this.pushChangeRequest(bodyChange);
108
- const deviceStatus: any = await body.json();
109
- await this.pushStatusCodes(statusCode, deviceStatus);
101
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange)
102
+ const deviceStatus: any = await body.json()
103
+ await this.pushStatusCodes(statusCode, deviceStatus)
110
104
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
111
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
112
- await this.updateHomeKitCharacteristics();
105
+ await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
106
+ await this.updateHomeKitCharacteristics()
113
107
  } else {
114
- await this.statusCode(statusCode);
115
- await this.statusCode(deviceStatus.statusCode);
108
+ await this.statusCode(statusCode)
109
+ await this.statusCode(deviceStatus.statusCode)
116
110
  }
117
111
  } catch (e: any) {
118
- await this.apiError(e);
119
- await this.pushChangeError(e);
112
+ await this.apiError(e)
113
+ await this.pushChangeError(e)
120
114
  }
121
115
  } else {
122
- await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
116
+ await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
123
117
  }
124
118
  }
125
119
 
126
120
  async updateHomeKitCharacteristics(): Promise<void> {
127
- await this.debugLog('updateHomeKitCharacteristics');
121
+ await this.debugLog('updateHomeKitCharacteristics')
128
122
  // Active
129
- await this.updateCharacteristic(this.Valve.Service, this.hap.Characteristic.Active,
130
- this.Valve.Active, 'Active');
123
+ await this.updateCharacteristic(this.Valve.Service, this.hap.Characteristic.Active, this.Valve.Active, 'Active')
131
124
  }
132
125
 
133
126
  async apiError({ e }: { e: any }): Promise<void> {
134
- this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
127
+ this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
135
128
  }
136
129
  }