@switchbot/homebridge-switchbot 3.5.0-beta.6 → 3.5.0-beta.61

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 (177) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/CHANGELOG.md +4 -1
  3. package/config.schema.json +120 -17
  4. package/dist/device/blindtilt.d.ts +23 -96
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +408 -779
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +26 -72
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +696 -822
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +14 -68
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +237 -606
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +14 -75
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +280 -658
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +15 -66
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +242 -544
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +19 -88
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +402 -805
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/device.d.ts +59 -0
  29. package/dist/device/device.d.ts.map +1 -0
  30. package/dist/device/device.js +684 -0
  31. package/dist/device/device.js.map +1 -0
  32. package/dist/device/fan.d.ts +51 -0
  33. package/dist/device/fan.d.ts.map +1 -0
  34. package/dist/device/fan.js +535 -0
  35. package/dist/device/fan.js.map +1 -0
  36. package/dist/device/hub.d.ts +16 -60
  37. package/dist/device/hub.d.ts.map +1 -1
  38. package/dist/device/hub.js +246 -613
  39. package/dist/device/hub.js.map +1 -1
  40. package/dist/device/humidifier.d.ts +11 -66
  41. package/dist/device/humidifier.d.ts.map +1 -1
  42. package/dist/device/humidifier.js +232 -593
  43. package/dist/device/humidifier.js.map +1 -1
  44. package/dist/device/iosensor.d.ts +11 -64
  45. package/dist/device/iosensor.d.ts.map +1 -1
  46. package/dist/device/iosensor.js +185 -600
  47. package/dist/device/iosensor.js.map +1 -1
  48. package/dist/device/lightstrip.d.ts +11 -69
  49. package/dist/device/lightstrip.d.ts.map +1 -1
  50. package/dist/device/lightstrip.js +277 -586
  51. package/dist/device/lightstrip.js.map +1 -1
  52. package/dist/device/lock.d.ts +16 -63
  53. package/dist/device/lock.d.ts.map +1 -1
  54. package/dist/device/lock.js +241 -560
  55. package/dist/device/lock.js.map +1 -1
  56. package/dist/device/meter.d.ts +14 -64
  57. package/dist/device/meter.d.ts.map +1 -1
  58. package/dist/device/meter.js +181 -593
  59. package/dist/device/meter.js.map +1 -1
  60. package/dist/device/meterplus.d.ts +14 -65
  61. package/dist/device/meterplus.d.ts.map +1 -1
  62. package/dist/device/meterplus.js +170 -593
  63. package/dist/device/meterplus.js.map +1 -1
  64. package/dist/device/motion.d.ts +13 -69
  65. package/dist/device/motion.d.ts.map +1 -1
  66. package/dist/device/motion.js +178 -531
  67. package/dist/device/motion.js.map +1 -1
  68. package/dist/device/plug.d.ts +9 -57
  69. package/dist/device/plug.d.ts.map +1 -1
  70. package/dist/device/plug.js +92 -458
  71. package/dist/device/plug.js.map +1 -1
  72. package/dist/device/robotvacuumcleaner.d.ts +12 -63
  73. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  74. package/dist/device/robotvacuumcleaner.js +197 -521
  75. package/dist/device/robotvacuumcleaner.js.map +1 -1
  76. package/dist/device/waterdetector.d.ts +10 -65
  77. package/dist/device/waterdetector.d.ts.map +1 -1
  78. package/dist/device/waterdetector.js +139 -495
  79. package/dist/device/waterdetector.js.map +1 -1
  80. package/dist/homebridge-ui/public/index.html +22 -16
  81. package/dist/homebridge-ui/server.js +1 -1
  82. package/dist/homebridge-ui/server.js.map +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -2
  86. package/dist/index.js.map +1 -1
  87. package/dist/irdevice/airconditioner.d.ts +9 -49
  88. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  89. package/dist/irdevice/airconditioner.js +309 -419
  90. package/dist/irdevice/airconditioner.js.map +1 -1
  91. package/dist/irdevice/airpurifier.d.ts +8 -39
  92. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  93. package/dist/irdevice/airpurifier.js +72 -304
  94. package/dist/irdevice/airpurifier.js.map +1 -1
  95. package/dist/irdevice/camera.d.ts +7 -36
  96. package/dist/irdevice/camera.d.ts.map +1 -1
  97. package/dist/irdevice/camera.js +34 -278
  98. package/dist/irdevice/camera.js.map +1 -1
  99. package/dist/irdevice/fan.d.ts +10 -43
  100. package/dist/irdevice/fan.d.ts.map +1 -1
  101. package/dist/irdevice/fan.js +100 -338
  102. package/dist/irdevice/fan.js.map +1 -1
  103. package/dist/irdevice/irdevice.d.ts +40 -0
  104. package/dist/irdevice/irdevice.d.ts.map +1 -0
  105. package/dist/irdevice/irdevice.js +330 -0
  106. package/dist/irdevice/irdevice.js.map +1 -0
  107. package/dist/irdevice/light.d.ts +12 -45
  108. package/dist/irdevice/light.d.ts.map +1 -1
  109. package/dist/irdevice/light.js +87 -357
  110. package/dist/irdevice/light.js.map +1 -1
  111. package/dist/irdevice/other.d.ts +19 -48
  112. package/dist/irdevice/other.d.ts.map +1 -1
  113. package/dist/irdevice/other.js +352 -546
  114. package/dist/irdevice/other.js.map +1 -1
  115. package/dist/irdevice/tv.d.ts +8 -40
  116. package/dist/irdevice/tv.d.ts.map +1 -1
  117. package/dist/irdevice/tv.js +82 -321
  118. package/dist/irdevice/tv.js.map +1 -1
  119. package/dist/irdevice/vacuumcleaner.d.ts +7 -36
  120. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  121. package/dist/irdevice/vacuumcleaner.js +41 -284
  122. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  123. package/dist/irdevice/waterheater.d.ts +7 -36
  124. package/dist/irdevice/waterheater.d.ts.map +1 -1
  125. package/dist/irdevice/waterheater.js +42 -287
  126. package/dist/irdevice/waterheater.js.map +1 -1
  127. package/dist/platform.d.ts +19 -6
  128. package/dist/platform.d.ts.map +1 -1
  129. package/dist/platform.js +310 -169
  130. package/dist/platform.js.map +1 -1
  131. package/dist/settings.d.ts +62 -19
  132. package/dist/settings.d.ts.map +1 -1
  133. package/dist/settings.js +16 -552
  134. package/dist/settings.js.map +1 -1
  135. package/dist/utils.d.ts +77 -0
  136. package/dist/utils.d.ts.map +1 -1
  137. package/dist/utils.js +638 -1
  138. package/dist/utils.js.map +1 -1
  139. package/eslint.config.js +96 -0
  140. package/package.json +19 -15
  141. package/src/custom.d.ts +2 -1
  142. package/src/device/blindtilt.ts +442 -814
  143. package/src/device/bot.ts +754 -915
  144. package/src/device/ceilinglight.ts +255 -633
  145. package/src/device/colorbulb.ts +295 -685
  146. package/src/device/contact.ts +277 -571
  147. package/src/device/curtain.ts +431 -835
  148. package/src/device/device.ts +709 -0
  149. package/src/device/fan.ts +591 -0
  150. package/src/device/hub.ts +286 -644
  151. package/src/device/humidifier.ts +266 -646
  152. package/src/device/iosensor.ts +220 -625
  153. package/src/device/lightstrip.ts +305 -620
  154. package/src/device/lock.ts +280 -600
  155. package/src/device/meter.ts +216 -617
  156. package/src/device/meterplus.ts +205 -619
  157. package/src/device/motion.ts +206 -556
  158. package/src/device/plug.ts +107 -490
  159. package/src/device/robotvacuumcleaner.ts +223 -550
  160. package/src/device/waterdetector.ts +160 -519
  161. package/src/homebridge-ui/public/index.html +22 -16
  162. package/src/homebridge-ui/server.ts +1 -1
  163. package/src/index.ts +4 -3
  164. package/src/irdevice/airconditioner.ts +333 -447
  165. package/src/irdevice/airpurifier.ts +92 -322
  166. package/src/irdevice/camera.ts +45 -294
  167. package/src/irdevice/fan.ts +115 -353
  168. package/src/irdevice/irdevice.ts +346 -0
  169. package/src/irdevice/light.ts +110 -385
  170. package/src/irdevice/other.ts +399 -616
  171. package/src/irdevice/tv.ts +103 -340
  172. package/src/irdevice/vacuumcleaner.ts +52 -306
  173. package/src/irdevice/waterheater.ts +53 -311
  174. package/src/platform.ts +355 -216
  175. package/src/settings.ts +116 -611
  176. package/src/utils.ts +642 -1
  177. package/src/device/waterdetector.json +0 -11
