@switchbot/homebridge-switchbot 1.2.3 → 1.2.6-beta.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 (53) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/devices/bots.js +8 -8
  3. package/dist/devices/bots.js.map +1 -1
  4. package/dist/devices/contact.js +6 -6
  5. package/dist/devices/contact.js.map +1 -1
  6. package/dist/devices/curtains.d.ts.map +1 -1
  7. package/dist/devices/curtains.js +9 -7
  8. package/dist/devices/curtains.js.map +1 -1
  9. package/dist/devices/humidifiers.js +2 -2
  10. package/dist/devices/humidifiers.js.map +1 -1
  11. package/dist/devices/plugs.d.ts +0 -1
  12. package/dist/devices/plugs.d.ts.map +1 -1
  13. package/dist/devices/plugs.js +0 -10
  14. package/dist/devices/plugs.js.map +1 -1
  15. package/dist/irdevices/airconditioners.d.ts +1 -4
  16. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  17. package/dist/irdevices/airconditioners.js +32 -18
  18. package/dist/irdevices/airconditioners.js.map +1 -1
  19. package/dist/irdevices/airpurifiers.js +3 -3
  20. package/dist/irdevices/airpurifiers.js.map +1 -1
  21. package/dist/irdevices/cameras.js +1 -1
  22. package/dist/irdevices/cameras.js.map +1 -1
  23. package/dist/irdevices/fans.js +3 -3
  24. package/dist/irdevices/fans.js.map +1 -1
  25. package/dist/irdevices/lights.js +1 -1
  26. package/dist/irdevices/lights.js.map +1 -1
  27. package/dist/irdevices/others.js +2 -2
  28. package/dist/irdevices/others.js.map +1 -1
  29. package/dist/irdevices/tvs.js +2 -2
  30. package/dist/irdevices/tvs.js.map +1 -1
  31. package/dist/irdevices/vacuumcleaners.js +1 -1
  32. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  33. package/dist/irdevices/waterheaters.js +1 -1
  34. package/dist/irdevices/waterheaters.js.map +1 -1
  35. package/dist/platform.d.ts.map +1 -1
  36. package/dist/platform.js +3 -0
  37. package/dist/platform.js.map +1 -1
  38. package/package.json +66 -66
  39. package/src/devices/bots.ts +8 -8
  40. package/src/devices/contact.ts +6 -6
  41. package/src/devices/curtains.ts +9 -7
  42. package/src/devices/humidifiers.ts +2 -2
  43. package/src/devices/plugs.ts +0 -11
  44. package/src/irdevices/airconditioners.ts +33 -24
  45. package/src/irdevices/airpurifiers.ts +3 -3
  46. package/src/irdevices/cameras.ts +1 -1
  47. package/src/irdevices/fans.ts +3 -3
  48. package/src/irdevices/lights.ts +1 -1
  49. package/src/irdevices/others.ts +2 -2
  50. package/src/irdevices/tvs.ts +2 -2
  51. package/src/irdevices/vacuumcleaners.ts +1 -1
  52. package/src/irdevices/waterheaters.ts +1 -1
  53. package/src/platform.ts +2 -0
