@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-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 (154) hide show
  1. package/.github/npm-version-script.cjs +81 -0
  2. package/.github/workflows/dependabot.yml +10 -11
  3. package/CHANGELOG.md +11 -2
  4. package/LICENSE +1 -1
  5. package/config.schema.json +1 -0
  6. package/dist/device/blindtilt.d.ts +9 -5
  7. package/dist/device/blindtilt.d.ts.map +1 -1
  8. package/dist/device/blindtilt.js +151 -91
  9. package/dist/device/blindtilt.js.map +1 -1
  10. package/dist/device/bot.d.ts +9 -5
  11. package/dist/device/bot.d.ts.map +1 -1
  12. package/dist/device/bot.js +234 -184
  13. package/dist/device/bot.js.map +1 -1
  14. package/dist/device/ceilinglight.d.ts +9 -5
  15. package/dist/device/ceilinglight.d.ts.map +1 -1
  16. package/dist/device/ceilinglight.js +110 -64
  17. package/dist/device/ceilinglight.js.map +1 -1
  18. package/dist/device/colorbulb.d.ts +9 -5
  19. package/dist/device/colorbulb.d.ts.map +1 -1
  20. package/dist/device/colorbulb.js +121 -69
  21. package/dist/device/colorbulb.js.map +1 -1
  22. package/dist/device/contact.d.ts +9 -5
  23. package/dist/device/contact.d.ts.map +1 -1
  24. package/dist/device/contact.js +111 -66
  25. package/dist/device/contact.js.map +1 -1
  26. package/dist/device/curtain.d.ts +9 -5
  27. package/dist/device/curtain.d.ts.map +1 -1
  28. package/dist/device/curtain.js +164 -107
  29. package/dist/device/curtain.js.map +1 -1
  30. package/dist/device/hub.d.ts +9 -5
  31. package/dist/device/hub.d.ts.map +1 -1
  32. package/dist/device/hub.js +87 -51
  33. package/dist/device/hub.js.map +1 -1
  34. package/dist/device/humidifier.d.ts +9 -5
  35. package/dist/device/humidifier.d.ts.map +1 -1
  36. package/dist/device/humidifier.js +133 -90
  37. package/dist/device/humidifier.js.map +1 -1
  38. package/dist/device/iosensor.d.ts +9 -5
  39. package/dist/device/iosensor.d.ts.map +1 -1
  40. package/dist/device/iosensor.js +108 -66
  41. package/dist/device/iosensor.js.map +1 -1
  42. package/dist/device/lightstrip.d.ts +9 -5
  43. package/dist/device/lightstrip.d.ts.map +1 -1
  44. package/dist/device/lightstrip.js +110 -65
  45. package/dist/device/lightstrip.js.map +1 -1
  46. package/dist/device/lock.d.ts +10 -6
  47. package/dist/device/lock.d.ts.map +1 -1
  48. package/dist/device/lock.js +125 -84
  49. package/dist/device/lock.js.map +1 -1
  50. package/dist/device/meter.d.ts +9 -5
  51. package/dist/device/meter.d.ts.map +1 -1
  52. package/dist/device/meter.js +102 -63
  53. package/dist/device/meter.js.map +1 -1
  54. package/dist/device/meterplus.d.ts +9 -5
  55. package/dist/device/meterplus.d.ts.map +1 -1
  56. package/dist/device/meterplus.js +102 -63
  57. package/dist/device/meterplus.js.map +1 -1
  58. package/dist/device/motion.d.ts +9 -5
  59. package/dist/device/motion.d.ts.map +1 -1
  60. package/dist/device/motion.js +95 -54
  61. package/dist/device/motion.js.map +1 -1
  62. package/dist/device/plug.d.ts +9 -5
  63. package/dist/device/plug.d.ts.map +1 -1
  64. package/dist/device/plug.js +68 -40
  65. package/dist/device/plug.js.map +1 -1
  66. package/dist/device/robotvacuumcleaner.d.ts +9 -5
  67. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  68. package/dist/device/robotvacuumcleaner.js +86 -52
  69. package/dist/device/robotvacuumcleaner.js.map +1 -1
  70. package/dist/homebridge-ui/server.d.ts +2 -0
  71. package/dist/homebridge-ui/server.d.ts.map +1 -0
  72. package/dist/homebridge-ui/server.js +44 -0
  73. package/dist/homebridge-ui/server.js.map +1 -0
  74. package/dist/index.d.ts +1 -4
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +9 -5
  77. package/dist/index.js.map +1 -1
  78. package/dist/irdevice/airconditioner.d.ts +8 -4
  79. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  80. package/dist/irdevice/airconditioner.js +105 -71
  81. package/dist/irdevice/airconditioner.js.map +1 -1
  82. package/dist/irdevice/airpurifier.d.ts +8 -4
  83. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  84. package/dist/irdevice/airpurifier.js +78 -46
  85. package/dist/irdevice/airpurifier.js.map +1 -1
  86. package/dist/irdevice/camera.d.ts +8 -4
  87. package/dist/irdevice/camera.d.ts.map +1 -1
  88. package/dist/irdevice/camera.js +41 -25
  89. package/dist/irdevice/camera.js.map +1 -1
  90. package/dist/irdevice/fan.d.ts +8 -4
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +62 -39
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/light.d.ts +8 -4
  95. package/dist/irdevice/light.d.ts.map +1 -1
  96. package/dist/irdevice/light.js +67 -45
  97. package/dist/irdevice/light.js.map +1 -1
  98. package/dist/irdevice/other.d.ts +8 -4
  99. package/dist/irdevice/other.d.ts.map +1 -1
  100. package/dist/irdevice/other.js +176 -150
  101. package/dist/irdevice/other.js.map +1 -1
  102. package/dist/irdevice/tv.d.ts +8 -4
  103. package/dist/irdevice/tv.d.ts.map +1 -1
  104. package/dist/irdevice/tv.js +81 -62
  105. package/dist/irdevice/tv.js.map +1 -1
  106. package/dist/irdevice/vacuumcleaner.d.ts +8 -4
  107. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  108. package/dist/irdevice/vacuumcleaner.js +41 -25
  109. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  110. package/dist/irdevice/waterheater.d.ts +8 -4
  111. package/dist/irdevice/waterheater.d.ts.map +1 -1
  112. package/dist/irdevice/waterheater.js +48 -32
  113. package/dist/irdevice/waterheater.js.map +1 -1
  114. package/dist/platform.d.ts +8 -9
  115. package/dist/platform.d.ts.map +1 -1
  116. package/dist/platform.js +147 -162
  117. package/dist/platform.js.map +1 -1
  118. package/dist/settings.js +7 -14
  119. package/dist/settings.js.map +1 -1
  120. package/dist/utils.js +1 -5
  121. package/dist/utils.js.map +1 -1
  122. package/package.json +28 -16
  123. package/src/device/blindtilt.ts +80 -69
  124. package/src/device/bot.ts +189 -178
  125. package/src/device/ceilinglight.ts +55 -42
  126. package/src/device/colorbulb.ts +51 -38
  127. package/src/device/contact.ts +69 -58
  128. package/src/device/curtain.ts +94 -83
  129. package/src/device/hub.ts +54 -43
  130. package/src/device/humidifier.ts +86 -75
  131. package/src/device/iosensor.ts +63 -52
  132. package/src/device/lightstrip.ts +54 -41
  133. package/src/device/lock.ts +89 -79
  134. package/src/device/meter.ts +59 -48
  135. package/src/device/meterplus.ts +63 -52
  136. package/src/device/motion.ts +56 -45
  137. package/src/device/plug.ts +36 -25
  138. package/src/device/robotvacuumcleaner.ts +47 -36
  139. package/src/homebridge-ui/public/index.html +240 -0
  140. package/src/homebridge-ui/server.ts +48 -0
  141. package/src/index.ts +10 -7
  142. package/src/irdevice/airconditioner.ts +70 -62
  143. package/src/irdevice/airpurifier.ts +47 -39
  144. package/src/irdevice/camera.ts +27 -19
  145. package/src/irdevice/fan.ts +41 -33
  146. package/src/irdevice/light.ts +47 -39
  147. package/src/irdevice/other.ts +163 -155
  148. package/src/irdevice/tv.ts +65 -57
  149. package/src/irdevice/vacuumcleaner.ts +27 -19
  150. package/src/irdevice/waterheater.ts +34 -26
  151. package/src/platform.ts +35 -21
  152. package/tsconfig.json +11 -13
  153. package/homebridge-ui/server.js +0 -50
  154. /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