@@ -1,82 +1,65 @@
1
- import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * waterheater.ts: @switchbot/homebridge-switchbot.
4
+ */
2
5
  import { request } from 'undici';
3
- import { SwitchBotPlatform } from '../platform.js';
4
- import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings.js';
6
+ import { Devices } from '../settings.js';
7
+ import { irdeviceBase } from './irdevice.js';
8
+
9
+ import type { SwitchBotPlatform } from '../platform.js';
10
+ import type { irDevicesConfig, irdevice } from '../settings.js';
11
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
12
 
6
13
  /**
7
14
  * Platform Accessory
8
15
  * An instance of this class is created for each accessory your platform registers
9
16
  * Each accessory may expose multiple services of different service types.
10
17
  */
11
- export class WaterHeater {
12
- public readonly api: API;
13
- public readonly log: Logging;
14
- public readonly config!: SwitchBotPlatformConfig;
15
- protected readonly hap: HAP;
18
+ export class WaterHeater extends irdeviceBase {
16
19
  // Services
17
- valveService!: Service;
18
-
19
- // Characteristic Values
20
- Active!: CharacteristicValue;
21
- FirmwareRevision!: CharacteristicValue;
22
-
23
- // Config
24
- deviceLogging!: string;
25
- disablePushOn?: boolean;
26
- disablePushOff?: boolean;
20
+ private Valve: {
21
+ Service: Service;
22
+ Active: CharacteristicValue;
23
+ };
27
24
 
28
25
  constructor(
29
- private readonly platform: SwitchBotPlatform,
30
- private accessory: PlatformAccessory,
31
- public device: irdevice & irDevicesConfig,
26
+ readonly platform: SwitchBotPlatform,
27
+ accessory: PlatformAccessory,
28
+ device: irdevice & irDevicesConfig,
32
29
  ) {
33
- this.api = this.platform.api;
34
- this.log = this.platform.log;
35
- this.config = this.platform.config;
36
- this.hap = this.api.hap;
37
- // default placeholders
38
- this.deviceLogs(device);
39
- this.deviceContext();
40
- this.disablePushOnChanges(device);
41
- this.disablePushOffChanges(device);
42
- this.deviceConfig(device);
30
+ super(platform, accessory, device);
43
31
 
44
- // set accessory information
45
- accessory
46
- .getService(this.hap.Service.AccessoryInformation)!
47
- .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
48
- .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
49
- .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
50
- .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
32
+ // Initialize Valve property
33
+ this.Valve = {
34
+ Service: accessory.getService(this.hap.Service.Valve) as Service,
35
+ Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
36
+ };
51
37
 
52
38
  // get the Television service if it exists, otherwise create a new Television service
53
39
  // you can create multiple services for each accessory
54
- const valveService = `${accessory.displayName} ${device.remoteType}`;
55
- (this.valveService = accessory.getService(this.hap.Service.Valve)
56
- || accessory.addService(this.hap.Service.Valve)), valveService;
40
+ const ValveService = `${accessory.displayName} ${device.remoteType}`;
41
+ (this.Valve.Service = accessory.getService(this.hap.Service.Valve)
42
+ || accessory.addService(this.hap.Service.Valve)), ValveService;
57
43
 
58
- this.valveService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
59
- if (!this.valveService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
60
- this.valveService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
61
- }
44
+ this.Valve.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
62
45
 
63
46
  // set sleep discovery characteristic
64
- this.valveService.setCharacteristic(this.hap.Characteristic.ValveType, this.hap.Characteristic.ValveType.GENERIC_VALVE);
47
+ this.Valve.Service.setCharacteristic(this.hap.Characteristic.ValveType, this.hap.Characteristic.ValveType.GENERIC_VALVE);
65
48
 
66
49
  // handle on / off events using the Active characteristic
67
- this.valveService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
50
+ this.Valve.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
68
51
  }
69
52
 
70
53
  async ActiveSet(value: CharacteristicValue): Promise<void> {
71
54
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
72
55
 
73
- this.Active = value;
74
- if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
56
+ this.Valve.Active = value;
57
+ if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE) {
75
58
  await this.pushWaterHeaterOnChanges();
76
- this.valveService.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.IN_USE);
59
+ this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.IN_USE);
77
60
  } else {
78
61
  await this.pushWaterHeaterOffChanges();
79
- this.valveService.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.NOT_IN_USE);
62
+ this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.NOT_IN_USE);
80
63
  }