package/package.json CHANGED
@@ -1,68 +1,68 @@
1
1
  {
2
- "displayName": "Homebridge SwitchBot",
3
- "name": "@switchbot/homebridge-switchbot",
4
- "version": "1.2.3",
5
- "description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
6
- "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
7
- "license": "ISC",
8
- "repository": {
9
- "type": "git",
10
- "url": "git://github.com/OpenWonderLabs/homebridge-switchbot.git"
11
- },
12
- "bugs": {
13
- "url": "https://github.com/OpenWonderLabs/homebridge-switchbot/issues"
14
- },
15
- "engines": {
16
- "homebridge": "^1.3.8",
17
- "node": "^14.18.1 || ^16.13.0"
18
- },
19
- "main": "dist/index.js",
20
- "scripts": {
21
- "check": "npm install && npm outdated",
22
- "update": "ncu -u && npm update && npm install",
23
- "lint": "eslint src/**.ts",
24
- "watch": "npm run build && npm link && nodemon",
25
- "build": "rimraf ./dist && tsc",
26
- "prepublishOnly": "npm run lint && npm run build"
27
- },
28
- "funding": [
29
- {
30
- "type": "Paypal",
31
- "url": "https://www.paypal.me/donavanbecker"
2
+ "displayName": "Homebridge SwitchBot",
3
+ "name": "@switchbot/homebridge-switchbot",
4
+ "version": "1.2.6-beta.0",
5
+ "description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
6
+ "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
7
+ "license": "ISC",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git://github.com/OpenWonderLabs/homebridge-switchbot.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/OpenWonderLabs/homebridge-switchbot/issues"
14
+ },
15
+ "engines": {
16
+ "homebridge": "^1.3.8",
17
+ "node": "^14.18.1 || ^16.13.0"
18
+ },
19
+ "main": "dist/index.js",
20
+ "scripts": {
21
+ "check": "npm install && npm outdated",
22
+ "update": "ncu -u && npm update && npm install",
23
+ "lint": "eslint src/**.ts",
24
+ "watch": "npm run build && npm link && nodemon",
25
+ "build": "rimraf ./dist && tsc",
26
+ "prepublishOnly": "npm run lint && npm run build"
27
+ },
28
+ "funding": [
29
+ {
30
+ "type": "Paypal",
31
+ "url": "https://www.paypal.me/donavanbecker"
32
+ }
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "keywords": [
38
+ "homebridge-plugin",
39
+ "switchbot",
40
+ "humidifier",
41
+ "humidity",
42
+ "temperature",
43
+ "bot",
44
+ "curtains",
45
+ "windows",
46
+ "ble",
47
+ "ir"
48
+ ],
49
+ "dependencies": {
50
+ "@homebridge/plugin-ui-utils": "^0.0.19",
51
+ "axios": "^0.24.0",
52
+ "node-switchbot": "^1.1.2",
53
+ "rxjs": "^7.4.0"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^16.11.11",
57
+ "@typescript-eslint/eslint-plugin": "^5.5.0",
58
+ "@typescript-eslint/parser": "^5.5.0",
59
+ "eslint": "^8.3.0",
60
+ "homebridge": "^1.3.8",
61
+ "nodemon": "^2.0.15",
62
+ "npm-check-updates": "^12.0.2",
63
+ "rimraf": "^3.0.2",
64
+ "ts-node": "^10.4.0",
65
+ "typescript": "^4.5.2",
66
+ "typescript-axios-wb": "^1.0.3"
32
67
  }
33
- ],
34
- "publishConfig": {
35
- "access": "public"
36
- },
37
- "keywords": [
38
- "homebridge-plugin",
39
- "switchbot",
40
- "humidifier",
41
- "humidity",
42
- "temperature",
43
- "bot",
44
- "curtains",
45
- "windows",
46
- "ble",
47
- "ir"
48
- ],
49
- "dependencies": {
50
- "@homebridge/plugin-ui-utils": "^0.0.19",
51
- "axios": "^0.24.0",
52
- "node-switchbot": "^1.1.2",
53
- "rxjs": "^7.4.0"
54
- },
55
- "devDependencies": {
56
- "@types/node": "^16.11.10",
57
- "@typescript-eslint/eslint-plugin": "^5.4.0",
58
- "@typescript-eslint/parser": "^5.4.0",
59
- "eslint": "^8.3.0",
60
- "homebridge": "^1.3.8",
61
- "nodemon": "^2.0.15",
62
- "npm-check-updates": "^12.0.2",
63
- "rimraf": "^3.0.2",
64
- "ts-node": "^10.4.0",
65
- "typescript": "^4.5.2",
66
- "typescript-axios-wb": "^1.0.3"
67
- }
68
- }
68
+ }
@@ -75,7 +75,7 @@ export class Bot {
75
75
  if (device.bot?.deviceType === 'switch') {
76
76
  // If outletService still pressent, then remove first
77
77
  if (this.outletService) {
78
- this.platform.device(`Bot: ${this.accessory.displayName} Removing Leftover outletService first`);
78
+ this.platform.device(`Bot: ${accessory.displayName} Removing Leftover outletService first`);
79
79
  }
80
80
  this.outletService = this.accessory.getService(this.platform.Service.Outlet);
81
81
  accessory.removeService(this.outletService!);
@@ -84,13 +84,13 @@ export class Bot {
84
84
  (this.switchService =
85
85
  accessory.getService(this.platform.Service.Switch) ||
86
86
  accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Switch`;
87
- this.platform.log.info(`Bot: ${this.accessory.displayName} Displaying as Switch`);
87
+ this.platform.log.info(`Bot: ${accessory.displayName} Displaying as Switch`);
88
88
 
89
89
  this.switchService?.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
90
90
  } else {
91
91
  // If switchService still pressent, then remove first
92
92
  if (this.switchService) {
93
- this.platform.device(`Bot: ${this.accessory.displayName} Removing Leftover switchService first`);
93
+ this.platform.device(`Bot: ${accessory.displayName} Removing Leftover switchService first`);
94
94
  }
95
95
  this.switchService = this.accessory.getService(this.platform.Service.Switch);
96
96
  accessory.removeService(this.switchService!);
@@ -99,7 +99,7 @@ export class Bot {
99
99
  (this.outletService =
100
100
  accessory.getService(this.platform.Service.Outlet) ||
101
101
  accessory.addService(this.platform.Service.Outlet)), `${accessory.displayName} Outlet`;
102
- this.platform.log.info(`Bot: ${this.accessory.displayName} Displaying as Outlet`);
102
+ this.platform.log.info(`Bot: ${accessory.displayName} Displaying as Outlet`);
103
103
 
104
104
  this.outletService?.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
105
105
  }
@@ -444,9 +444,9 @@ export class Bot {
444
444
  this.platform.debug(`Bot: ${this.accessory.displayName} On: ${this.On}`);
445
445
  } else {
446
446
  if (this.device.bot?.deviceType === 'switch') {
447
- this.switchService!.updateCharacteristic(this.platform.Characteristic.On, this.On);
447
+ this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
448
448
  } else {
449
- this.outletService!.updateCharacteristic(this.platform.Characteristic.On, this.On);
449
+ this.outletService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
450
450
  }
451
451
  this.platform.device(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
452
452
  }
@@ -468,9 +468,9 @@ export class Bot {
468
468
 
469
469
  public apiError(e: any) {
470
470
  if (this.device.bot?.deviceType === 'switch') {
471
- this.switchService!.updateCharacteristic(this.platform.Characteristic.On, e);
471
+ this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
472
472
  } else {
473
- this.outletService!.updateCharacteristic(this.platform.Characteristic.On, e);
473
+ this.outletService?.updateCharacteristic(this.platform.Characteristic.On, e);
474
474
  }
475
475
  if (this.device.ble) {
476
476
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
@@ -89,7 +89,7 @@ export class Contact {
89
89
  // see https://developers.homebridge.io/#/service/MotionSensor
90
90
 
91
91
  // Motion Sensor Service
92
- if (this.device.contact?.hide_motionsensor) {
92
+ if (device.contact?.hide_motionsensor) {
93
93
  this.platform.device(`Contact Sensor: ${accessory.displayName} Removing Motion Sensor Service`);
94
94
  this.motionService = this.accessory.getService(this.platform.Service.MotionSensor);
95
95
  accessory.removeService(this.motionService!);
@@ -106,7 +106,7 @@ export class Contact {
106
106
  }
107
107
 
108
108
  // Light Sensor Service
109
- if (this.device.contact?.hide_lightsensor) {
109
+ if (device.contact?.hide_lightsensor) {
110
110
  this.platform.device(`Contact Sensor: ${accessory.displayName} Removing Light Sensor Service`);
111
111
  this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
112
112
  accessory.removeService(this.lightSensorService!);
@@ -328,7 +328,7 @@ export class Contact {
328
328
  if (this.MotionDetected === undefined) {
329
329
  this.platform.debug(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
330
330
  } else {
331
- this.motionService!.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
331
+ this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
332
332
  this.platform.device(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
333
333
  }
334
334
  }
@@ -336,7 +336,7 @@ export class Contact {
336
336
  if (this.CurrentAmbientLightLevel === undefined) {
337
337
  this.platform.debug(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
338
338
  } else {
339
- this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
339
+ this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
340
340
  this.platform.device(`Contact Sensor: ${this.accessory.displayName}`
341
341
  + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
342
342
  }
@@ -360,10 +360,10 @@ export class Contact {
360
360
  public apiError(e: any) {
361
361
  this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
362
362
  if (!this.device.contact?.hide_motionsensor) {
363
- this.motionService!.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
363
+ this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
364
364
  }
365
365
  if (!this.device.contact?.hide_lightsensor) {
366
- this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
366
+ this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
367
367
  }
368
368
  if (this.device.ble) {
369
369
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
@@ -123,7 +123,7 @@ export class Curtain {
123
123
  .onSet(this.TargetPositionSet.bind(this));
124
124
 
125
125
  // Light Sensor Service
126
- if (this.device.curtain?.hide_lightsensor) {
126
+ if (device.curtain?.hide_lightsensor) {
127
127
  this.platform.device(`Curtain: ${accessory.displayName} Removing Light Sensor Service`);
128
128
  this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
129
129
  accessory.removeService(this.lightSensorService!);
@@ -373,14 +373,16 @@ export class Curtain {
373
373
  + ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
374
374
 
375
375
  if (!this.device.curtain?.hide_lightsensor) {
376
+ this.set_minLux = this.minLux();
377
+ this.set_maxLux = this.maxLux();
376
378
  // Brightness
377
379
  switch (this.deviceStatus.body.brightness) {
378
380
  case 'dim':
379
- this.CurrentAmbientLightLevel = 0.0001;
381
+ this.CurrentAmbientLightLevel = this.set_minLux;
380
382
  break;
381
383
  case 'bright':
382
384
  default:
383
- this.CurrentAmbientLightLevel = 100000;
385
+ this.CurrentAmbientLightLevel = this.set_maxLux;
384
386
  }
385
387
  this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
386
388
  }
@@ -573,7 +575,7 @@ export class Curtain {
573
575
  if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
574
576
  this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
575
577
  } else {
576
- this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
578
+ this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
577
579
  this.platform.device(`Curtain: ${this.accessory.displayName}`
578
580
  + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
579
581
  }
@@ -599,11 +601,11 @@ export class Curtain {
599
601
  this.service.updateCharacteristic(this.platform.Characteristic.PositionState, e);
600
602
  this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
601
603
  if (!this.device.curtain?.hide_lightsensor) {
602
- this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
604
+ this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
603
605
  }
604
606
  if (this.device.ble) {
605
- this.batteryService!.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
606
- this.batteryService!.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
607
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
608
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
607
609
  }
608
610
  }
609
611
 
@@ -595,7 +595,7 @@ export class Humidifier {
595
595
  if (this.CurrentTemperature === undefined) {
596
596
  this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
597
597
  } else {
598
- this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
598
+ this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
599
599
  this.platform.device(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
600
600
  }
601
601
  }
@@ -611,7 +611,7 @@ export class Humidifier {
611
611
  this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
612
612
  this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
613
613
  if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
614
- this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
614
+ this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
615
615
  }
616
616
  }
617
617
 
@@ -12,7 +12,6 @@ export class Plug {
12
12
 
13
13
  // Characteristic Values
14
14
  On!: CharacteristicValue;
15
- OutletInUse!: CharacteristicValue;
16
15
 
17
16
  // OpenAPI Others
18
17
  deviceStatus!: deviceStatusResponse;
@@ -32,7 +31,6 @@ export class Plug {
32
31
  ) {
33
32
  // default placeholders
34
33
  this.On = false;
35
- this.OutletInUse = true;
36
34
 
37
35
  // this is subject we use to track when we need to POST changes to the SwitchBot API
38
36
  this.doPlugUpdate = new Subject();
@@ -68,8 +66,6 @@ export class Plug {
68
66
  // create handlers for required characteristics
69
67
  this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
70
68
 
71
- this.service.setCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse || true);
72
-
73
69
  // Update Homekit
74
70
  this.updateHomeKitCharacteristics();
75
71
 
@@ -173,17 +169,10 @@ export class Plug {
173
169
  this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
174
170
  this.platform.device(`Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
175
171
  }
176
- if (this.OutletInUse === undefined) {
177
- this.platform.debug(`Plug: ${this.accessory.displayName} OutletInUse: ${this.OutletInUse}`);
178
- } else {
179
- this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse);
180
- this.platform.device(`Plug: ${this.accessory.displayName} updateCharacteristic OutletInUse: ${this.OutletInUse}`);
181
- }
182
172
  }
183
173
 
184
174
  public apiError(e: any) {
185
175
  this.service.updateCharacteristic(this.platform.Characteristic.On, e);
186
- this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, e);
187
176
  }
