@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
@@ -5,11 +5,15 @@ import { interval, Subject } from 'rxjs';
5
5
  import { connectAsync } from 'async-mqtt';
6
6
  import { SwitchBotPlatform } from '../platform';
7
7
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
8
- import { Service, PlatformAccessory, CharacteristicValue, CharacteristicChange } from 'homebridge';
9
- import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '../settings';
8
+ import { Service, PlatformAccessory, CharacteristicValue, CharacteristicChange, API, Logging, HAP } from 'homebridge';
9
+ import { device, devicesConfig, serviceData, deviceStatus, ad, Devices, SwitchBotPlatformConfig } from '../settings';
10
10
  import { hostname } from 'os';
11
11
 
12
12
  export class Curtain {
13
+ public readonly api: API;
14
+ public readonly log: Logging;
15
+ public readonly config!: SwitchBotPlatformConfig;
16
+ protected readonly hap: HAP;
13
17
  // Services
14
18
  batteryService: Service;
15
19
  lightSensorService?: Service;
@@ -70,8 +74,8 @@ export class Curtain {
70
74
  doCurtainUpdate!: Subject<void>;
71
75
 
72
76
  // Connection
73
- private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
74
- private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
77
+ private readonly OpenAPI: boolean;
78
+ private readonly BLE: boolean;
75
79
 
76
80
  // EVE history service handler
77
81
  historyService: any = null;
@@ -81,13 +85,20 @@ export class Curtain {
81
85
  private accessory: PlatformAccessory,
82
86
  public device: device & devicesConfig,
83
87
  ) {
88
+ this.api = this.platform.api;
89
+ this.log = this.platform.log;
90
+ this.config = this.platform.config;
91
+ this.hap = this.api.hap;
92
+ // Connection
93
+ this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
94
+ this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
84
95
  // default placeholders
85
- this.logs(device);
96
+ this.deviceLogs(device);
86
97
  this.refreshRate(device);
87
98
  this.scan(device);
88
99
  this.setupMqtt(device);
89
100
  this.context();
90
- this.config(device);
101
+ this.deviceConfig(device);
91
102
 
92
103
  // this is subject we use to track when we need to POST changes to the SwitchBot API
93
104
  this.doCurtainUpdate = new Subject();
@@ -99,31 +110,31 @@ export class Curtain {
99
110
 
100
111
  // set accessory information
101
112
  accessory
102
- .getService(this.platform.Service.AccessoryInformation)!
103
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
104
- .setCharacteristic(this.platform.Characteristic.Model, 'W0701600')
105
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
106
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
113
+ .getService(this.hap.Service.AccessoryInformation)!
114
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
115
+ .setCharacteristic(this.hap.Characteristic.Model, 'W0701600')
116
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
117
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
107
118
 
108
119
  // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
109
120
  // you can create multiple services for each accessory
110
121
  const windowCoveringService = `${accessory.displayName} ${device.deviceType}`;
111
- (this.windowCoveringService = accessory.getService(this.platform.Service.WindowCovering)
112
- || accessory.addService(this.platform.Service.WindowCovering)), windowCoveringService;
122
+ (this.windowCoveringService = accessory.getService(this.hap.Service.WindowCovering)
123
+ || accessory.addService(this.hap.Service.WindowCovering)), windowCoveringService;
113
124
 
114
- this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
115
- if (!this.windowCoveringService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
116
- this.windowCoveringService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
125
+ this.windowCoveringService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
126
+ if (!this.windowCoveringService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
127
+ this.windowCoveringService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
117
128
  }
118
129
 
119
130
  // each service must implement at-minimum the "required characteristics" for the given service type
120
131
  // see https://developers.homebridge.io/#/service/WindowCovering
121
132
 
122
133
  // create handlers for required characteristics
123
- this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
134
+ this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.PositionState);
124
135
 
125
136
  this.windowCoveringService
126
- .getCharacteristic(this.platform.Characteristic.CurrentPosition)
137
+ .getCharacteristic(this.hap.Characteristic.CurrentPosition)
127
138
  .setProps({
128
139
  minStep: this.minStep(device),
129
140
  minValue: 0,
@@ -135,7 +146,7 @@ export class Curtain {
135
146
  });
136
147
 
137
148
  this.windowCoveringService
138
- .getCharacteristic(this.platform.Characteristic.TargetPosition)
149
+ .getCharacteristic(this.hap.Characteristic.TargetPosition)
139
150
  .setProps({
140
151
  minStep: this.minStep(device),
141
152
  minValue: 0,
@@ -145,7 +156,7 @@ export class Curtain {
145
156
  .onSet(this.TargetPositionSet.bind(this));
146
157
 
147
158
  this.windowCoveringService
148
- .getCharacteristic(this.platform.Characteristic.HoldPosition)
159
+ .getCharacteristic(this.hap.Characteristic.HoldPosition)
149
160
  .setProps({
150
161
  minStep: this.minStep(device),
151
162
  minValue: 0,
@@ -157,17 +168,17 @@ export class Curtain {
157
168
  // Light Sensor Service
158
169
  if (device.curtain?.hide_lightsensor) {
159
170
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
160
- this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
171
+ this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor);
161
172
  accessory.removeService(this.lightSensorService!);
162
173
  } else if (!this.lightSensorService) {
163
174
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
164
175
  const lightSensorService = `${accessory.displayName} Light Sensor`;
165
- (this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor)
166
- || this.accessory.addService(this.platform.Service.LightSensor)), lightSensorService;
176
+ (this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor)
177
+ || this.accessory.addService(this.hap.Service.LightSensor)), lightSensorService;
167
178
 
168
- this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
169
- if (!this.lightSensorService?.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
170
- this.lightSensorService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
179
+ this.lightSensorService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Light Sensor`);
180
+ if (!this.lightSensorService?.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
181
+ this.lightSensorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
171
182
  }
172
183
  } else {
173
184
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
@@ -175,12 +186,12 @@ export class Curtain {
175
186
 
176
187
  // Battery Service
177
188
  const batteryService = `${accessory.displayName} Battery`;
178
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery)
179
- || accessory.addService(this.platform.Service.Battery)), batteryService;
189
+ (this.batteryService = this.accessory.getService(this.hap.Service.Battery)
190
+ || accessory.addService(this.hap.Service.Battery)), batteryService;
180
191
 
181
- this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
182
- if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
183
- this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
192
+ this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
193
+ if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
194
+ this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
184
195
  }
185
196
 
186
197
  // Update Homekit
@@ -202,15 +213,15 @@ export class Curtain {
202
213
  const { slidePosition, battery } = context;
203
214
  const { CurrentPosition, BatteryLevel } = this;
204
215
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
205
- '(slidePosition, battery) = ' +
206
- `Webhook:(${slidePosition}, ${battery}), ` +
207
- `current:(${CurrentPosition}, ${BatteryLevel})`);
216
+ '(slidePosition, battery) = ' +
217
+ `Webhook:(${slidePosition}, ${battery}), ` +
218
+ `current:(${CurrentPosition}, ${BatteryLevel})`);
208
219
  this.CurrentPosition = slidePosition;
209
220
  this.BatteryLevel = battery;
210
221
  this.updateHomeKitCharacteristics();
211
222
  } catch (e: any) {
212
223
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
213
- + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
224
+ + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
214
225
  }
215
226
  };
216
227
  }
@@ -219,7 +230,7 @@ export class Curtain {
219
230
  interval(this.updateRate * 1000)
220
231
  //.pipe(skipWhile(() => this.curtainUpdateInProgress))
221
232
  .subscribe(async () => {
222
- if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) {
233
+ if (this.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
223
234
  return;
224
235
  }
225
236
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
@@ -270,8 +281,8 @@ export class Curtain {
270
281
  filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
271
282
  });
272
283
  const motion: Service =
273
- this.accessory.getService(this.platform.Service.MotionSensor) ||
274
- this.accessory.addService(this.platform.Service.MotionSensor, `${this.accessory.displayName} Motion`);
284
+ this.accessory.getService(this.hap.Service.MotionSensor) ||
285
+ this.accessory.addService(this.hap.Service.MotionSensor, `${this.accessory.displayName} Motion`);
275
286
  motion.addOptionalCharacteristic(this.platform.eve.Characteristics.LastActivation);
276
287
  motion.getCharacteristic(this.platform.eve.Characteristics.LastActivation).onGet(() => {
277
288
  const lastActivation = this.accessory.context.lastActivation
@@ -280,9 +291,9 @@ export class Curtain {
280
291
  return lastActivation;
281
292
  });
282
293
  await this.setMinMax();
283
- motion.getCharacteristic(this.platform.Characteristic.MotionDetected).on('change', (event: CharacteristicChange) => {
294
+ motion.getCharacteristic(this.hap.Characteristic.MotionDetected).on('change', (event: CharacteristicChange) => {
284
295
  if (event.newValue !== event.oldValue) {
285
- const sensor = this.accessory.getService(this.platform.Service.MotionSensor);
296
+ const sensor = this.accessory.getService(this.hap.Service.MotionSensor);
286
297
  const entry = {
287
298
  time: Math.round(new Date().valueOf() / 1000),
288
299
  motion: event.newValue,
@@ -341,24 +352,24 @@ export class Curtain {
341
352
  await this.setMinMax();
342
353
  if (Number(this.TargetPosition) > this.CurrentPosition) {
343
354
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
344
- this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
345
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
355
+ this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
356
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
346
357
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
347
358
  } else if (Number(this.TargetPosition) < this.CurrentPosition) {
348
359
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
349
- this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
350
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
360
+ this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
361
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
351
362
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
352
363
  } else {
353
364
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
354
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
355
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
365
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
366
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
356
367
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
357
368
  }
358
369
  } else {
359
370
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
360
371
  this.TargetPosition = this.CurrentPosition;
361
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
372
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
362
373
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
363
374
  }
364
375
  this.debugLog(
@@ -425,9 +436,9 @@ export class Curtain {
425
436
  // Battery
426
437
  this.BatteryLevel = Number(this.BLE_BatteryLevel);
427
438
  if (this.BatteryLevel < 10) {
428
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
439
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
429
440
  } else {
430
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
441
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
431
442
  }
432
443
  this.debugLog(
433
444
  `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
@@ -448,24 +459,24 @@ export class Curtain {
448
459
  await this.setMinMax();
449
460
  if (Number(this.TargetPosition) > this.CurrentPosition) {
450
461
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
451
- this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
452
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
462
+ this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
463
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
453
464
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
454
465
  } else if (Number(this.TargetPosition) < this.CurrentPosition) {
455
466
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
456
- this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
457
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
467
+ this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
468
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
458
469
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
459
470
  } else {
460
471
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
461
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
462
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
472
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
473
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
463
474
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
464
475
  }
465
476
  } else {
466
477
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
467
478
  this.TargetPosition = this.CurrentPosition;
468
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
479
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
469
480
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
470
481
  }
471
482
  this.debugLog(
@@ -491,9 +502,9 @@ export class Curtain {
491
502
  // BatteryLevel
492
503
  this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
493
504
  if (this.BatteryLevel < 10) {
494
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
505
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
495
506
  } else {
496
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
507
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
497
508
  }
498
509
  if (Number.isNaN(this.BatteryLevel)) {
499
510
  this.BatteryLevel = 100;
@@ -801,7 +812,7 @@ export class Curtain {
801
812
 
802
813
  // Set HoldPosition to false when TargetPosition is changed
803
814
  this.HoldPosition = false;
804
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.HoldPosition, this.HoldPosition);
815
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.HoldPosition);
805
816
 
806
817
  this.TargetPosition = value;
807
818
  if (this.device.mqttURL) {
@@ -811,20 +822,20 @@ export class Curtain {
811
822
 
812
823
  await this.setMinMax();
813
824
  if (value > this.CurrentPosition) {
814
- this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
825
+ this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
815
826
  this.setNewTarget = true;
816
827
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
817
828
  } else if (value < this.CurrentPosition) {
818
- this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
829
+ this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
819
830
  this.setNewTarget = true;
820
831
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
821
832
  } else {
822
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
833
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
823
834
  this.setNewTarget = false;
824
835
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
825
836
  }
826
- this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
827
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
837
+ this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.PositionState);
838
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
828
839
 
829
840
  /**
830
841
  * If Curtain movement time is short, the moving flag from backend is always false.
@@ -859,7 +870,7 @@ export class Curtain {
859
870
  this.mqttPublish('CurrentPosition', this.CurrentPosition);
860
871
  }
861
872
  this.accessory.context.CurrentPosition = this.CurrentPosition;
862
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition));
873
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.CurrentPosition, Number(this.CurrentPosition));
863
874
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
864
875
  }
865
876
  if (this.PositionState === undefined) {
@@ -869,7 +880,7 @@ export class Curtain {
869
880
  this.mqttPublish('PositionState', this.PositionState);
870
881
  }
871
882
  this.accessory.context.PositionState = this.PositionState;
872
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.PositionState, Number(this.PositionState));
883
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.PositionState, Number(this.PositionState));
873
884
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
874
885
  }
875
886
  if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
@@ -879,7 +890,7 @@ export class Curtain {
879
890
  this.mqttPublish('TargetPosition', this.TargetPosition);
880
891
  }
881
892
  this.accessory.context.TargetPosition = this.TargetPosition;
882
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
893
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.TargetPosition, Number(this.TargetPosition));
883
894
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
884
895
  }
885
896
  if (this.HoldPosition === undefined) {
@@ -889,7 +900,7 @@ export class Curtain {
889
900
  this.mqttPublish('HoldPosition', this.HoldPosition);
890
901
  }
891
902
  this.accessory.context.HoldPosition = this.HoldPosition;
892
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.HoldPosition, this.HoldPosition);
903
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.HoldPosition);
893
904
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic HoldPosition: ${this.HoldPosition}`);
894
905
  }
895
906
  if (!this.device.curtain?.hide_lightsensor) {
@@ -900,7 +911,7 @@ export class Curtain {
900
911
  this.mqttPublish('CurrentAmbientLightLevel', this.CurrentAmbientLightLevel);
901
912
  }
902
913
  this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
903
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
914
+ this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
904
915
  this.debugLog(
905
916
  `${this.device.deviceType}: ${this.accessory.displayName}` +
906
917
  ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
@@ -920,7 +931,7 @@ export class Curtain {
920
931
  this.mqttPublish('BatteryLevel', this.BatteryLevel);
921
932
  }
922
933
  this.accessory.context.BatteryLevel = this.BatteryLevel;
923
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
934
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
924
935
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
925
936
  }
926
937
  if (this.StatusLowBattery === undefined) {
@@ -930,7 +941,7 @@ export class Curtain {
930
941
  this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
931
942
  }
932
943
  this.accessory.context.StatusLowBattery = this.StatusLowBattery;
933
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
944
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
934
945
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
935
946
  }
936
947
  }
@@ -1042,9 +1053,9 @@ export class Curtain {
1042
1053
  }
1043
1054
  }
1044
1055
  if (this.device.history) {
1045
- const motion = this.accessory.getService(this.platform.Service.MotionSensor);
1056
+ const motion = this.accessory.getService(this.hap.Service.MotionSensor);
1046
1057
  const state = Number(this.CurrentPosition) > 0 ? 1 : 0;
1047
- motion?.updateCharacteristic(this.platform.Characteristic.MotionDetected, state);
1058
+ motion?.updateCharacteristic(this.hap.Characteristic.MotionDetected, state);
1048
1059
  }
1049
1060
  }
1050
1061
 
@@ -1153,14 +1164,14 @@ export class Curtain {
1153
1164
  }
1154
1165
 
1155
1166
  async apiError(e: any): Promise<void> {
1156
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
1157
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.PositionState, e);
1158
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
1167
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
1168
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.PositionState, e);
1169
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
1159
1170
  if (!this.device.curtain?.hide_lightsensor) {
1160
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
1171
+ this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
1161
1172
  }
1162
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
1163
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1173
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
1174
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
1164
1175
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1165
1176
  }
1166
1177
 
@@ -1178,7 +1189,7 @@ export class Curtain {
1178
1189
  }
1179
1190
 
1180
1191
  if (this.accessory.context.PositionState === undefined) {
1181
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
1192
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
1182
1193
  } else {
1183
1194
  this.PositionState = this.accessory.context.PositionState;
1184
1195
  }
@@ -1196,7 +1207,7 @@ export class Curtain {
1196
1207
  this.BatteryLevel = this.accessory.context.BatteryLevel;
1197
1208
  }
1198
1209
  if (this.accessory.context.StatusLowBattery === undefined) {
1199
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
1210
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
1200
1211
  } else {
1201
1212
  this.StatusLowBattery = this.accessory.context.StatusLowBattery;
1202
1213
  }
@@ -1234,7 +1245,7 @@ export class Curtain {
1234
1245
  }
1235
1246
  }
1236
1247
 
1237
- async config(device: device & devicesConfig): Promise<void> {
1248
+ async deviceConfig(device: device & devicesConfig): Promise<void> {
1238
1249
  let config = {};
1239
1250
  if (device.curtain) {
1240
1251
  config = device.curtain;
@@ -1265,7 +1276,7 @@ export class Curtain {
1265
1276
  }
1266
1277
  }
1267
1278
 
1268
- async logs(device: device & devicesConfig): Promise<void> {
1279
+ async deviceLogs(device: device & devicesConfig): Promise<void> {
1269
1280
  if (this.platform.debugMode) {
1270
1281
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
1271
1282
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);