@switchbot/homebridge-switchbot 3.7.1-beta.0 → 3.7.1-beta.2

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.
@@ -163,115 +163,45 @@ export abstract class deviceBase {
163
163
  }
164
164
 
165
165
  async getDeviceConfigSettings(device: device & devicesConfig): Promise<void> {
166
- const deviceConfig = {};
167
- if (device.logging !== 'standard') {
168
- deviceConfig['logging'] = device.logging;
169
- }
170
- if (device.refreshRate !== 0) {
171
- deviceConfig['refreshRate'] = device.refreshRate;
172
- }
173
- if (device.updateRate !== 0) {
174
- deviceConfig['updateRate'] = device.updateRate;
175
- }
176
- if (device.scanDuration !== 0) {
177
- deviceConfig['scanDuration'] = device.scanDuration;
178
- }
179
- if (device.offline === true) {
180
- deviceConfig['offline'] = device.offline;
181
- }
182
- if (device.maxRetry !== 0) {
183
- deviceConfig['maxRetry'] = device.maxRetry;
184
- }
185
- if (device.webhook === true) {
186
- deviceConfig['webhook'] = device.webhook;
187
- }
188
- if (device.connectionType !== '') {
189
- deviceConfig['connectionType'] = device.connectionType;
190
- }
191
- if (device.external === true) {
192
- deviceConfig['external'] = device.external;
193
- }
194
- if (device.mqttURL !== '') {
195
- deviceConfig['mqttURL'] = device.mqttURL;
196
- }
197
- if (device.mqttOptions) {
198
- deviceConfig['mqttOptions'] = device.mqttOptions;
199
- }
200
- if (device.mqttPubOptions) {
201
- deviceConfig['mqttPubOptions'] = device.mqttPubOptions;
202
- }
203
- if (device.maxRetries !== 0) {
204
- deviceConfig['maxRetries'] = device.maxRetries;
205
- }
206
- if (device.delayBetweenRetries !== 0) {
207
- deviceConfig['delayBetweenRetries'] = device.delayBetweenRetries;
208
- }
209
- let botConfig = {};
210
- if (device.bot) {
211
- botConfig = device.bot;
212
- }
213
- let lockConfig = {};
214
- if (device.lock) {
215
- lockConfig = device.lock;
216
- }
217
- let ceilinglightConfig = {};
218
- if (device.ceilinglight) {
219
- ceilinglightConfig = device.ceilinglight;
220
- }
221
- let colorbulbConfig = {};
222
- if (device.colorbulb) {
223
- colorbulbConfig = device.colorbulb;
224
- }
225
- let contactConfig = {};
226
- if (device.contact) {
227
- contactConfig = device.contact;
228
- }
229
- let motionConfig = {};
230
- if (device.motion) {
231
- motionConfig = device.motion;
232
- }
233
- let curtainConfig = {};
234
- if (device.curtain) {
235
- curtainConfig = device.curtain;
236
- }
237
- let hubConfig = {};
238
- if (device.hub) {
239
- hubConfig = device.hub;
240
- }
241
- let waterdetectorConfig = {};
242
- if (device.waterdetector) {
243
- waterdetectorConfig = device.waterdetector;
244
- }
245
- let humidifierConfig = {};
246
- if (device.humidifier) {
247
- humidifierConfig = device.humidifier;
248
- }
249
- let meterConfig = {};
250
- if (device.meter) {
251
- meterConfig = device.meter;
252
- }
253
- let iosensorConfig = {};
254
- if (device.iosensor) {
255
- iosensorConfig = device.iosensor;
256
- }
257
- let striplightConfig = {};
258
- if (device.striplight) {
259
- striplightConfig = device.striplight;
260
- }
261
- let plugConfig = {};
262
- if (device.plug) {
263
- plugConfig = device.plug;
264
- }
265
- let blindTiltConfig = {};
266
- if (device.blindTilt) {
267
- if (device.blindTilt?.mode === undefined) {
268
- blindTiltConfig['mode'] = BlindTiltMappingMode.OnlyUp;
269
- }
270
- blindTiltConfig = device.blindTilt;
271
- }
272
- const config = Object.assign({}, deviceConfig, botConfig, curtainConfig, waterdetectorConfig, striplightConfig, plugConfig, iosensorConfig,
273
- meterConfig, humidifierConfig, hubConfig, lockConfig, ceilinglightConfig, colorbulbConfig, contactConfig, motionConfig, blindTiltConfig);
274
- if (Object.entries(config).length !== 0) {
166
+ const deviceConfig = Object.assign(
167
+ {},
168
+ device.logging !== 'standard' && { logging: device.logging },
169
+ device.refreshRate !== 0 && { refreshRate: device.refreshRate },
170
+ device.updateRate !== 0 && { updateRate: device.updateRate },
171
+ device.scanDuration !== 0 && { scanDuration: device.scanDuration },
172
+ device.offline === true && { offline: device.offline },
173
+ device.maxRetry !== 0 && { maxRetry: device.maxRetry },
174
+ device.webhook === true && { webhook: device.webhook },
175
+ device.connectionType !== '' && { connectionType: device.connectionType },
176
+ device.external === true && { external: device.external },
177
+ device.mqttURL !== '' && { mqttURL: device.mqttURL },
178
+ device.mqttOptions && { mqttOptions: device.mqttOptions },
179
+ device.mqttPubOptions && { mqttPubOptions: device.mqttPubOptions },
180
+ device.maxRetries !== 0 && { maxRetries: device.maxRetries },
181
+ device.delayBetweenRetries !== 0 && { delayBetweenRetries: device.delayBetweenRetries },
182
+ );
183
+ const config = Object.assign(
184
+ {},
185
+ deviceConfig,
186
+ device.bot,
187
+ device.lock,
188
+ device.ceilinglight,
189
+ device.colorbulb,
190
+ device.contact,
191
+ device.motion,
192
+ device.curtain,
193
+ device.hub,
194
+ device.waterdetector,
195
+ device.humidifier,
196
+ device.meter,
197
+ device.iosensor,
198
+ device.striplight,
199
+ device.plug,
200
+ device.blindTilt?.mode === undefined ? { mode: BlindTiltMappingMode.OnlyUp } : {},
201
+ device.blindTilt,
202
+ );
203
+
204
+ if (Object.keys(config).length !== 0) {
275
205
  this.debugSuccessLog(`Config: ${JSON.stringify(config)}`);
276
206
  }
277
207
  }
@@ -450,224 +380,225 @@ export abstract class deviceBase {
450
380
  }
451
381
 
452
382
  async getDeviceContext(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
453
- // Set the accessory context
454
- switch (device.deviceType) {
455
- case 'Humidifier':
456
- device.model = SwitchBotModel.Humidifier;
457
- device.bleModel = SwitchBotBLEModel.Humidifier;
458
- device.bleModelName = SwitchBotBLEModelName.Humidifier;
459
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Humidifier;
460
- break;
461
- case 'Hub Mini':
462
- device.model = SwitchBotModel.HubMini;
463
- device.bleModel = SwitchBotBLEModel.Unknown;
464
- device.bleModelName = SwitchBotBLEModelName.Unknown;
465
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
466
- break;
467
- case 'Hub Plus':
468
- device.model = SwitchBotModel.HubPlus;
469
- device.bleModel = SwitchBotBLEModel.Unknown;
470
- device.bleModelName = SwitchBotBLEModelName.Unknown;
471
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
472
- break;
473
- case 'Hub 2':
474
- device.model = SwitchBotModel.Hub2;
475
- device.bleModel = SwitchBotBLEModel.Hub2;
476
- device.bleModelName = SwitchBotBLEModelName.Hub2;
477
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Hub2;
478
- break;
479
- case 'Bot':
480
- device.model = SwitchBotModel.Bot;
481
- device.bleModel = SwitchBotBLEModel.Bot;
482
- device.bleModelName = SwitchBotBLEModelName.Bot;
483
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Bot;
484
- break;
485
- case 'Meter':
486
- device.model = SwitchBotModel.Meter;
487
- device.bleModel = SwitchBotBLEModel.Meter;
488
- device.bleModelName = SwitchBotBLEModelName.Meter;
489
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Meter;
490
- break;
491
- case 'MeterPlus':
492
- device.model = SwitchBotModel.MeterPlusUS;
493
- device.bleModel = SwitchBotBLEModel.MeterPlus;
494
- device.bleModelName = SwitchBotBLEModelName.MeterPlus;
495
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.MeterPlus;
496
- break;
497
- case 'Meter Plus (JP)':
498
- device.model = SwitchBotModel.MeterPlusJP;
499
- device.bleModel = SwitchBotBLEModel.MeterPlus;
500
- device.bleModelName = SwitchBotBLEModelName.MeterPlus;
501
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.MeterPlus;
502
- break;
503
- case 'WoIOSensor':
504
- device.model = SwitchBotModel.OutdoorMeter;
505
- device.bleModel = SwitchBotBLEModel.OutdoorMeter;
506
- device.bleModelName = SwitchBotBLEModelName.OutdoorMeter;
507
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.OutdoorMeter;
508
- break;
509
- case 'Water Detector':
510
- device.model = SwitchBotModel.WaterDetector;
511
- device.bleModel = SwitchBotBLEModel.Unknown;
512
- device.bleModelName = SwitchBotBLEModelName.Unknown;
513
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
514
- break;
515
- case 'Motion Sensor':
516
- device.model = SwitchBotModel.MotionSensor;
517
- device.bleModel = SwitchBotBLEModel.MotionSensor;
518
- device.bleModelName = SwitchBotBLEModelName.MotionSensor;
519
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.MotionSensor;
520
- break;
521
- case 'Contact Sensor':
522
- device.model = SwitchBotModel.ContactSensor;
523
- device.bleModel = SwitchBotBLEModel.ContactSensor;
524
- device.bleModelName = SwitchBotBLEModelName.ContactSensor;
525
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.ContactSensor;
526
- break;
527
- case 'Curtain':
528
- device.model = SwitchBotModel.Curtain;
529
- device.bleModel = SwitchBotBLEModel.Curtain;
530
- device.bleModelName = SwitchBotBLEModelName.Curtain;
531
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Curtain;
532
- break;
533
- case 'Curtain3':
534
- device.model = SwitchBotModel.Curtain3;
535
- device.bleModel = SwitchBotBLEModel.Curtain3;
536
- device.bleModelName = SwitchBotBLEModelName.Curtain3;
537
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Curtain3;
538
- break;
539
- case 'Blind Tilt':
540
- device.model = SwitchBotModel.BlindTilt;
541
- device.bleModel = SwitchBotBLEModel.BlindTilt;
542
- device.bleModelName = SwitchBotBLEModelName.BlindTilt;
543
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.BlindTilt;
544
- break;
545
- case 'Plug':
546
- device.model = SwitchBotModel.Plug;
547
- device.bleModel = SwitchBotBLEModel.PlugMiniUS;
548
- device.bleModelName = SwitchBotBLEModelName.PlugMini;
549
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.PlugMini;
550
- break;
551
- case 'Plug Mini (US)':
552
- device.model = SwitchBotModel.PlugMiniUS;
553
- device.bleModel = SwitchBotBLEModel.PlugMiniUS;
554
- device.bleModelName = SwitchBotBLEModelName.PlugMini;
555
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.PlugMini;
556
- break;
557
- case 'Plug Mini (JP)':
558
- device.model = SwitchBotModel.PlugMiniJP;
559
- device.bleModel = SwitchBotBLEModel.PlugMiniJP;
560
- device.bleModelName = SwitchBotBLEModelName.PlugMini;
561
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.PlugMini;
562
- break;
563
- case 'Smart Lock':
564
- device.model = SwitchBotModel.Lock;
565
- device.bleModel = SwitchBotBLEModel.Lock;
566
- device.bleModelName = SwitchBotBLEModelName.Lock;
567
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Lock;
568
- break;
569
- case 'Smart Lock Pro':
570
- device.model = SwitchBotModel.LockPro;
571
- device.bleModel = SwitchBotBLEModel.LockPro;
572
- device.bleModelName = SwitchBotBLEModelName.LockPro;
573
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.LockPro;
574
- break;
575
- case 'Color Bulb':
576
- device.model = SwitchBotModel.ColorBulb;
577
- device.bleModel = SwitchBotBLEModel.ColorBulb;
578
- device.bleModelName = SwitchBotBLEModelName.ColorBulb;
579
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.ColorBulb;
580
- break;
581
- case 'K10+':
582
- device.model = SwitchBotModel.K10;
583
- device.bleModel = SwitchBotBLEModel.Unknown;
584
- device.bleModelName = SwitchBotBLEModelName.Unknown;
585
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
586
- break;
587
- case 'WoSweeper':
588
- device.model = SwitchBotModel.WoSweeper;
589
- device.bleModel = SwitchBotBLEModel.Unknown;
590
- device.bleModelName = SwitchBotBLEModelName.Unknown;
591
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
592
- break;
593
- case 'WoSweeperMini':
594
- device.model = SwitchBotModel.WoSweeperMini;
595
- device.bleModel = SwitchBotBLEModel.Unknown;
596
- device.bleModelName = SwitchBotBLEModelName.Unknown;
597
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
598
- break;
599
- case 'Robot Vacuum Cleaner S1':
600
- device.model = SwitchBotModel.RobotVacuumCleanerS1;
601
- device.bleModel = SwitchBotBLEModel.Unknown;
602
- device.bleModelName = SwitchBotBLEModelName.Unknown;
603
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
604
- break;
605
- case 'Robot Vacuum Cleaner S1 Plus':
606
- device.model = SwitchBotModel.RobotVacuumCleanerS1Plus;
607
- device.bleModel = SwitchBotBLEModel.Unknown;
608
- device.bleModelName = SwitchBotBLEModelName.Unknown;
609
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
610
- break;
611
- case 'Robot Vacuum Cleaner S10':
612
- device.model = SwitchBotModel.RobotVacuumCleanerS10;
613
- device.bleModel = SwitchBotBLEModel.Unknown;
614
- device.bleModelName = SwitchBotBLEModelName.Unknown;
615
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
616
- break;
617
- case 'Ceiling Light':
618
- device.model = SwitchBotModel.CeilingLight;
619
- device.bleModel = SwitchBotBLEModel.CeilingLight;
620
- device.bleModelName = SwitchBotBLEModelName.CeilingLight;
621
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.CeilingLight;
622
- break;
623
- case 'Ceiling Light Pro':
624
- device.model = SwitchBotModel.CeilingLightPro;
625
- device.bleModel = SwitchBotBLEModel.CeilingLightPro;
626
- device.bleModelName = SwitchBotBLEModelName.CeilingLightPro;
627
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.CeilingLightPro;
628
- break;
629
- case 'Strip Light':
630
- device.model = SwitchBotModel.StripLight;
631
- device.bleModel = SwitchBotBLEModel.StripLight;
632
- device.bleModelName = SwitchBotBLEModelName.StripLight;
633
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.StripLight;
634
- break;
635
- case 'Indoor Cam':
636
- device.model = SwitchBotModel.IndoorCam;
637
- device.bleModel = SwitchBotBLEModel.Unknown;
638
- device.bleModelName = SwitchBotBLEModelName.Unknown;
639
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
640
- break;
641
- case 'Remote':
642
- device.model = SwitchBotModel.Remote;
643
- device.bleModel = SwitchBotBLEModel.Unknown;
644
- device.bleModelName = SwitchBotBLEModelName.Unknown;
645
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
646
- break;
647
- case 'remote with screen+':
648
- device.model = SwitchBotModel.UniversalRemote;
649
- device.bleModel = SwitchBotBLEModel.Unknown;
650
- device.bleModelName = SwitchBotBLEModelName.Unknown;
651
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
652
- break;
653
- case 'Battery Circulator Fan':
654
- device.model = SwitchBotModel.BatteryCirculatorFan;
655
- device.bleModel = SwitchBotBLEModel.Unknown;
656
- device.bleModelName = SwitchBotBLEModelName.Unknown;
657
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
658
- break;
659
- default:
660
- device.model = SwitchBotModel.Unknown;
661
- device.bleModel = SwitchBotBLEModel.Unknown;
662
- device.bleModelName = SwitchBotBLEModelName.Unknown;
663
- device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
664
- }
383
+ const deviceMapping = {
384
+ 'Humidifier': {
385
+ model: SwitchBotModel.Humidifier,
386
+ bleModel: SwitchBotBLEModel.Humidifier,
387
+ bleModelName: SwitchBotBLEModelName.Humidifier,
388
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Humidifier,
389
+ },
390
+ 'Hub Mini': {
391
+ model: SwitchBotModel.HubMini,
392
+ bleModel: SwitchBotBLEModel.Unknown,
393
+ bleModelName: SwitchBotBLEModelName.Unknown,
394
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
395
+ },
396
+ 'Hub Plus': {
397
+ model: SwitchBotModel.HubPlus,
398
+ bleModel: SwitchBotBLEModel.Unknown,
399
+ bleModelName: SwitchBotBLEModelName.Unknown,
400
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
401
+ },
402
+ 'Hub 2': {
403
+ model: SwitchBotModel.Hub2,
404
+ bleModel: SwitchBotBLEModel.Hub2,
405
+ bleModelName: SwitchBotBLEModelName.Hub2,
406
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Hub2,
407
+ },
408
+ 'Bot': {
409
+ model: SwitchBotModel.Bot,
410
+ bleModel: SwitchBotBLEModel.Bot,
411
+ bleModelName: SwitchBotBLEModelName.Bot,
412
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Bot,
413
+ },
414
+ 'Meter': {
415
+ model: SwitchBotModel.Meter,
416
+ bleModel: SwitchBotBLEModel.Meter,
417
+ bleModelName: SwitchBotBLEModelName.Meter,
418
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Meter,
419
+ },
420
+ 'MeterPlus': {
421
+ model: SwitchBotModel.MeterPlusUS,
422
+ bleModel: SwitchBotBLEModel.MeterPlus,
423
+ bleModelName: SwitchBotBLEModelName.MeterPlus,
424
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.MeterPlus,
425
+ },
426
+ 'Meter Plus (JP)': {
427
+ model: SwitchBotModel.MeterPlusJP,
428
+ bleModel: SwitchBotBLEModel.MeterPlus,
429
+ bleModelName: SwitchBotBLEModelName.MeterPlus,
430
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.MeterPlus,
431
+ },
432
+ 'WoIOSensor': {
433
+ model: SwitchBotModel.OutdoorMeter,
434
+ bleModel: SwitchBotBLEModel.OutdoorMeter,
435
+ bleModelName: SwitchBotBLEModelName.OutdoorMeter,
436
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.OutdoorMeter,
437
+ },
438
+ 'Water Detector': {
439
+ model: SwitchBotModel.WaterDetector,
440
+ bleModel: SwitchBotBLEModel.Unknown,
441
+ bleModelName: SwitchBotBLEModelName.Unknown,
442
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
443
+ },
444
+ 'Motion Sensor': {
445
+ model: SwitchBotModel.MotionSensor,
446
+ bleModel: SwitchBotBLEModel.MotionSensor,
447
+ bleModelName: SwitchBotBLEModelName.MotionSensor,
448
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.MotionSensor,
449
+ },
450
+ 'Contact Sensor': {
451
+ model: SwitchBotModel.ContactSensor,
452
+ bleModel: SwitchBotBLEModel.ContactSensor,
453
+ bleModelName: SwitchBotBLEModelName.ContactSensor,
454
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.ContactSensor,
455
+ },
456
+ 'Curtain': {
457
+ model: SwitchBotModel.Curtain,
458
+ bleModel: SwitchBotBLEModel.Curtain,
459
+ bleModelName: SwitchBotBLEModelName.Curtain,
460
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Curtain,
461
+ },
462
+ 'Curtain3': {
463
+ model: SwitchBotModel.Curtain3,
464
+ bleModel: SwitchBotBLEModel.Curtain3,
465
+ bleModelName: SwitchBotBLEModelName.Curtain3,
466
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Curtain3,
467
+ },
468
+ 'Blind Tilt': {
469
+ model: SwitchBotModel.BlindTilt,
470
+ bleModel: SwitchBotBLEModel.BlindTilt,
471
+ bleModelName: SwitchBotBLEModelName.BlindTilt,
472
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.BlindTilt,
473
+ },
474
+ 'Plug': {
475
+ model: SwitchBotModel.Plug,
476
+ bleModel: SwitchBotBLEModel.PlugMiniUS,
477
+ bleModelName: SwitchBotBLEModelName.PlugMini,
478
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.PlugMini,
479
+ },
480
+ 'Plug Mini (US)': {
481
+ model: SwitchBotModel.PlugMiniUS,
482
+ bleModel: SwitchBotBLEModel.PlugMiniUS,
483
+ bleModelName: SwitchBotBLEModelName.PlugMini,
484
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.PlugMini,
485
+ },
486
+ 'Plug Mini (JP)': {
487
+ model: SwitchBotModel.PlugMiniJP,
488
+ bleModel: SwitchBotBLEModel.PlugMiniJP,
489
+ bleModelName: SwitchBotBLEModelName.PlugMini,
490
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.PlugMini,
491
+ },
492
+ 'Smart Lock': {
493
+ model: SwitchBotModel.Lock,
494
+ bleModel: SwitchBotBLEModel.Lock,
495
+ bleModelName: SwitchBotBLEModelName.Lock,
496
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Lock,
497
+ },
498
+ 'Smart Lock Pro': {
499
+ model: SwitchBotModel.LockPro,
500
+ bleModel: SwitchBotBLEModel.LockPro,
501
+ bleModelName: SwitchBotBLEModelName.LockPro,
502
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.LockPro,
503
+ },
504
+ 'Color Bulb': {
505
+ model: SwitchBotModel.ColorBulb,
506
+ bleModel: SwitchBotBLEModel.ColorBulb,
507
+ bleModelName: SwitchBotBLEModelName.ColorBulb,
508
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.ColorBulb,
509
+ },
510
+ 'K10+': {
511
+ model: SwitchBotModel.K10,
512
+ bleModel: SwitchBotBLEModel.Unknown,
513
+ bleModelName: SwitchBotBLEModelName.Unknown,
514
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
515
+ },
516
+ 'WoSweeper': {
517
+ model: SwitchBotModel.WoSweeper,
518
+ bleModel: SwitchBotBLEModel.Unknown,
519
+ bleModelName: SwitchBotBLEModelName.Unknown,
520
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
521
+ },
522
+ 'WoSweeperMini': {
523
+ model: SwitchBotModel.WoSweeperMini,
524
+ bleModel: SwitchBotBLEModel.Unknown,
525
+ bleModelName: SwitchBotBLEModelName.Unknown,
526
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
527
+ },
528
+ 'Robot Vacuum Cleaner S1': {
529
+ model: SwitchBotModel.RobotVacuumCleanerS1,
530
+ bleModel: SwitchBotBLEModel.Unknown,
531
+ bleModelName: SwitchBotBLEModelName.Unknown,
532
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
533
+ },
534
+ 'Robot Vacuum Cleaner S1 Plus': {
535
+ model: SwitchBotModel.RobotVacuumCleanerS1Plus,
536
+ bleModel: SwitchBotBLEModel.Unknown,
537
+ bleModelName: SwitchBotBLEModelName.Unknown,
538
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
539
+ },
540
+ 'Robot Vacuum Cleaner S10': {
541
+ model: SwitchBotModel.RobotVacuumCleanerS10,
542
+ bleModel: SwitchBotBLEModel.Unknown,
543
+ bleModelName: SwitchBotBLEModelName.Unknown,
544
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
545
+ },
546
+ 'Ceiling Light': {
547
+ model: SwitchBotModel.CeilingLight,
548
+ bleModel: SwitchBotBLEModel.CeilingLight,
549
+ bleModelName: SwitchBotBLEModelName.CeilingLight,
550
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.CeilingLight,
551
+ },
552
+ 'Ceiling Light Pro': {
553
+ model: SwitchBotModel.CeilingLightPro,
554
+ bleModel: SwitchBotBLEModel.CeilingLightPro,
555
+ bleModelName: SwitchBotBLEModelName.CeilingLightPro,
556
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.CeilingLightPro,
557
+ },
558
+ 'Strip Light': {
559
+ model: SwitchBotModel.StripLight,
560
+ bleModel: SwitchBotBLEModel.StripLight,
561
+ bleModelName: SwitchBotBLEModelName.StripLight,
562
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.StripLight,
563
+ },
564
+ 'Indoor Cam': {
565
+ model: SwitchBotModel.IndoorCam,
566
+ bleModel: SwitchBotBLEModel.Unknown,
567
+ bleModelName: SwitchBotBLEModelName.Unknown,
568
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
569
+ },
570
+ 'Remote': {
571
+ model: SwitchBotModel.Remote,
572
+ bleModel: SwitchBotBLEModel.Unknown,
573
+ bleModelName: SwitchBotBLEModelName.Unknown,
574
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
575
+ },
576
+ 'remote with screen+': {
577
+ model: SwitchBotModel.UniversalRemote,
578
+ bleModel: SwitchBotBLEModel.Unknown,
579
+ bleModelName: SwitchBotBLEModelName.Unknown,
580
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
581
+ },
582
+ 'Battery Circulator Fan': {
583
+ model: SwitchBotModel.BatteryCirculatorFan,
584
+ bleModel: SwitchBotBLEModel.Unknown,
585
+ bleModelName: SwitchBotBLEModelName.Unknown,
586
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
587
+ },
588
+ };
589
+ const defaultDevice = {
590
+ model: SwitchBotModel.Unknown,
591
+ bleModel: SwitchBotBLEModel.Unknown,
592
+ bleModelName: SwitchBotBLEModelName.Unknown,
593
+ bleModelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
594
+ };
595
+ const deviceConfig = deviceMapping[device.deviceType] || defaultDevice;
596
+ device.model = deviceConfig.model;
597
+ device.bleModel = deviceConfig.bleModel;
598
+ device.bleModelName = deviceConfig.bleModelName;
599
+ device.bleModelFriednlyName = deviceConfig.bleModelFriednlyName;
665
600
  await this.debugLog(`Model: ${device.model}, BLE Model: ${device.bleModel}, BLE Model Name: ${device.bleModelName}, `
666
601
  + `BLE Model Friendly Name: ${device.bleModelFriednlyName}`);
667
- accessory.context.model = device.model;
668
- accessory.context.bleModel = device.bleModel;
669
- accessory.context.bleModelName = device.bleModelName;
670
- accessory.context.bleModelFriednlyName = device.bleModelFriednlyName;
671
602
 
672
603
  const deviceFirmwareVersion = device.firmware ?? device.version ?? accessory.context.version ?? this.platform.version ?? '0.0.0';
673
604
  const version = deviceFirmwareVersion.toString();
@@ -693,76 +624,33 @@ export abstract class deviceBase {
693
624
  }
694
625
 
695
626
  async statusCode(statusCode: number): Promise<void> {
696
- if (statusCode === 171) {
697
- const previousStatusCode = statusCode;
698
- if (this.device.hubDeviceId === this.device.deviceId) {
699
- statusCode = 161;
700
- }
701
- if (this.device.hubDeviceId === '000000000000') {
702
- statusCode = 161;
703
- }
704
- this.debugErrorLog(`statusCode: ${previousStatusCode} is now statusCode: ${statusCode}, because the hubDeviceId: ${this.device.hubDeviceId}`
705
- + ` is set to the same as the deviceId: ${this.device.deviceId}, meaning the device is it's own hub.`);
706
- }
707
- switch (statusCode) {
708
- case 151:
709
- this.errorLog(`Command not supported by this deviceType, statusCode: ${statusCode}`);
710
- break;
711
- case 152:
712
- this.errorLog(`Device not found, statusCode: ${statusCode}`);
713
- break;
714
- case 160:
715
- this.errorLog(`Command is not supported, statusCode: ${statusCode}`);
716
- break;
717
- case 161:
718
- this.errorLog(`Device is offline, statusCode: ${statusCode}`);
719
- break;
720
- case 171:
721
- this.errorLog(`Hub Device is offline, statusCode: ${statusCode}. Hub: ${this.device.hubDeviceId}`);
722
- break;
723
- case 190:
724
- this.errorLog('Device internal error due to device states not synchronized with server, or command format is invalid,'
725
- + ` statusCode: ${statusCode}`);
726
- break;
727
- case 100:
728
- this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
729
- break;
730
- case 200:
731
- this.debugLog(`Request successful, statusCode: ${statusCode}`);
732
- break;
733
- case 400:
734
- this.errorLog(`Bad Request, an invalid payload request, statusCode: ${statusCode}`);
735
- break;
736
- case 401:
737
- this.errorLog(`Unauthorized, Authorization for the API is required, but the request has not been authenticated, statusCode: ${statusCode}`);
738
- break;
739
- case 403:
740
- this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions,'
741
- + ` or a requested resource is not found, statusCode: ${statusCode}`);
742
- break;
743
- case 404:
744
- this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
745
- break;
746
- case 406:
747
- this.errorLog('Not Acceptable, a MIME type has been requested via the Accept header for a value not supported by the server,'
748
- + ` statusCode: ${statusCode}`);
749
- break;
750
- case 415:
751
- this.errorLog(`Unsupported Media Type, a contentType header has been defined that is not supported by the server, statusCode: ${statusCode}`);
752
- break;
753
- case 422:
754
- this.errorLog('Unprocessable Entity, a valid request has been made, but the server cannot process it. '
755
- + `This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
756
- break;
757
- case 429:
758
- this.errorLog(`Too Many Requests, exceeded the number of requests allowed for a given time window, statusCode: ${statusCode}`);
759
- break;
760
- case 500:
761
- this.errorLog(`Internal Server Error, An unexpected error occurred. These errors should be rare, statusCode: ${statusCode}`);
762
- break;
763
- default:
764
- this.infoLog(`Unknown statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
765
- }
627
+ const statusMessages = {
628
+ 151: 'Command not supported by this deviceType',
629
+ 152: 'Device not found',
630
+ 160: 'Command is not supported',
631
+ 161: 'Device is offline',
632
+ 171: `Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
633
+ 190: 'Device internal error due to device states not synchronized with server, or command format is invalid',
634
+ 100: 'Command successfully sent',
635
+ 200: 'Request successful',
636
+ 400: 'Bad Request, an invalid payload request',
637
+ 401: 'Unauthorized, Authorization for the API is required, but the request has not been authenticated',
638
+ 403: 'Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not found',
639
+ 404: 'Not Found, Specifies the requested path does not exist',
640
+ 406: 'Not Acceptable, a MIME type has been requested via the Accept header for a value not supported by the server',
641
+ 415: 'Unsupported Media Type, a contentType header has been defined that is not supported by the server',
642
+ 422: 'Unprocessable Entity: The server cannot process the request, often due to exceeded API limits.',
643
+ 429: 'Too Many Requests, exceeded the number of requests allowed for a given time window',
644
+ 500: 'Internal Server Error, An unexpected error occurred. These errors should be rare',
645
+ };
646
+ if (statusCode === 171 && (this.device.hubDeviceId === this.device.deviceId || this.device.hubDeviceId === '000000000000')) {
647
+ this.debugErrorLog(`statusCode 171 changed to 161: hubDeviceId ${this.device.hubDeviceId} matches deviceId`
648
+ + ` ${this.device.deviceId}, device is its own hub.`);
649
+ statusCode = 161;
650
+ }
651
+ const logMessage = statusMessages[statusCode] || `Unknown statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`;
652
+ const logMethod = [100, 200].includes(statusCode) ? 'debugLog' : statusMessages[statusCode] ? 'errorLog' : 'infoLog';
653
+ this[logMethod](`${logMessage}, statusCode: ${statusCode}`);
766
654
  }
767
655
 
768
656
  /**