81
64
  }
82
65
 
@@ -87,11 +70,9 @@ export class WaterHeater {
87
70
  * WaterHeater "command" "turnOn" "default" set to ON state
88
71
  */
89
72
  async pushWaterHeaterOnChanges(): Promise<void> {
90
- this.debugLog(
91
- `${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOnChanges Active: ${this.Active},` +
92
- ` disablePushOn: ${this.disablePushOn}`,
93
- );
94
- if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
73
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOnChanges Active: ${this.Valve.Active},`
74
+ + ` disablePushOn: ${this.disablePushOn}`);
75
+ if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
95
76
  const commandType: string = await this.commandType();
96
77
  const command: string = await this.commandOn();
97
78
  const bodyChange = JSON.stringify({
@@ -104,11 +85,9 @@ export class WaterHeater {
104
85
  }
105
86
 
106
87
  async pushWaterHeaterOffChanges(): Promise<void> {
107
- this.debugLog(
108
- `${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOffChanges Active: ${this.Active},` +
109
- ` disablePushOff: ${this.disablePushOff}`,
110
- );
111
- if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
88
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOffChanges Active: ${this.Valve.Active},`
89
+ + ` disablePushOff: ${this.disablePushOff}`);
90
+ if (this.Valve.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
112
91
  const commandType: string = await this.commandType();
113
92
  const command: string = await this.commandOff();
114
93
  const bodyChange = JSON.stringify({
@@ -135,8 +114,10 @@ export class WaterHeater {
135
114
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
136
115
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
137
116
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
138
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
117
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
139
118
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
119
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
120
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
140
121
  this.updateHomeKitCharacteristics();
141
122
  } else {
142
123
  this.statusCode(statusCode);
@@ -144,266 +125,27 @@ export class WaterHeater {
144
125
  }
145
126
  } catch (e: any) {
146
127
  this.apiError(e);
147
- this.errorLog(
148
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
149
- ` Connection, Error Message: ${JSON.stringify(e.message)}`,
150
- );
128
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
129
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
151
130
  }
152
131
  } else {
153
- this.warnLog(
154
- `${this.device.remoteType}: ${this.accessory.displayName}` +
155
- ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
156
- );
132
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
133
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
157
134
  }
158
135
  }
159
136
 
160
137
  async updateHomeKitCharacteristics(): Promise<void> {
161
138
  // Active
162
- if (this.Active === undefined) {
163
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
139
+ if (this.Valve.Active === undefined) {
140
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Valve.Active}`);
164
141
  } else {
165
- this.accessory.context.Active = this.Active;
166
- this.valveService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
167
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
168
- }
169
- }
170
-
171
- async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
172
- if (device.disablePushOn === undefined) {
173
- this.disablePushOn = false;
174
- } else {
175
- this.disablePushOn = device.disablePushOn;
176
- }
177
- }
178
-
179
- async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
180
- if (device.disablePushOff === undefined) {
181
- this.disablePushOff = false;
182
- } else {
183
- this.disablePushOff = device.disablePushOff;
184
- }
185
- }
186
-
187
- async commandType(): Promise<string> {
188
- let commandType: string;
189
- if (this.device.customize) {
190
- commandType = 'customize';
191
- } else {
192
- commandType = 'command';
193
- }
194
- return commandType;
195
- }
196
-
197
- async commandOn(): Promise<string> {
198
- let command: string;
199
- if (this.device.customize && this.device.customOn) {
200
- command = this.device.customOn;
201
- } else {
202
- command = 'turnOn';
203
- }
204
- return command;
205
- }
206
-
207
- async commandOff(): Promise<string> {
208
- let command: string;
209
- if (this.device.customize && this.device.customOff) {
210
- command = this.device.customOff;
211
- } else {
212
- command = 'turnOff';
213
- }
214
- return command;
215
- }
216
-
217
- async statusCode(statusCode: number): Promise<void> {
218
- switch (statusCode) {
219
- case 151:
220
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
221
- break;
222
- case 152:
223
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
224
- break;
225
- case 160:
226
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
227
- break;
228
- case 161:
229
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
230
- break;
231
- case 171:
232
- this.errorLog(
233
- `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
234
- `Hub: ${this.device.hubDeviceId}`,
235
- );
236
- break;
237
- case 190:
238
- this.errorLog(
239
- `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
240
- ` Or command format is invalid, statusCode: ${statusCode}`,
241
- );
242
- break;
243
- case 100:
244
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
245
- break;
246
- case 200:
247
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
248
- break;
249
- case 400:
250
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
251
- + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
252
- break;
253
- case 401:
254
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
255
- + `but the request has not been authenticated, statusCode: ${statusCode}`);
256
- break;
257
- case 403:
258
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
259
- + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
260
- break;
261
- case 404:
262
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
263
- + `statusCode: ${statusCode}`);
264
- break;
265
- case 406:
266
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
267
- + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
268
- break;
269
- case 415:
270
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
271
- + `header that is not supported by the server, statusCode: ${statusCode}`);
272
- break;
273
- case 422:
274
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
275
- + `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
276
- break;
277
- case 429:
278
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
279
- + `requests allowed for a given time window, statusCode: ${statusCode}`);
280
- break;
281
- case 500:
282
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
283
- + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
284
- break;
285
- default:
286
- this.infoLog(
287
- `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
288
- `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
289
- );
142
+ this.accessory.context.Active = this.Valve.Active;
143
+ this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Valve.Active);
144
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Valve.Active}`);
290
145
  }
291
146
  }
292
147
 
293
148
  async apiError({ e }: { e: any }): Promise<void> {
294
- this.valveService.updateCharacteristic(this.hap.Characteristic.Active, e);
295
- }
296
-
297
- async deviceContext(): Promise<void> {
298
- if (this.Active === undefined) {
299
- this.Active = this.hap.Characteristic.Active.INACTIVE;
300
- } else {
301
- this.Active = this.accessory.context.Active;
302
- }
303
- if (this.FirmwareRevision === undefined) {
304
- this.FirmwareRevision = this.platform.version;
305
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
306
- }
307
- }
308
-
309
- async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
310
- let config = {};
311
- if (device.irwh) {
312
- config = device.irwh;
313
- }
314
- if (device.logging !== undefined) {
315
- config['logging'] = device.logging;
316
- }
317
- if (device.connectionType !== undefined) {
318
- config['connectionType'] = device.connectionType;
319
- }
320
- if (device.external !== undefined) {
321
- config['external'] = device.external;
322
- }
323
- if (device.customOn !== undefined) {
324
- config['customOn'] = device.customOn;
325
- }
326
- if (device.customOff !== undefined) {
327
- config['customOff'] = device.customOff;
328
- }
329
- if (device.customize !== undefined) {
330
- config['customize'] = device.customize;
331
- }
332
- if (device.disablePushOn !== undefined) {
333
- config['disablePushOn'] = device.disablePushOn;
334
- }
335
- if (device.disablePushOff !== undefined) {
336
- config['disablePushOff'] = device.disablePushOff;
337
- }
338
- if (Object.entries(config).length !== 0) {
339
- this.debugWarnLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`] });
340
- }
341
- }
342
-
343
- async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
344
- if (this.platform.debugMode) {
345
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
346
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
347
- } else if (device.logging) {
348
- this.deviceLogging = this.accessory.context.logging = device.logging;
349
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
350
- } else if (this.platform.config.options?.logging) {
351
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
352
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
353
- } else {
354
- this.deviceLogging = this.accessory.context.logging = 'standard';
355
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
356
- }
357
- }
358
-
359
- /**
360
- * Logging for Device
361
- */
362
- infoLog(...log: any[]): void {
363
- if (this.enablingDeviceLogging()) {
364
- this.platform.log.info(String(...log));
365
- }
366
- }
367
-
368
- warnLog(...log: any[]): void {
369
- if (this.enablingDeviceLogging()) {
370
- this.platform.log.warn(String(...log));
371
- }
372
- }
373
-
374
- debugWarnLog(...log: any[]): void {
375
- if (this.enablingDeviceLogging()) {
376
- if (this.deviceLogging?.includes('debug')) {
377
- this.platform.log.warn('[DEBUG]', String(...log));
378
- }
379
- }
380
- }
381
-
382
- errorLog(...log: any[]): void {
383
- if (this.enablingDeviceLogging()) {
384
- this.platform.log.error(String(...log));
385
- }
386
- }
387
-
388
- debugErrorLog(...log: any[]): void {
389
- if (this.enablingDeviceLogging()) {
390
- if (this.deviceLogging?.includes('debug')) {
391
- this.platform.log.error('[DEBUG]', String(...log));
392
- }
393
- }
394
- }
395
-
396
- debugLog(...log: any[]): void {
397
- if (this.enablingDeviceLogging()) {
398
- if (this.deviceLogging === 'debug') {
399
- this.platform.log.info('[DEBUG]', String(...log));
400
- } else {
401
- this.platform.log.debug(String(...log));
402
- }
403
- }
404
- }
405
-
406
- enablingDeviceLogging(): boolean {
407
- return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
149
+ this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
408
150
  }
409
151
  }