188
177
 
189
178
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
@@ -14,18 +14,15 @@ export class AirConditioner {
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
17
- ARActive!: CharacteristicValue;
18
17
  RotationSpeed!: CharacteristicValue;
19
- CurrentARTemp!: CharacteristicValue;
20
- CurrentARMode!: CharacteristicValue;
21
18
  LastTemperature!: CharacteristicValue;
22
- CurrentARFanSpeed!: CharacteristicValue;
23
19
  CurrentTemperature!: CharacteristicValue;
24
20
  TargetHeaterCoolerState?: CharacteristicValue;
25
21
  CurrentHeaterCoolerState!: CharacteristicValue;
26
22
  HeatingThresholdTemperature?: CharacteristicValue;
27
23
 
28
24
  // Others
25
+ state!: string;
29
26
  Busy: any;
30
27
  Timeout: any = null;
31
28
  CurrentMode!: number;
@@ -158,8 +155,10 @@ export class AirConditioner {
158
155
 
159
156
  if (value === this.platform.Characteristic.Active.INACTIVE) {
160
157
  this.pushAirConditionerOffChanges();
158
+ this.platform.device(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
161
159
  } else {
162
160
  this.pushAirConditionerOnChanges();
161
+ this.platform.device(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
163
162
  }
164
163
  this.Active = value;
165
164
  }
@@ -168,48 +167,47 @@ export class AirConditioner {
168
167
  if (this.Active === undefined) {
169
168
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
170
169
  } else {
171
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
170
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
172
171
  this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
173
172
  }
174
173
  if (this.RotationSpeed === undefined) {
175
174
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
176
175
  } else {
177
- this.service!.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
176
+ this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
178
177
  this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
179
178
  }
180
179
  if (this.CurrentTemperature === undefined) {
181
180
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
182
181
  } else {
183
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.CurrentTemperature);
182
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
184
183
  this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
185
184
  }
186
185
  if (this.TargetHeaterCoolerState === undefined) {
187
186
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
188
187
  } else {
189
- this.service!.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
188
+ this.service?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
190
189
  this.platform.device(`Air Conditioner: ${this.accessory.displayName}`
191
190
  + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
192
191
  }
193
192
  if (this.CurrentHeaterCoolerState === undefined) {
194
193
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
195
194
  } else {
196
- this.service!.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
195
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
197
196
  this.platform.device(`Air Conditioner: ${this.accessory.displayName}`
198
197
  + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
199
198
  }
200
199
  if (this.HeatingThresholdTemperature === undefined) {
201
200
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
202
201
  } else {
203
- this.service!.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
202
+ this.service?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
204
203
  this.platform.device(`Air Conditioner: ${this.accessory.displayName}`
205
204
  + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
206
205
  }
207
206
  }
208
207
 
209
208
  private CurrentTemperatureGet(value: CharacteristicValue) {
210
- this.platform.debug('Trigger Get CurrentTemperture');
211
-
212
209
  value = Number(this.CurrentTemperature) || 24;
210
+ this.platform.debug(`Air Conditioner: ${this.accessory.displayName} Trigger Get CurrentTemperature: ${value}` );
213
211
 
214
212
  this.service
215
213
  .getCharacteristic(this.platform.Characteristic.CurrentTemperature)
@@ -236,7 +234,7 @@ export class AirConditioner {
236
234
  }
237
235
 
238
236
  private CurrentHeaterCoolerStateGet() {
239
- if (this.Active === 1) {
237
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
240
238
  if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
241
239
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
242
240
  } else {
@@ -273,7 +271,7 @@ export class AirConditioner {
273
271
  * AirConditioner: "command" "highSpeed" "default" = fan speed to high
274
272
  */
275
273
  async pushAirConditionerOnChanges() {
276
- if (this.Active !== 1) {
274
+ if (this.Active !== this.platform.Characteristic.Active.ACTIVE) {
277
275
  const payload = {
278
276
  commandType: 'command',
279
277
  parameter: 'default',
@@ -284,7 +282,7 @@ export class AirConditioner {
284
282
  }
285
283
 
286
284
  async pushAirConditionerOffChanges() {
287
- if (this.Active !== 0) {
285
+ if (this.Active !== this.platform.Characteristic.Active.INACTIVE) {
288
286
  const payload = {
289
287
  commandType: 'command',
290
288
  parameter: 'default',
@@ -311,14 +309,25 @@ export class AirConditioner {
311
309
  command: 'setAll',
312
310
  } as any;
313
311
 
314
- this.CurrentARTemp = this.CurrentTemperature || 24;
315
- this.CurrentARMode = this.CurrentMode || 1;
316
- this.CurrentARFanSpeed = this.CurrentFanSpeed || 1;
317
- this.ARActive = this.Active === 1 ? 'on' : 'off';
318
- payload.parameter = `${this.CurrentARTemp},${this.CurrentARMode},${this.CurrentARFanSpeed},${this.ARActive}`;
312
+ if (this.CurrentTemperature === undefined) {
313
+ this.CurrentTemperature = 24;
314
+ }
315
+ if (this.CurrentMode === undefined) {
316
+ this.CurrentMode = 1;
317
+ }
318
+ if (this.CurrentFanSpeed === undefined) {
319
+ this.CurrentFanSpeed = 1;
320
+ }
321
+ this.Active = this.platform.Characteristic.Active.ACTIVE;
322
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
323
+ this.state = 'on';
324
+ } else {
325
+ this.state = 'off';
326
+ }
327
+ payload.parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
319
328
 
320
329
 
321
- if (this.Active === 1) {
330
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
322
331
  if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
323
332
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
324
333
  } else {
@@ -334,11 +343,11 @@ export class AirConditioner {
334
343
  public async pushChanges(payload: payload) {
335
344
  try {
336
345
  this.platform.log.info(`Air Conditioner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
337
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
346
+ + ` parameter: [${payload.parameter}], commandType: ${payload.commandType}`);
338
347
 
339
348
  // Make the API request
340
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
341
- this.platform.debug(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${push.data}`);
349
+ const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
350
+ this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
342
351
  this.statusCode(push);
343
352
  this.updateHomeKitCharacteristics();
344
353
  } catch (e: any) {
@@ -87,20 +87,20 @@ export class AirPurifier {
87
87
  if (this.Active === undefined) {
88
88
  this.platform.debug(`Air Purifier: ${this.accessory.displayName} Active: ${this.Active}`);
89
89
  } else {
90
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
90
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
91
91
  this.platform.device(`Air Purifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
92
92
  }
93
93
  if (this.CurrentAirPurifierState === undefined) {
94
94
  this.platform.debug(`Air Purifier: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
95
95
  } else {
96
- this.service!.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
96
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
97
97
  this.platform.device(`Air Purifier: ${this.accessory.displayName}`
98
98
  + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
99
99
  }
100
100
  if (this.CurrentHeaterCoolerState === undefined) {
101
101
  this.platform.debug(`Air Purifier: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
102
102
  } else {
103
- this.service!.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
103
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
104
104
  this.platform.device(`Air Purifier: ${this.accessory.displayName}`
105
105
  + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
106
106
  }
@@ -63,7 +63,7 @@ export class Camera {
63
63
  if (this.On === undefined) {
64
64
  this.platform.debug(`Camera: ${this.accessory.displayName} On: ${this.On}`);
65
65
  } else {
66
- this.service!.updateCharacteristic(this.platform.Characteristic.On, this.On);
66
+ this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
67
67
  this.platform.device(`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
68
68
  }
69
69
  }
@@ -126,19 +126,19 @@ export class Fan {
126
126
  if (this.Active === undefined) {
127
127
  this.platform.debug(`Fan: ${this.accessory.displayName} Active: ${this.Active}`);
128
128
  } else {
129
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
129
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
130
130
  this.platform.device(`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
131
131
  }
132
132
  if (this.SwingMode === undefined) {
133
133
  this.platform.debug(`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
134
134
  } else {
135
- this.service!.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
135
+ this.service?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
136
136
  this.platform.device(`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
137
137
  }
138
138
  if (this.RotationSpeed === undefined) {
139
139
  this.platform.debug(`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
140
140
  } else {
141
- this.service!.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
141
+ this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
142
142
  this.platform.device(`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
143
143
  }
144
144
  }
@@ -78,7 +78,7 @@ export class Light {
78
78
  if (this.On === undefined) {
79
79
  this.platform.debug(`Light: ${this.accessory.displayName} On: ${this.On}`);
80
80
  } else {
81
- this.service!.updateCharacteristic(this.platform.Characteristic.On, this.On);
81
+ this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
82
82
  this.platform.device(`Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
83
83
  }
84
84
  }
@@ -60,7 +60,7 @@ export class Others {
60
60
  if (this.Active === undefined) {
61
61
  this.platform.debug(`Other: ${this.accessory.displayName} Active: ${this.Active}`);
62
62
  } else {
63
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
63
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
64
64
  this.platform.device(`Other: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
65
65
  }
66
66
  }
@@ -175,6 +175,6 @@ export class Others {
175
175
  }
176
176
 
177
177
  public apiError(e: any) {
178
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, e);
178
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, e);
179
179
  }
180
180
  }
@@ -214,13 +214,13 @@ export class TV {
214
214
  if (this.Active === undefined) {
215
215
  this.platform.debug(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
216
216
  } else {
217
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
217
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
218
218
  this.platform.device(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
219
219
  }
220
220
  if (this.ActiveIdentifier === undefined) {
221
221
  this.platform.debug(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
222
222
  } else {
223
- this.service!.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
223
+ this.service?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
224
224
  this.platform.device(`${this.device.remoteType}: ${this.accessory.displayName}`
225
225
  + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
226
226
  }
@@ -63,7 +63,7 @@ export class VacuumCleaner {
63
63
  if (this.On === undefined) {
64
64
  this.platform.debug(`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`);
65
65
  } else {
66
- this.service!.updateCharacteristic(this.platform.Characteristic.On, this.On);
66
+ this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
67
67
  this.platform.device(`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
68
68
  }
69
69
  }
@@ -77,7 +77,7 @@ export class WaterHeater {
77
77
  if (this.Active === undefined) {
78
78
  this.platform.debug(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
79
79
  } else {
80
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
80
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
81
81
  this.platform.device(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
82
82
  }
83
83
  }
package/src/platform.ts CHANGED
@@ -1451,6 +1451,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1451
1451
  device(...log: any[]) {
1452
1452
  if (this.config.options!.debug === 'device') {
1453
1453
  this.log.warn('[DEVICE]', String(...log));
1454
+ } else if (this.config.options!.debug === 'debug') {
1455
+ this.log.info('[DEBUG]', String(...log));
1454
1456
  } else {
1455
1457
  this.log.debug(String(...log));
1456
1458
  }