@switchbot/homebridge-switchbot 3.7.1-beta.1 → 3.7.1-beta.3

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 (99) hide show
  1. package/dist/device/blindtilt.d.ts +3 -1
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +38 -24
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +1 -0
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +30 -24
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +1 -0
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +30 -24
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +1 -0
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +30 -24
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +1 -0
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +30 -24
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +2 -0
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +51 -39
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/device.d.ts.map +1 -1
  26. package/dist/device/device.js +247 -394
  27. package/dist/device/device.js.map +1 -1
  28. package/dist/device/fan.d.ts +1 -0
  29. package/dist/device/fan.d.ts.map +1 -1
  30. package/dist/device/fan.js +30 -24
  31. package/dist/device/fan.js.map +1 -1
  32. package/dist/device/hub.d.ts +1 -0
  33. package/dist/device/hub.d.ts.map +1 -1
  34. package/dist/device/hub.js +30 -24
  35. package/dist/device/hub.js.map +1 -1
  36. package/dist/device/humidifier.d.ts +1 -0
  37. package/dist/device/humidifier.d.ts.map +1 -1
  38. package/dist/device/humidifier.js +30 -24
  39. package/dist/device/humidifier.js.map +1 -1
  40. package/dist/device/iosensor.d.ts +1 -0
  41. package/dist/device/iosensor.d.ts.map +1 -1
  42. package/dist/device/iosensor.js +30 -24
  43. package/dist/device/iosensor.js.map +1 -1
  44. package/dist/device/lightstrip.d.ts +1 -0
  45. package/dist/device/lightstrip.d.ts.map +1 -1
  46. package/dist/device/lightstrip.js +30 -24
  47. package/dist/device/lightstrip.js.map +1 -1
  48. package/dist/device/lock.d.ts +1 -0
  49. package/dist/device/lock.d.ts.map +1 -1
  50. package/dist/device/lock.js +31 -25
  51. package/dist/device/lock.js.map +1 -1
  52. package/dist/device/meter.d.ts +1 -0
  53. package/dist/device/meter.d.ts.map +1 -1
  54. package/dist/device/meter.js +30 -24
  55. package/dist/device/meter.js.map +1 -1
  56. package/dist/device/meterplus.d.ts +1 -0
  57. package/dist/device/meterplus.d.ts.map +1 -1
  58. package/dist/device/meterplus.js +30 -24
  59. package/dist/device/meterplus.js.map +1 -1
  60. package/dist/device/motion.d.ts +1 -0
  61. package/dist/device/motion.d.ts.map +1 -1
  62. package/dist/device/motion.js +30 -24
  63. package/dist/device/motion.js.map +1 -1
  64. package/dist/device/plug.d.ts +1 -0
  65. package/dist/device/plug.d.ts.map +1 -1
  66. package/dist/device/plug.js +31 -25
  67. package/dist/device/plug.js.map +1 -1
  68. package/dist/device/robotvacuumcleaner.d.ts +1 -0
  69. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  70. package/dist/device/robotvacuumcleaner.js +30 -24
  71. package/dist/device/robotvacuumcleaner.js.map +1 -1
  72. package/dist/device/waterdetector.d.ts +1 -0
  73. package/dist/device/waterdetector.d.ts.map +1 -1
  74. package/dist/device/waterdetector.js +30 -24
  75. package/dist/device/waterdetector.js.map +1 -1
  76. package/dist/irdevice/irdevice.d.ts.map +1 -1
  77. package/dist/irdevice/irdevice.js +30 -133
  78. package/dist/irdevice/irdevice.js.map +1 -1
  79. package/package.json +3 -3
  80. package/src/device/blindtilt.ts +39 -23
  81. package/src/device/bot.ts +30 -22
  82. package/src/device/ceilinglight.ts +31 -23
  83. package/src/device/colorbulb.ts +30 -22
  84. package/src/device/contact.ts +30 -22
  85. package/src/device/curtain.ts +50 -36
  86. package/src/device/device.ts +283 -395
  87. package/src/device/fan.ts +30 -22
  88. package/src/device/hub.ts +30 -22
  89. package/src/device/humidifier.ts +30 -22
  90. package/src/device/iosensor.ts +30 -22
  91. package/src/device/lightstrip.ts +30 -22
  92. package/src/device/lock.ts +31 -23
  93. package/src/device/meter.ts +30 -22
  94. package/src/device/meterplus.ts +30 -22
  95. package/src/device/motion.ts +30 -22
  96. package/src/device/plug.ts +31 -23
  97. package/src/device/robotvacuumcleaner.ts +30 -22
  98. package/src/device/waterdetector.ts +30 -22
  99. package/src/irdevice/irdevice.ts +54 -134