@@ -1,7 +1,7 @@
1
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
+ import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
2
2
  import { request } from 'undici';
3
3
  import { SwitchBotPlatform } from '../platform';
4
- import { Devices, irDevicesConfig, irdevice } from '../settings';
4
+ import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -9,6 +9,10 @@ import { Devices, irDevicesConfig, irdevice } from '../settings';
9
9
  * Each accessory may expose multiple services of different service types.
10
10
  */
11
11
  export class Camera {
12
+ public readonly api: API;
13
+ public readonly log: Logging;
14
+ public readonly config!: SwitchBotPlatformConfig;
15
+ protected readonly hap: HAP;
12
16
  // Services
13
17
  switchService!: Service;
14
18
 
@@ -26,34 +30,38 @@ export class Camera {
26
30
  private accessory: PlatformAccessory,
27
31
  public device: irdevice & irDevicesConfig,
28
32
  ) {
33
+ this.api = this.platform.api;
34
+ this.log = this.platform.log;
35
+ this.config = this.platform.config;
36
+ this.hap = this.api.hap;
29
37
  // default placeholders
30
- this.logs(device);
38
+ this.deviceLogs(device);
31
39
  this.context();
32
40
  this.disablePushOnChanges(device);
33
41
  this.disablePushOffChanges(device);
34
- this.config(device);
42
+ this.deviceConfig(device);
35
43
 
36
44
  // set accessory information
37
45
  accessory
38
- .getService(this.platform.Service.AccessoryInformation)!
39
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
- .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
42
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
46
+ .getService(this.hap.Service.AccessoryInformation)!
47
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
48
+ .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
49
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
50
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
43
51
 
44
52
  // get the Television service if it exists, otherwise create a new Television service
45
53
  // you can create multiple services for each accessory
46
54
  const switchService = `${accessory.displayName} Camera`;
47
- (this.switchService = accessory.getService(this.platform.Service.Switch)
48
- || accessory.addService(this.platform.Service.Switch)), switchService;
55
+ (this.switchService = accessory.getService(this.hap.Service.Switch)
56
+ || accessory.addService(this.hap.Service.Switch)), switchService;
49
57
 
50
- this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
51
- if (!this.switchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
52
- this.switchService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
58
+ this.switchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
59
+ if (!this.switchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
60
+ this.switchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
53
61
  }
54
62
 
55
63
  // handle on / off events using the On characteristic
56
- this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
64
+ this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
57
65
  }
58
66
 
59
67
  async OnSet(value: CharacteristicValue): Promise<void> {
@@ -153,7 +161,7 @@ export class Camera {
153
161
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
154
162
  } else {
155
163
  this.accessory.context.On = this.On;
156
- this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
164
+ this.switchService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
157
165
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
158
166
  }
159
167
  }
@@ -245,7 +253,7 @@ export class Camera {
245
253
  }
246
254
 
247
255
  async apiError(e: any): Promise<void> {
248
- this.switchService.updateCharacteristic(this.platform.Characteristic.On, e);
256
+ this.switchService.updateCharacteristic(this.hap.Characteristic.On, e);
249
257
  }
250
258
 
251
259
  async context() {
@@ -260,7 +268,7 @@ export class Camera {
260
268
  }
261
269
  }
262
270
 
263
- async config(device: irdevice & irDevicesConfig): Promise<void> {
271
+ async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
264
272
  let config = {};
265
273
  if (device.ircam) {
266
274
  config = device.ircam;
@@ -294,7 +302,7 @@ export class Camera {
294
302
  }
295
303
  }
296
304
 
297
- async logs(device: irdevice & irDevicesConfig): Promise<void> {
305
+ async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
298
306
  if (this.platform.debugMode) {
299
307
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
300
308
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -1,7 +1,7 @@
1
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
+ import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
2
2
  import { request } from 'undici';
3
3
  import { SwitchBotPlatform } from '../platform';
4
- import { Devices, irDevicesConfig, irdevice } from '../settings';
4
+ import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -9,6 +9,10 @@ import { Devices, irDevicesConfig, irdevice } from '../settings';
9
9
  * Each accessory may expose multiple services of different service types.
10
10
  */
11
11
  export class Fan {
12
+ public readonly api: API;
13
+ public readonly log: Logging;
14
+ public readonly config!: SwitchBotPlatformConfig;
15
+ protected readonly hap: HAP;
12
16
  // Services
13
17
  fanService!: Service;
14
18
 
@@ -33,34 +37,38 @@ export class Fan {
33
37
  private accessory: PlatformAccessory,
34
38
  public device: irdevice & irDevicesConfig,
35
39
  ) {
40
+ this.api = this.platform.api;
41
+ this.log = this.platform.log;
42
+ this.config = this.platform.config;
43
+ this.hap = this.api.hap;
36
44
  // default placeholders
37
- this.logs(device);
45
+ this.deviceLogs(device);
38
46
  this.context();
39
47
  this.disablePushOnChanges(device);
40
48
  this.disablePushOffChanges(device);
41
- this.config(device);
49
+ this.deviceConfig(device);
42
50
 
43
51
  // set accessory information
44
52
  accessory
45
- .getService(this.platform.Service.AccessoryInformation)!
46
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
47
- .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
48
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
49
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
53
+ .getService(this.hap.Service.AccessoryInformation)!
54
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
55
+ .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
56
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
57
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
50
58
 
51
59
  // get the Television service if it exists, otherwise create a new Television service
52
60
  // you can create multiple services for each accessory
53
61
  const fanService = `${accessory.displayName} Fan`;
54
- (this.fanService = accessory.getService(this.platform.Service.Fanv2)
55
- || accessory.addService(this.platform.Service.Fanv2)), fanService;
62
+ (this.fanService = accessory.getService(this.hap.Service.Fanv2)
63
+ || accessory.addService(this.hap.Service.Fanv2)), fanService;
56
64
 
57
- this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
58
- if (!this.fanService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
59
- this.fanService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
65
+ this.fanService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
66
+ if (!this.fanService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
67
+ this.fanService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
60
68
  }
61
69
 
62
70
  // handle on / off events using the Active characteristic
63
- this.fanService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
71
+ this.fanService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
64
72
 
65
73
  if (device.irfan?.rotation_speed) {
66
74
  if (device.irfan?.set_minStep) {
@@ -80,15 +88,15 @@ export class Fan {
80
88
  }
81
89
  // handle Roation Speed events using the RotationSpeed characteristic
82
90
  this.fanService
83
- .getCharacteristic(this.platform.Characteristic.RotationSpeed)
91
+ .getCharacteristic(this.hap.Characteristic.RotationSpeed)
84
92
  .setProps({
85
93
  minStep: this.minStep,
86
94
  minValue: this.minValue,
87
95
  maxValue: this.maxValue,
88
96
  })
89
97
  .onSet(this.RotationSpeedSet.bind(this));
90
- } else if (this.fanService.testCharacteristic(this.platform.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
91
- const characteristic = this.fanService.getCharacteristic(this.platform.Characteristic.RotationSpeed);
98
+ } else if (this.fanService.testCharacteristic(this.hap.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
99
+ const characteristic = this.fanService.getCharacteristic(this.hap.Characteristic.RotationSpeed);
92
100
  this.fanService.removeCharacteristic(characteristic);
93
101
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
94
102
  } else {
@@ -101,9 +109,9 @@ export class Fan {
101
109
 
102
110
  if (device.irfan?.swing_mode) {
103
111
  // handle Osolcation events using the SwingMode characteristic
104
- this.fanService.getCharacteristic(this.platform.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
105
- } else if (this.fanService.testCharacteristic(this.platform.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
106
- const characteristic = this.fanService.getCharacteristic(this.platform.Characteristic.SwingMode);
112
+ this.fanService.getCharacteristic(this.hap.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
113
+ } else if (this.fanService.testCharacteristic(this.hap.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
114
+ const characteristic = this.fanService.getCharacteristic(this.hap.Characteristic.SwingMode);
107
115
  this.fanService.removeCharacteristic(characteristic);
108
116
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
109
117
  } else {
@@ -148,7 +156,7 @@ export class Fan {
148
156
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
149
157
 
150
158
  this.Active = value;
151
- if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
159
+ if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
152
160
  this.pushFanOnChanges();
153
161
  } else {
154
162
  this.pushFanOffChanges();
@@ -168,7 +176,7 @@ export class Fan {
168
176
  this.debugLog(
169
177
  `${this.device.remoteType}: ${this.accessory.displayName} pushFanOnChanges Active: ${this.Active},` + ` disablePushOn: ${this.disablePushOn}`,
170
178
  );
171
- if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
179
+ if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
172
180
  const commandType: string = await this.commandType();
173
181
  const command: string = await this.commandOn();
174
182
  const bodyChange = JSON.stringify({
@@ -185,7 +193,7 @@ export class Fan {
185
193
  `${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges Active: ${this.Active},` +
186
194
  ` disablePushOff: ${this.disablePushOff}`,
187
195
  );
188
- if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
196
+ if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
189
197
  const commandType: string = await this.commandType();
190
198
  const command: string = await this.commandOff();
191
199
  const bodyChange = JSON.stringify({
@@ -269,21 +277,21 @@ export class Fan {
269
277
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
270
278
  } else {
271
279
  this.accessory.context.Active = this.Active;
272
- this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
280
+ this.fanService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
273
281
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
274
282
  }
275
283
  if (this.SwingMode === undefined) {
276
284
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
277
285
  } else {
278
286
  this.accessory.context.SwingMode = this.SwingMode;
279
- this.fanService?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
287
+ this.fanService?.updateCharacteristic(this.hap.Characteristic.SwingMode, this.SwingMode);
280
288
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
281
289
  }
282
290
  if (this.RotationSpeed === undefined) {
283
291
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
284
292
  } else {
285
293
  this.accessory.context.RotationSpeed = this.RotationSpeed;
286
- this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
294
+ this.fanService?.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.RotationSpeed);
287
295
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
288
296
  }
289
297
  }
@@ -375,14 +383,14 @@ export class Fan {
375
383
  }
376
384
 
377
385
  async apiError(e: any): Promise<void> {
378
- this.fanService.updateCharacteristic(this.platform.Characteristic.Active, e);
379
- this.fanService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
380
- this.fanService.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
386
+ this.fanService.updateCharacteristic(this.hap.Characteristic.Active, e);
387
+ this.fanService.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
388
+ this.fanService.updateCharacteristic(this.hap.Characteristic.SwingMode, e);
381
389
  }
382
390
 
383
391
  async context() {
384
392
  if (this.Active === undefined) {
385
- this.Active = this.platform.Characteristic.Active.INACTIVE;
393
+ this.Active = this.hap.Characteristic.Active.INACTIVE;
386
394
  } else {
387
395
  this.Active = this.accessory.context.Active;
388
396
  }
@@ -392,7 +400,7 @@ export class Fan {
392
400
  }
393
401
  }
394
402
 
395
- async config(device: irdevice & irDevicesConfig): Promise<void> {
403
+ async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
396
404
  let config = {};
397
405
  if (device.irfan) {
398
406
  config = device.irfan;
@@ -426,7 +434,7 @@ export class Fan {
426
434
  }
427
435
  }
428
436
 
429
- async logs(device: irdevice & irDevicesConfig): Promise<void> {
437
+ async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
430
438
  if (this.platform.debugMode) {
431
439
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
432
440
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -1,7 +1,7 @@
1
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
+ import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
2
2
  import { request } from 'undici';
3
3
  import { SwitchBotPlatform } from '../platform';
4
- import { Devices, irDevicesConfig, irdevice } from '../settings';
4
+ import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -9,6 +9,10 @@ import { Devices, irDevicesConfig, irdevice } from '../settings';
9
9
  * Each accessory may expose multiple services of different service types.
10
10
  */
11
11
  export class Light {
12
+ public readonly api: API;
13
+ public readonly log: Logging;
14
+ public readonly config!: SwitchBotPlatformConfig;
15
+ protected readonly hap: HAP;
12
16
  // Services
13
17
  lightBulbService?: Service;
14
18
  ProgrammableSwitchServiceOn?: Service;
@@ -32,50 +36,54 @@ export class Light {
32
36
  private accessory: PlatformAccessory,
33
37
  public device: irdevice & irDevicesConfig,
34
38
  ) {
39
+ this.api = this.platform.api;
40
+ this.log = this.platform.log;
41
+ this.config = this.platform.config;
42
+ this.hap = this.api.hap;
35
43
  // default placeholders
36
- this.logs(device);
44
+ this.deviceLogs(device);
37
45
  this.context();
38
46
  this.disablePushOnChanges(device);
39
47
  this.disablePushOffChanges(device);
40
- this.config(device);
48
+ this.deviceConfig(device);
41
49
 
42
50
  // set accessory information
43
51
  accessory
44
- .getService(this.platform.Service.AccessoryInformation)!
45
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
46
- .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
47
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
48
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
52
+ .getService(this.hap.Service.AccessoryInformation)!
53
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
54
+ .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
55
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
56
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
49
57
 
50
58
  if (!device.irlight?.stateless) {
51
59
  // get the Light service if it exists, otherwise create a new Light service
52
60
  // you can create multiple services for each accessory
53
61
  const lightBulbService = `${accessory.displayName} ${device.remoteType}`;
54
- (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb)
55
- || accessory.addService(this.platform.Service.Lightbulb)), lightBulbService;
62
+ (this.lightBulbService = accessory.getService(this.hap.Service.Lightbulb)
63
+ || accessory.addService(this.hap.Service.Lightbulb)), lightBulbService;
56
64
 
57
65
 
58
- this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
59
- if (!this.lightBulbService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
60
- this.lightBulbService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
66
+ this.lightBulbService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
67
+ if (!this.lightBulbService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
68
+ this.lightBulbService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
61
69
  }
62
70
 
63
71
  // handle on / off events using the On characteristic
64
- this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
72
+ this.lightBulbService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
65
73
  } else {
66
74
 
67
75
  // create a new Stateful Programmable Switch On service
68
76
  const ProgrammableSwitchServiceOn = `${accessory.displayName} ${device.remoteType} On`;
69
- (this.ProgrammableSwitchServiceOn = accessory.getService(this.platform.Service.StatefulProgrammableSwitch)
70
- || accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), ProgrammableSwitchServiceOn;
77
+ (this.ProgrammableSwitchServiceOn = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
78
+ || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchServiceOn;
71
79
 
72
80
 
73
- this.ProgrammableSwitchServiceOn.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} On`);
74
- if (!this.ProgrammableSwitchServiceOn.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
75
- this.ProgrammableSwitchServiceOn.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} On`);
81
+ this.ProgrammableSwitchServiceOn.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} On`);
82
+ if (!this.ProgrammableSwitchServiceOn.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
83
+ this.ProgrammableSwitchServiceOn.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} On`);
76
84
  }
77
85
 
78
- this.ProgrammableSwitchServiceOn.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent).setProps({
86
+ this.ProgrammableSwitchServiceOn.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
79
87
  validValueRanges: [0, 0],
80
88
  minValue: 0,
81
89
  maxValue: 0,
@@ -85,23 +93,23 @@ export class Light {
85
93
  return this.ProgrammableSwitchEventOn!;
86
94
  });
87
95
 
88
- this.ProgrammableSwitchServiceOn.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
96
+ this.ProgrammableSwitchServiceOn.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
89
97
  .onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
90
98
 
91
99
 
92
100
 
93
101
  // create a new Stateful Programmable Switch Off service
94
102
  const ProgrammableSwitchServiceOff = `${accessory.displayName} ${device.remoteType} Off`;
95
- (this.ProgrammableSwitchServiceOff = accessory.getService(this.platform.Service.StatefulProgrammableSwitch)
96
- || accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), ProgrammableSwitchServiceOff;
103
+ (this.ProgrammableSwitchServiceOff = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
104
+ || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchServiceOff;
97
105
 
98
106
 
99
- this.ProgrammableSwitchServiceOff.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Off`);
100
- if (!this.ProgrammableSwitchServiceOff.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
101
- this.ProgrammableSwitchServiceOff.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Off`);
107
+ this.ProgrammableSwitchServiceOff.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Off`);
108
+ if (!this.ProgrammableSwitchServiceOff.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
109
+ this.ProgrammableSwitchServiceOff.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Off`);
102
110
  }
103
111
 
104
- this.ProgrammableSwitchServiceOff.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent).setProps({
112
+ this.ProgrammableSwitchServiceOff.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
105
113
  validValueRanges: [0, 0],
106
114
  minValue: 0,
107
115
  maxValue: 0,
@@ -111,7 +119,7 @@ export class Light {
111
119
  return this.ProgrammableSwitchEventOff!;
112
120
  });
113
121
 
114
- this.ProgrammableSwitchServiceOff.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
122
+ this.ProgrammableSwitchServiceOff.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
115
123
  .onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
116
124
  }
117
125
 
@@ -270,7 +278,7 @@ export class Light {
270
278
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
271
279
  } else {
272
280
  this.accessory.context.On = this.On;
273
- this.lightBulbService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
281
+ this.lightBulbService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
274
282
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
275
283
  }
276
284
  } else {
@@ -280,7 +288,7 @@ export class Light {
280
288
  + ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOutputStateOn}`);
281
289
  } else {
282
290
  this.accessory.context.ProgrammableSwitchOutputStateOn = this.ProgrammableSwitchOutputStateOn;
283
- this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState,
291
+ this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
284
292
  this.ProgrammableSwitchOutputStateOn);
285
293
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
286
294
  + ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOutputStateOn}`);
@@ -291,7 +299,7 @@ export class Light {
291
299
  + ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOutputStateOff}`);
292
300
  } else {
293
301
  this.accessory.context.ProgrammableSwitchOutputStateOff = this.ProgrammableSwitchOutputStateOff;
294
- this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState,
302
+ this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
295
303
  this.ProgrammableSwitchOutputStateOff);
296
304
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
297
305
  + ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOutputStateOff}`);
@@ -387,12 +395,12 @@ export class Light {
387
395
 
388
396
  async apiError(e: any): Promise<void> {
389
397
  if (this.device.irlight?.stateless) {
390
- this.lightBulbService?.updateCharacteristic(this.platform.Characteristic.On, e);
398
+ this.lightBulbService?.updateCharacteristic(this.hap.Characteristic.On, e);
391
399
  } else {
392
- this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, e);
393
- this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, e);
394
- this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, e);
395
- this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, e);
400
+ this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
401
+ this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
402
+ this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
403
+ this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
396
404
  }
397
405
  }
398
406
 
@@ -408,7 +416,7 @@ export class Light {
408
416
  }
409
417
  }
410
418
 
411
- async config(device: irdevice & irDevicesConfig): Promise<void> {
419
+ async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
412
420
  let config = {};
413
421
  if (device.irlight) {
414
422
  config = device.irlight;
@@ -442,7 +450,7 @@ export class Light {
442
450
  }
443
451
  }
444
452
 
445
- async logs(device: irdevice & irDevicesConfig): Promise<void> {
453
+ async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
446
454
  if (this.platform.debugMode) {
447
455
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
448
456
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);