@switchbot/homebridge-switchbot 3.5.0-beta.8 → 3.5.0

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