@@ -141,10 +141,14 @@ export class Motion extends deviceBase {
141
141
  this.debugLog('Retrieve initial values and update Homekit');
142
142
  this.refreshStatus();
143
143
 
144
- //regisiter webhook event handler
144
+ //regisiter webhook event handler if enabled
145
145
  this.debugLog('Registering Webhook Event Handler');
146
146
  this.registerWebhook();
147
147
 
148
+ //regisiter platform BLE event handler if enabled
149
+ this.debugLog('Registering Platform BLE Event Handler');
150
+ this.registerPlatformBLE();
151
+
148
152
  // Start an update interval
149
153
  interval(this.deviceRefreshRate * 1000)
150
154
  .pipe(skipWhile(() => this.motionUbpdateInProgress))
@@ -236,7 +240,7 @@ export class Motion extends deviceBase {
236
240
  async refreshStatus(): Promise<void> {
237
241
  if (!this.device.enableCloudService && this.OpenAPI) {
238
242
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
239
- } else if (this.BLE || this.config.options?.BLE) {
243
+ } else if (this.BLE) {
240
244
  await this.BLERefreshStatus();
241
245
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
242
246
  await this.openAPIRefreshStatus();
@@ -248,6 +252,29 @@ export class Motion extends deviceBase {
248
252
 
249
253
  async BLERefreshStatus(): Promise<void> {
250
254
  await this.debugLog('BLERefreshStatus');
255
+ const switchbot = await this.switchbotBLE();
256
+ if (switchbot === undefined) {
257
+ await this.BLERefreshConnection(switchbot);
258
+ } else {
259
+ // Start to monitor advertisement packets
260
+ (async () => {
261
+ // Start to monitor advertisement packets
262
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
263
+ // Update HomeKit
264
+ if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
265
+ this.serviceData = serviceData;
266
+ await this.BLEparseStatus();
267
+ await this.updateHomeKitCharacteristics();
268
+ } else {
269
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
270
+ await this.BLERefreshConnection(switchbot);
271
+ }
272
+ })();
273
+ }
274
+ }
275
+
276
+ async registerPlatformBLE(): Promise<void> {
277
+ await this.debugLog('registerPlatformBLE');
251
278
  if (this.config.options?.BLE) {
252
279
  await this.debugLog('is listening to Platform BLE.');
253
280
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -263,26 +290,7 @@ export class Motion extends deviceBase {
263
290
  }
264
291
  };
265
292
  } else {
266
- await this.debugLog('is using Device BLE Scanning.');
267
- const switchbot = await this.switchbotBLE();
268
- if (switchbot === undefined) {
269
- await this.BLERefreshConnection(switchbot);
270
- } else {
271
- // Start to monitor advertisement packets
272
- (async () => {
273
- // Start to monitor advertisement packets
274
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
275
- // Update HomeKit
276
- if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
277
- this.serviceData = serviceData;
278
- await this.BLEparseStatus();
279
- await this.updateHomeKitCharacteristics();
280
- } else {
281
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
282
- await this.BLERefreshConnection(switchbot);
283
- }
284
- })();
285
- }
293
+ await this.debugLog('is not listening to Platform BLE');
286
294
  }
287
295
  }
288
296
 
@@ -69,10 +69,14 @@ export class Plug extends deviceBase {
69
69
  this.debugLog('Retrieve initial values and update Homekit');
70
70
  this.refreshStatus();
71
71
 
72
- //regisiter webhook event handler
72
+ //regisiter webhook event handler if enabled
73
73
  this.debugLog('Registering Webhook Event Handler');
74
74
  this.registerWebhook();
75
75
 
76
+ //regisiter platform BLE event handler if enabled
77
+ this.debugLog('Registering Platform BLE Event Handler');
78
+ this.registerPlatformBLE();
79
+
76
80
  // Start an update interval
77
81
  interval(this.deviceRefreshRate * 1000)
78
82
  .pipe(skipWhile(() => this.plugUpdateInProgress))
@@ -148,7 +152,7 @@ export class Plug extends deviceBase {
148
152
  async refreshStatus(): Promise<void> {
149
153
  if (!this.device.enableCloudService && this.OpenAPI) {
150
154
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
151
- } else if (this.BLE || this.config.options?.BLE) {
155
+ } else if (this.BLE) {
152
156
  await this.BLERefreshStatus();
153
157
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
154
158
  await this.openAPIRefreshStatus();
@@ -160,6 +164,30 @@ export class Plug extends deviceBase {
160
164
 
161
165
  async BLERefreshStatus(): Promise<void> {
162
166
  await this.debugLog('BLERefreshStatus');
167
+ const switchbot = await this.switchbotBLE();
168
+ if (switchbot === undefined) {
169
+ await this.BLERefreshConnection(switchbot);
170
+ } else {
171
+ // Start to monitor advertisement packets
172
+ (async () => {
173
+ // Start to monitor advertisement packets
174
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as plugMiniUSServiceData | plugMiniJPServiceData;
175
+ // Update HomeKit
176
+ if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
177
+ && serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
178
+ this.serviceData = serviceData;
179
+ await this.BLEparseStatus();
180
+ await this.updateHomeKitCharacteristics();
181
+ } else {
182
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
183
+ await this.BLERefreshConnection(switchbot);
184
+ }
185
+ })();
186
+ }
187
+ }
188
+
189
+ async registerPlatformBLE(): Promise<void> {
190
+ await this.debugLog('registerPlatformBLE');
163
191
  if (this.config.options?.BLE) {
164
192
  await this.debugLog('is listening to Platform BLE.');
165
193
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -175,27 +203,7 @@ export class Plug extends deviceBase {
175
203
  }
176
204
  };
177
205
  } else {
178
- await this.debugLog('is using Device BLE Scanning.');
179
- const switchbot = await this.switchbotBLE();
180
- if (switchbot === undefined) {
181
- await this.BLERefreshConnection(switchbot);
182
- } else {
183
- // Start to monitor advertisement packets
184
- (async () => {
185
- // Start to monitor advertisement packets
186
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as plugMiniUSServiceData | plugMiniJPServiceData;
187
- // Update HomeKit
188
- if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
189
- && serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
190
- this.serviceData = serviceData;
191
- await this.BLEparseStatus();
192
- await this.updateHomeKitCharacteristics();
193
- } else {
194
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
195
- await this.BLERefreshConnection(switchbot);
196
- }
197
- })();
198
- }
206
+ await this.debugLog('is not listening to Platform BLE');
199
207
  }
200
208
  }
201
209
 
@@ -130,10 +130,14 @@ export class RobotVacuumCleaner extends deviceBase {
130
130
  this.debugLog('Retrieve initial values and update Homekit');
131
131
  this.refreshStatus();
132
132
 
133
- //regisiter webhook event handler
133
+ //regisiter webhook event handler if enabled
134
134
  this.debugLog('Registering Webhook Event Handler');
135
135
  this.registerWebhook();
136
136
 
137
+ //regisiter platform BLE event handler if enabled
138
+ this.debugLog('Registering Platform BLE Event Handler');
139
+ this.registerPlatformBLE();
140
+
137
141
  // Start an update interval
138
142
  interval(this.deviceRefreshRate * 1000)
139
143
  .pipe(skipWhile(() => this.robotVacuumCleanerUpdateInProgress))
@@ -249,7 +253,7 @@ export class RobotVacuumCleaner extends deviceBase {
249
253
  async refreshStatus(): Promise<void> {
250
254
  if (!this.device.enableCloudService && this.OpenAPI) {
251
255
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
252
- } else if (this.BLE || this.config.options?.BLE) {
256
+ } else if (this.BLE) {
253
257
  await this.BLERefreshStatus();
254
258
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
255
259
  await this.openAPIRefreshStatus();
@@ -261,6 +265,29 @@ export class RobotVacuumCleaner extends deviceBase {
261
265
 
262
266
  async BLERefreshStatus(): Promise<void> {
263
267
  await this.debugLog('BLERefreshStatus');
268
+ const switchbot = await this.switchbotBLE();
269
+ if (switchbot === undefined) {
270
+ await this.BLERefreshConnection(switchbot);
271
+ } else {
272
+ // Start to monitor advertisement packets
273
+ (async () => {
274
+ // Start to monitor advertisement packets
275
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
276
+ // Update HomeKit
277
+ if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
278
+ this.serviceData = serviceData;
279
+ await this.BLEparseStatus();
280
+ await this.updateHomeKitCharacteristics();
281
+ } else {
282
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
283
+ await this.BLERefreshConnection(switchbot);
284
+ }
285
+ })();
286
+ }
287
+ }
288
+
289
+ async registerPlatformBLE(): Promise<void> {
290
+ await this.debugLog('registerPlatformBLE');
264
291
  if (this.config.options?.BLE) {
265
292
  await this.debugLog('is listening to Platform BLE.');
266
293
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -276,26 +303,7 @@ export class RobotVacuumCleaner extends deviceBase {
276
303
  }
277
304
  };
278
305
  } else {
279
- await this.debugLog('is using Device BLE Scanning.');
280
- const switchbot = await this.switchbotBLE();
281
- if (switchbot === undefined) {
282
- await this.BLERefreshConnection(switchbot);
283
- } else {
284
- // Start to monitor advertisement packets
285
- (async () => {
286
- // Start to monitor advertisement packets
287
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
288
- // Update HomeKit
289
- if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
290
- this.serviceData = serviceData;
291
- await this.BLEparseStatus();
292
- await this.updateHomeKitCharacteristics();
293
- } else {
294
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
295
- await this.BLERefreshConnection(switchbot);
296
- }
297
- })();
298
- }
306
+ await this.debugLog('is not listening to Platform BLE');
299
307
  }
300
308
  }
301
309
 
@@ -121,10 +121,14 @@ export class WaterDetector extends deviceBase {
121
121
  this.debugLog('Retrieve initial values and update Homekit');
122
122
  this.refreshStatus();
123
123
 
124
- //regisiter webhook event handler
124
+ //regisiter webhook event handler if enabled
125
125
  this.debugLog('Registering Webhook Event Handler');
126
126
  this.registerWebhook();
127
127
 
128
+ //regisiter platform BLE event handler if enabled
129
+ this.debugLog('Registering Platform BLE Event Handler');
130
+ this.registerPlatformBLE();
131
+
128
132
  // Start an update interval
129
133
  interval(this.deviceRefreshRate * 1000)
130
134
  .pipe(skipWhile(() => this.WaterDetectorUpdateInProgress))
@@ -234,7 +238,7 @@ export class WaterDetector extends deviceBase {
234
238
  async refreshStatus(): Promise<void> {
235
239
  if (!this.device.enableCloudService && this.OpenAPI) {
236
240
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
237
- } else if (this.BLE || this.config.options?.BLE) {
241
+ } else if (this.BLE) {
238
242
  await this.BLERefreshStatus();
239
243
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
240
244
  await this.openAPIRefreshStatus();
@@ -246,6 +250,29 @@ export class WaterDetector extends deviceBase {
246
250
 
247
251
  async BLERefreshStatus(): Promise<void> {
248
252
  await this.debugLog('BLERefreshStatus');
253
+ const switchbot = await this.switchbotBLE();
254
+ if (switchbot === undefined) {
255
+ await this.BLERefreshConnection(switchbot);
256
+ } else {
257
+ // Start to monitor advertisement packets
258
+ (async () => {
259
+ // Start to monitor advertisement packets
260
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as waterLeakDetectorServiceData;
261
+ // Update HomeKit
262
+ if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
263
+ this.serviceData = serviceData;
264
+ await this.BLEparseStatus();
265
+ await this.updateHomeKitCharacteristics();
266
+ } else {
267
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
268
+ await this.BLERefreshConnection(switchbot);
269
+ }
270
+ })();
271
+ }
272
+ }
273
+
274
+ async registerPlatformBLE(): Promise<void> {
275
+ await this.debugLog('registerPlatformBLE');
249
276
  if (this.config.options?.BLE) {
250
277
  await this.debugLog('is listening to Platform BLE.');
251
278
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -261,26 +288,7 @@ export class WaterDetector extends deviceBase {
261
288
  }
262
289
  };
263
290
  } else {
264
- await this.debugLog('is using Device BLE Scanning.');
265
- const switchbot = await this.switchbotBLE();
266
- if (switchbot === undefined) {
267
- await this.BLERefreshConnection(switchbot);
268
- } else {
269
- // Start to monitor advertisement packets
270
- (async () => {
271
- // Start to monitor advertisement packets
272
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as waterLeakDetectorServiceData;
273
- // Update HomeKit
274
- if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
275
- this.serviceData = serviceData;
276
- await this.BLEparseStatus();
277
- await this.updateHomeKitCharacteristics();
278
- } else {
279
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
280
- await this.BLERefreshConnection(switchbot);
281
- }
282
- })();
283
- }
291
+ await this.debugLog('is not listening to Platform BLE');
284
292
  }
285
293
  }
286
294
 
@@ -67,76 +67,33 @@ export abstract class irdeviceBase {
67
67
  }
68
68
 
69
69
  async getDeviceConfigSettings(device: irdevice & irDevicesConfig): Promise<void> {
70
- const deviceConfig = {};
71
- if (device.logging !== 'standard') {
72
- deviceConfig['logging'] = device.logging;
73
- }
74
- if (device.connectionType !== '') {
75
- deviceConfig['connectionType'] = device.connectionType;
76
- }
77
- if (device.external === true) {
78
- deviceConfig['external'] = device.external;
79
- }
80
- if (device.customize === true) {
81
- deviceConfig['customize'] = device.customize;
82
- }
83
- if (device.commandType !== '') {
84
- deviceConfig['commandType'] = device.commandType;
85
- }
86
- if (device.customOn !== '') {
87
- deviceConfig['customOn'] = device.customOn;
88
- }
89
- if (device.customOff !== '') {
90
- deviceConfig['customOff'] = device.customOff;
91
- }
92
- if (device.disablePushOn === true) {
93
- deviceConfig['disablePushOn'] = device.disablePushOn;
94
- }
95
- if (device.disablePushOff === true) {
96
- deviceConfig['disablePushOff'] = device.disablePushOff;
97
- }
98
- if (device.disablePushDetail === true) {
99
- deviceConfig['disablePushDetail'] = device.disablePushDetail;
100
- }
101
- let irairConfig = {};
102
- if (device.irair) {
103
- irairConfig = device.irair;
104
- }
105
- let irpurConfig = {};
106
- if (device.irpur) {
107
- irpurConfig = device.irpur;
108
- }
109
- let ircamConfig = {};
110
- if (device.ircam) {
111
- ircamConfig = device.ircam;
112
- }
113
- let irfanConfig = {};
114
- if (device.irfan) {
115
- irfanConfig = device.irfan;
116
- }
117
- let irlightConfig = {};
118
- if (device.irlight) {
119
- irlightConfig = device.irlight;
120
- }
121
- let otherConfig = {};
122
- if (device.other) {
123
- otherConfig = device.other;
124
- }
125
- let irtvConfig = {};
126
- if (device.irtv) {
127
- irtvConfig = device.irtv;
128
- }
129
- let irvcConfig = {};
130
- if (device.irvc) {
131
- irvcConfig = device.irvc;
132
- }
133
- let irwhConfig = {};
134
- if (device.irwh) {
135
- irwhConfig = device.irwh;
136
- }
137
- const config = Object.assign({}, deviceConfig, irairConfig, irpurConfig, ircamConfig, irfanConfig, irlightConfig, otherConfig,
138
- irtvConfig, irvcConfig, irwhConfig);
139
- if (Object.entries(config).length !== 0) {
70
+ const deviceConfig = Object.assign(
71
+ {},
72
+ device.logging !== 'standard' && { logging: device.logging },
73
+ device.connectionType !== '' && { connectionType: device.connectionType },
74
+ device.external === true && { external: device.external },
75
+ device.customize === true && { customize: device.customize },
76
+ device.commandType !== '' && { commandType: device.commandType },
77
+ device.customOn !== '' && { customOn: device.customOn },
78
+ device.customOff !== '' && { customOff: device.customOff },
79
+ device.disablePushOn === true && { disablePushOn: device.disablePushOn },
80
+ device.disablePushOff === true && { disablePushOff: device.disablePushOff },
81
+ device.disablePushDetail === true && { disablePushDetail: device.disablePushDetail },
82
+ );
83
+ const config = Object.assign(
84
+ {},
85
+ deviceConfig,
86
+ device.irair,
87
+ device.irpur,
88
+ device.ircam,
89
+ device.irfan,
90
+ device.irlight,
91
+ device.other,
92
+ device.irtv,
93
+ device.irvc,
94
+ device.irwh,
95
+ );
96
+ if (Object.keys(config).length !== 0) {
140
97
  this.debugSuccessLog(`Config: ${JSON.stringify(config)}`);
141
98
  }
142
99
  }
@@ -280,70 +237,33 @@ export abstract class irdeviceBase {
280
237
  }
281
238
 
282
239
  async statusCode(statusCode: number): Promise<void> {
283
- switch (statusCode) {
284
- case 151:
285
- this.errorLog(`Command not supported by this deviceType, statusCode: ${statusCode}`);
286
- break;
287
- case 152:
288
- this.errorLog(`Device not found, statusCode: ${statusCode}`);
289
- break;
290
- case 160:
291
- this.errorLog(`Command is not supported, statusCode: ${statusCode}`);
292
- break;
293
- case 161:
294
- this.errorLog(`Device is offline, statusCode: ${statusCode}`);
295
- break;
296
- case 171:
297
- this.errorLog(`Hub Device is offline, statusCode: ${statusCode}. Hub: ${this.device.hubDeviceId}`);
298
- break;
299
- case 190:
300
- this.errorLog('Device internal error due to device states not synchronized with server, Or command format is invalid,'
301
- + ` statusCode: ${statusCode}`);
302
- break;
303
- case 100:
304
- await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
305
- break;
306
- case 200:
307
- await this.debugLog(`Request successful, statusCode: ${statusCode}`);
308
- break;
309
- case 400:
310
- this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request'
311
- + ` payload, statusCode: ${statusCode}`);
312
- break;
313
- case 401:
314
- this.errorLog(`Unauthorized, Authorization for the API is required, but the request has not been authenticated, statusCode: ${statusCode}`);
315
- break;
316
- case 403:
317
- this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not'
318
- + ` found, statusCode: ${statusCode}`);
319
- break;
320
- case 404:
321
- this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
322
- break;
323
- case 406:
324
- this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server,'
325
- + ` statusCode: ${statusCode}`);
326
- break;
327
- case 415:
328
- this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server,'
329
- + ` statusCode: ${statusCode}`);
330
- break;
331
- case 422:
332
- this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for APIs'
333
- + ` for which certain limits have been exceeded, statusCode: ${statusCode}`);
334
- break;
335
- case 429:
336
- this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window,'
337
- + ` statusCode: ${statusCode}`);
338
- break;
339
- case 500:
340
- this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare,'
341
- + ` statusCode: ${statusCode}`);
342
- break;
343
- default:
344
- this.infoLog('Unknown statusCode: '
345
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
346
- }
240
+ const statusMessages = {
241
+ 151: 'Command not supported by this deviceType',
242
+ 152: 'Device not found',
243
+ 160: 'Command is not supported',
244
+ 161: 'Device is offline',
245
+ 171: `Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
246
+ 190: 'Device internal error due to device states not synchronized with server, or command format is invalid',
247
+ 100: 'Command successfully sent',
248
+ 200: 'Request successful',
249
+ 400: 'Bad Request, an invalid payload request',
250
+ 401: 'Unauthorized, Authorization for the API is required, but the request has not been authenticated',
251
+ 403: 'Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not found',
252
+ 404: 'Not Found, Specifies the requested path does not exist',
253
+ 406: 'Not Acceptable, a MIME type has been requested via the Accept header for a value not supported by the server',
254
+ 415: 'Unsupported Media Type, a contentType header has been defined that is not supported by the server',
255
+ 422: 'Unprocessable Entity: The server cannot process the request, often due to exceeded API limits.',
256
+ 429: 'Too Many Requests, exceeded the number of requests allowed for a given time window',
257
+ 500: 'Internal Server Error, An unexpected error occurred. These errors should be rare',
258
+ };
259
+ if (statusCode === 171 && (this.device.hubDeviceId === this.device.deviceId || this.device.hubDeviceId === '000000000000')) {
260
+ this.debugErrorLog(`statusCode 171 changed to 161: hubDeviceId ${this.device.hubDeviceId} matches deviceId`
261
+ + ` ${this.device.deviceId}, device is its own hub.`);
262
+ statusCode = 161;
263
+ }
264
+ const logMessage = statusMessages[statusCode] || `Unknown statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`;
265
+ const logMethod = [100, 200].includes(statusCode) ? 'debugLog' : statusMessages[statusCode] ? 'errorLog' : 'infoLog';
266
+ this[logMethod](`${logMessage}, statusCode: ${statusCode}`);
347
267
  }
348
268
 
349
269
  /**