@switchbot/homebridge-switchbot 2.14.1-beta.0 → 3.0.0-beta.1

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 (147) hide show
  1. package/.github/{npm-version-script.js → npm-version-script.cjs} +1 -1
  2. package/.github/workflows/dependabot.yml +10 -11
  3. package/CHANGELOG.md +11 -2
  4. package/LICENSE +1 -1
  5. package/dist/device/blindtilt.d.ts +10 -6
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +152 -91
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts +10 -6
  10. package/dist/device/bot.d.ts.map +1 -1
  11. package/dist/device/bot.js +234 -184
  12. package/dist/device/bot.js.map +1 -1
  13. package/dist/device/ceilinglight.d.ts +10 -6
  14. package/dist/device/ceilinglight.d.ts.map +1 -1
  15. package/dist/device/ceilinglight.js +110 -64
  16. package/dist/device/ceilinglight.js.map +1 -1
  17. package/dist/device/colorbulb.d.ts +10 -6
  18. package/dist/device/colorbulb.d.ts.map +1 -1
  19. package/dist/device/colorbulb.js +121 -69
  20. package/dist/device/colorbulb.js.map +1 -1
  21. package/dist/device/contact.d.ts +10 -6
  22. package/dist/device/contact.d.ts.map +1 -1
  23. package/dist/device/contact.js +111 -66
  24. package/dist/device/contact.js.map +1 -1
  25. package/dist/device/curtain.d.ts +10 -6
  26. package/dist/device/curtain.d.ts.map +1 -1
  27. package/dist/device/curtain.js +165 -107
  28. package/dist/device/curtain.js.map +1 -1
  29. package/dist/device/hub.d.ts +10 -6
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +88 -51
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts +10 -6
  34. package/dist/device/humidifier.d.ts.map +1 -1
  35. package/dist/device/humidifier.js +133 -90
  36. package/dist/device/humidifier.js.map +1 -1
  37. package/dist/device/iosensor.d.ts +10 -6
  38. package/dist/device/iosensor.d.ts.map +1 -1
  39. package/dist/device/iosensor.js +109 -66
  40. package/dist/device/iosensor.js.map +1 -1
  41. package/dist/device/lightstrip.d.ts +10 -6
  42. package/dist/device/lightstrip.d.ts.map +1 -1
  43. package/dist/device/lightstrip.js +110 -65
  44. package/dist/device/lightstrip.js.map +1 -1
  45. package/dist/device/lock.d.ts +11 -7
  46. package/dist/device/lock.d.ts.map +1 -1
  47. package/dist/device/lock.js +125 -84
  48. package/dist/device/lock.js.map +1 -1
  49. package/dist/device/meter.d.ts +10 -6
  50. package/dist/device/meter.d.ts.map +1 -1
  51. package/dist/device/meter.js +103 -63
  52. package/dist/device/meter.js.map +1 -1
  53. package/dist/device/meterplus.d.ts +10 -6
  54. package/dist/device/meterplus.d.ts.map +1 -1
  55. package/dist/device/meterplus.js +103 -63
  56. package/dist/device/meterplus.js.map +1 -1
  57. package/dist/device/motion.d.ts +10 -6
  58. package/dist/device/motion.d.ts.map +1 -1
  59. package/dist/device/motion.js +95 -54
  60. package/dist/device/motion.js.map +1 -1
  61. package/dist/device/plug.d.ts +10 -6
  62. package/dist/device/plug.d.ts.map +1 -1
  63. package/dist/device/plug.js +68 -40
  64. package/dist/device/plug.js.map +1 -1
  65. package/dist/device/robotvacuumcleaner.d.ts +10 -6
  66. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  67. package/dist/device/robotvacuumcleaner.js +86 -52
  68. package/dist/device/robotvacuumcleaner.js.map +1 -1
  69. package/dist/homebridge-ui/server.js +5 -10
  70. package/dist/homebridge-ui/server.js.map +1 -1
  71. package/dist/index.d.ts +1 -4
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +9 -5
  74. package/dist/index.js.map +1 -1
  75. package/dist/irdevice/airconditioner.d.ts +9 -5
  76. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  77. package/dist/irdevice/airconditioner.js +105 -71
  78. package/dist/irdevice/airconditioner.js.map +1 -1
  79. package/dist/irdevice/airpurifier.d.ts +9 -5
  80. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  81. package/dist/irdevice/airpurifier.js +78 -46
  82. package/dist/irdevice/airpurifier.js.map +1 -1
  83. package/dist/irdevice/camera.d.ts +9 -5
  84. package/dist/irdevice/camera.d.ts.map +1 -1
  85. package/dist/irdevice/camera.js +41 -25
  86. package/dist/irdevice/camera.js.map +1 -1
  87. package/dist/irdevice/fan.d.ts +9 -5
  88. package/dist/irdevice/fan.d.ts.map +1 -1
  89. package/dist/irdevice/fan.js +62 -39
  90. package/dist/irdevice/fan.js.map +1 -1
  91. package/dist/irdevice/light.d.ts +9 -5
  92. package/dist/irdevice/light.d.ts.map +1 -1
  93. package/dist/irdevice/light.js +67 -45
  94. package/dist/irdevice/light.js.map +1 -1
  95. package/dist/irdevice/other.d.ts +9 -5
  96. package/dist/irdevice/other.d.ts.map +1 -1
  97. package/dist/irdevice/other.js +176 -150
  98. package/dist/irdevice/other.js.map +1 -1
  99. package/dist/irdevice/tv.d.ts +9 -5
  100. package/dist/irdevice/tv.d.ts.map +1 -1
  101. package/dist/irdevice/tv.js +81 -62
  102. package/dist/irdevice/tv.js.map +1 -1
  103. package/dist/irdevice/vacuumcleaner.d.ts +9 -5
  104. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  105. package/dist/irdevice/vacuumcleaner.js +41 -25
  106. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  107. package/dist/irdevice/waterheater.d.ts +9 -5
  108. package/dist/irdevice/waterheater.d.ts.map +1 -1
  109. package/dist/irdevice/waterheater.js +48 -32
  110. package/dist/irdevice/waterheater.js.map +1 -1
  111. package/dist/platform.d.ts +8 -9
  112. package/dist/platform.d.ts.map +1 -1
  113. package/dist/platform.js +151 -162
  114. package/dist/platform.js.map +1 -1
  115. package/dist/settings.js +7 -14
  116. package/dist/settings.js.map +1 -1
  117. package/dist/utils.js +1 -5
  118. package/dist/utils.js.map +1 -1
  119. package/package.json +20 -9
  120. package/src/device/blindtilt.ts +84 -72
  121. package/src/device/bot.ts +191 -180
  122. package/src/device/ceilinglight.ts +57 -44
  123. package/src/device/colorbulb.ts +53 -40
  124. package/src/device/contact.ts +71 -60
  125. package/src/device/curtain.ts +98 -86
  126. package/src/device/hub.ts +57 -45
  127. package/src/device/humidifier.ts +88 -77
  128. package/src/device/iosensor.ts +67 -55
  129. package/src/device/lightstrip.ts +56 -43
  130. package/src/device/lock.ts +91 -81
  131. package/src/device/meter.ts +63 -51
  132. package/src/device/meterplus.ts +67 -55
  133. package/src/device/motion.ts +58 -47
  134. package/src/device/plug.ts +38 -27
  135. package/src/device/robotvacuumcleaner.ts +49 -38
  136. package/src/index.ts +10 -7
  137. package/src/irdevice/airconditioner.ts +71 -63
  138. package/src/irdevice/airpurifier.ts +48 -40
  139. package/src/irdevice/camera.ts +28 -20
  140. package/src/irdevice/fan.ts +42 -34
  141. package/src/irdevice/light.ts +48 -40
  142. package/src/irdevice/other.ts +164 -156
  143. package/src/irdevice/tv.ts +66 -58
  144. package/src/irdevice/vacuumcleaner.ts +28 -20
  145. package/src/irdevice/waterheater.ts +35 -27
  146. package/src/platform.ts +65 -47
  147. package/tsconfig.json +11 -13
@@ -1,12 +1,16 @@
1
1
  import { request } from 'undici';
2
- import { sleep } from '../utils';
2
+ import { sleep } from '../utils.js';
3
3
  import { interval, Subject } from 'rxjs';
4
- import { SwitchBotPlatform } from '../platform';
4
+ import { SwitchBotPlatform } from '../platform.js';
5
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
- import { device, devicesConfig, deviceStatus, ad, Devices, serviceData } from '../settings';
6
+ import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
7
+ import { device, devicesConfig, deviceStatus, ad, Devices, serviceData, SwitchBotPlatformConfig } from '../settings.js';
8
8
 
9
9
  export class Lock {
10
+ public readonly api: API;
11
+ public readonly log: Logging;
12
+ public readonly config!: SwitchBotPlatformConfig;
13
+ protected readonly hap: HAP;
10
14
  // Services
11
15
  lockService: Service;
12
16
  batteryService: Service;
@@ -46,20 +50,27 @@ export class Lock {
46
50
  doLockUpdate!: Subject<void>;
47
51
 
48
52
  // Connection
49
- private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
50
- private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
53
+ private readonly OpenAPI: boolean;
54
+ private readonly BLE: boolean;
51
55
 
52
56
  constructor(
53
57
  private readonly platform: SwitchBotPlatform,
54
58
  private accessory: PlatformAccessory,
55
59
  public device: device & devicesConfig,
56
60
  ) {
61
+ this.api = this.platform.api;
62
+ this.log = this.platform.log;
63
+ this.config = this.platform.config;
64
+ this.hap = this.api.hap;
65
+ // Connection
66
+ this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
67
+ this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
57
68
  // default placeholders
58
- this.logs(device);
69
+ this.deviceLogs(device);
59
70
  this.scan(device);
60
71
  this.refreshRate(device);
61
72
  this.context();
62
- this.config(device);
73
+ this.deviceConfig(device);
63
74
 
64
75
  // this is subject we use to track when we need to POST changes to the SwitchBot API
65
76
  this.doLockUpdate = new Subject();
@@ -70,21 +81,21 @@ export class Lock {
70
81
 
71
82
  // set accessory information
72
83
  accessory
73
- .getService(this.platform.Service.AccessoryInformation)!
74
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
75
- .setCharacteristic(this.platform.Characteristic.Model, 'W1601700')
76
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
77
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
84
+ .getService(this.hap.Service.AccessoryInformation)!
85
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
86
+ .setCharacteristic(this.hap.Characteristic.Model, 'W1601700')
87
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
88
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
78
89
 
79
90
  // get the LockMechanism service if it exists, otherwise create a new LockMechanism service
80
91
  // you can create multiple services for each accessory
81
92
  const lockService = `${accessory.displayName} ${device.deviceType}`;
82
- (this.lockService = accessory.getService(this.platform.Service.LockMechanism)
83
- || accessory.addService(this.platform.Service.LockMechanism)), lockService;
93
+ (this.lockService = accessory.getService(this.hap.Service.LockMechanism)
94
+ || accessory.addService(this.hap.Service.LockMechanism)), lockService;
84
95
 
85
- this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
86
- if (!this.lockService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
87
- this.lockService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
96
+ this.lockService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
97
+ if (!this.lockService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
98
+ this.lockService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
88
99
  }
89
100
 
90
101
  // each service must implement at-minimum the "required characteristics" for the given service type
@@ -92,32 +103,31 @@ export class Lock {
92
103
 
93
104
 
94
105
  // create handlers for required characteristics
95
- this.lockService.getCharacteristic(this.platform.Characteristic.LockTargetState).onSet(this.LockTargetStateSet.bind(this));
106
+ this.lockService.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.LockTargetStateSet.bind(this));
96
107
 
97
108
 
98
109
  // Latch Button Service
99
110
  if (device.lock?.activate_latchbutton === false) { // remove the service when this variable is false
100
111
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Latch Button Service`);
101
- this.latchButtonService = accessory.getService(this.platform.Service.Switch);
112
+ this.latchButtonService = accessory.getService(this.hap.Service.Switch);
102
113
  if (this.latchButtonService) {
103
114
  accessory.removeService(this.latchButtonService);
104
115
  this.latchButtonService = undefined; // Reset the service variable to undefined
105
116
  }
106
- }
107
- else
108
- if (!this.latchButtonService) {
109
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Adding Latch Button Service`);
110
- const latchServiceName = `${accessory.displayName} Latch`;
111
- this.latchButtonService = accessory.getService(this.platform.Service.Switch)
112
- || accessory.addService(this.platform.Service.Switch, latchServiceName, 'LatchButtonServiceIdentifier');
117
+ } else
118
+ if (!this.latchButtonService) {
119
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Adding Latch Button Service`);
120
+ const latchServiceName = `${accessory.displayName} Latch`;
121
+ this.latchButtonService = accessory.getService(this.hap.Service.Switch)
122
+ || accessory.addService(this.hap.Service.Switch, latchServiceName, 'LatchButtonServiceIdentifier');
113
123
 
114
- this.latchButtonService.setCharacteristic(this.platform.Characteristic.Name, latchServiceName);
124
+ this.latchButtonService.setCharacteristic(this.hap.Characteristic.Name, latchServiceName);
115
125
 
116
- if (!this.latchButtonService.testCharacteristic(this.platform.Characteristic.On)) {
117
- this.latchButtonService.addCharacteristic(this.platform.Characteristic.On);
118
- }
126
+ if (!this.latchButtonService.testCharacteristic(this.hap.Characteristic.On)) {
127
+ this.latchButtonService.addCharacteristic(this.hap.Characteristic.On);
128
+ }
119
129
 
120
- this.latchButtonService.getCharacteristic(this.platform.Characteristic.On)
130
+ this.latchButtonService.getCharacteristic(this.hap.Characteristic.On)
121
131
  .on('set', (value, callback) => {
122
132
  if (typeof value === 'boolean') {
123
133
  this.handleLatchCharacteristic(value, callback);
@@ -125,25 +135,25 @@ export class Lock {
125
135
  callback(new Error('Wrong characteristic value type'));
126
136
  }
127
137
  });
128
- } else {
129
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Latch Button Service already exists`);
130
- }
138
+ } else {
139
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Latch Button Service already exists`);
140
+ }
131
141
 
132
142
 
133
143
  // Contact Sensor Service
134
144
  if (device.lock?.hide_contactsensor) {
135
145
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Contact Sensor Service`);
136
- this.contactSensorService = this.accessory.getService(this.platform.Service.ContactSensor);
146
+ this.contactSensorService = this.accessory.getService(this.hap.Service.ContactSensor);
137
147
  accessory.removeService(this.contactSensorService!);
138
148
  } else if (!this.contactSensorService) {
139
149
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Contact Sensor Service`);
140
150
  const contactSensorService = `${accessory.displayName} Contact Sensor`;
141
- (this.contactSensorService = this.accessory.getService(this.platform.Service.ContactSensor)
142
- || this.accessory.addService(this.platform.Service.ContactSensor)), contactSensorService;
151
+ (this.contactSensorService = this.accessory.getService(this.hap.Service.ContactSensor)
152
+ || this.accessory.addService(this.hap.Service.ContactSensor)), contactSensorService;
143
153
 
144
- this.contactSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Contact Sensor`);
145
- if (!this.contactSensorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
146
- this.contactSensorService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Contact Sensor`);
154
+ this.contactSensorService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Contact Sensor`);
155
+ if (!this.contactSensorService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
156
+ this.contactSensorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Contact Sensor`);
147
157
  }
148
158
  } else {
149
159
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Contact Sensor Service Not Added`);
@@ -151,14 +161,14 @@ export class Lock {
151
161
 
152
162
  // Battery Service
153
163
  const batteryService = `${accessory.displayName} Battery`;
154
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery)
155
- || accessory.addService(this.platform.Service.Battery)), batteryService;
164
+ (this.batteryService = this.accessory.getService(this.hap.Service.Battery)
165
+ || accessory.addService(this.hap.Service.Battery)), batteryService;
156
166
 
157
- this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
158
- if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
159
- this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
167
+ this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
168
+ if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
169
+ this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
160
170
  }
161
- this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
171
+ this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
162
172
 
163
173
  // Update Homekit
164
174
  this.updateHomeKitCharacteristics();
@@ -179,14 +189,14 @@ export class Lock {
179
189
  const { lockState } = context;
180
190
  const { LockCurrentState } = this;
181
191
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
182
- '(lockState) = ' +
183
- `Webhook:(${lockState}), ` +
184
- `current:(${LockCurrentState})`);
192
+ '(lockState) = ' +
193
+ `Webhook:(${lockState}), ` +
194
+ `current:(${LockCurrentState})`);
185
195
  this.LockCurrentState = lockState === 'LOCKED' ? 1 : 0;
186
196
  this.updateHomeKitCharacteristics();
187
197
  } catch (e: any) {
188
198
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
189
- + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
199
+ + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
190
200
  }
191
201
  };
192
202
  }
@@ -217,7 +227,7 @@ export class Lock {
217
227
  /**
218
228
  * Method for handling the LatchCharacteristic
219
229
  */
220
- private handleLatchCharacteristic(value: boolean, callback: Function) {
230
+ async handleLatchCharacteristic(value: boolean, callback) {
221
231
  this.debugLog(`handleLatchCharacteristic called with value: ${value}`);
222
232
 
223
233
  if (value) {
@@ -232,7 +242,7 @@ export class Lock {
232
242
  const latchButtonService = this.latchButtonService;
233
243
  // Simulate a button press by waiting a short period before turning the switch off
234
244
  setTimeout(() => {
235
- latchButtonService.getCharacteristic(this.platform.Characteristic.On).updateValue(false);
245
+ latchButtonService.getCharacteristic(this.hap.Characteristic.On).updateValue(false);
236
246
  this.debugLog('Latch button switched off automatically.');
237
247
  }, 500); // 500 ms delay
238
248
  }
@@ -243,7 +253,7 @@ export class Lock {
243
253
 
244
254
  // Ensure we turn the switch back off even in case of an error
245
255
  if (this.latchButtonService) {
246
- this.latchButtonService.getCharacteristic(this.platform.Characteristic.On).updateValue(false);
256
+ this.latchButtonService.getCharacteristic(this.hap.Characteristic.On).updateValue(false);
247
257
  this.debugLog('Latch button switched off after an error.');
248
258
  }
249
259
 
@@ -279,27 +289,27 @@ export class Lock {
279
289
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
280
290
  switch (this.BLE_LockCurrentState) {
281
291
  case 'locked':
282
- this.LockCurrentState = this.platform.Characteristic.LockCurrentState.SECURED;
283
- this.LockTargetState = this.platform.Characteristic.LockTargetState.SECURED;
292
+ this.LockCurrentState = this.hap.Characteristic.LockCurrentState.SECURED;
293
+ this.LockTargetState = this.hap.Characteristic.LockTargetState.SECURED;
284
294
  break;
285
295
  default:
286
- this.LockCurrentState = this.platform.Characteristic.LockCurrentState.UNSECURED;
287
- this.LockTargetState = this.platform.Characteristic.LockTargetState.UNSECURED;
296
+ this.LockCurrentState = this.hap.Characteristic.LockCurrentState.UNSECURED;
297
+ this.LockTargetState = this.hap.Characteristic.LockTargetState.UNSECURED;
288
298
  }
289
299
  switch (this.BLE_ContactSensorState) {
290
300
  case 'opened':
291
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
301
+ this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
292
302
  break;
293
303
  default:
294
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
304
+ this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
295
305
  }
296
306
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockTargetState}`);
297
307
  // Battery
298
308
  this.BatteryLevel = Number(this.BLE_BatteryLevel);
299
309
  if (this.BatteryLevel < 10) {
300
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
310
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
301
311
  } else {
302
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
312
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
303
313
  }
304
314
  this.debugLog(
305
315
  `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
@@ -310,28 +320,28 @@ export class Lock {
310
320
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
311
321
  switch (this.OpenAPI_LockCurrentState) {
312
322
  case 'locked':
313
- this.LockCurrentState = this.platform.Characteristic.LockCurrentState.SECURED;
314
- this.LockTargetState = this.platform.Characteristic.LockTargetState.SECURED;
323
+ this.LockCurrentState = this.hap.Characteristic.LockCurrentState.SECURED;
324
+ this.LockTargetState = this.hap.Characteristic.LockTargetState.SECURED;
315
325
  break;
316
326
  default:
317
- this.LockCurrentState = this.platform.Characteristic.LockCurrentState.UNSECURED;
318
- this.LockTargetState = this.platform.Characteristic.LockTargetState.UNSECURED;
327
+ this.LockCurrentState = this.hap.Characteristic.LockCurrentState.UNSECURED;
328
+ this.LockTargetState = this.hap.Characteristic.LockTargetState.UNSECURED;
319
329
  }
320
330
  switch (this.OpenAPI_ContactSensorState) {
321
331
  case 'opened':
322
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
332
+ this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
323
333
  break;
324
334
  default:
325
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
335
+ this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
326
336
  }
327
337
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockTargetState}`);
328
338
 
329
339
  // Battery
330
340
  this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
331
341
  if (this.BatteryLevel < 10) {
332
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
342
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
333
343
  } else {
334
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
344
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
335
345
  }
336
346
  if (Number.isNaN(this.BatteryLevel)) {
337
347
  this.BatteryLevel = 100;
@@ -511,7 +521,7 @@ export class Lock {
511
521
  })
512
522
  .then(() => {
513
523
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
514
- this.LockTargetState = this.platform.Characteristic.LockTargetState.SECURED;
524
+ this.LockTargetState = this.hap.Characteristic.LockTargetState.SECURED;
515
525
  })
516
526
  .catch(async (e: any) => {
517
527
  this.apiError(e);
@@ -603,7 +613,7 @@ export class Lock {
603
613
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
604
614
  } else {
605
615
  this.accessory.context.ContactSensorState = this.ContactSensorState;
606
- this.contactSensorService?.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
616
+ this.contactSensorService?.updateCharacteristic(this.hap.Characteristic.ContactSensorState, this.ContactSensorState);
607
617
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
608
618
  }
609
619
  }
@@ -611,28 +621,28 @@ export class Lock {
611
621
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LockTargetState: ${this.LockTargetState}`);
612
622
  } else {
613
623
  this.accessory.context.LockTargetState = this.LockTargetState;
614
- this.lockService.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.LockTargetState);
624
+ this.lockService.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.LockTargetState);
615
625
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LockTargetState: ${this.LockTargetState}`);
616
626
  }
617
627
  if (this.LockCurrentState === undefined) {
618
628
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LockCurrentState: ${this.LockCurrentState}`);
619
629
  } else {
620
630
  this.accessory.context.LockCurrentState = this.LockCurrentState;
621
- this.lockService.updateCharacteristic(this.platform.Characteristic.LockCurrentState, this.LockCurrentState);
631
+ this.lockService.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.LockCurrentState);
622
632
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LockCurrentState: ${this.LockCurrentState}`);
623
633
  }
624
634
  if (this.BatteryLevel === undefined) {
625
635
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
626
636
  } else {
627
637
  this.accessory.context.BatteryLevel = this.BatteryLevel;
628
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
638
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
629
639
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
630
640
  }
631
641
  if (this.StatusLowBattery === undefined) {
632
642
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
633
643
  } else {
634
644
  this.accessory.context.StatusLowBattery = this.StatusLowBattery;
635
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
645
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
636
646
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
637
647
  }
638
648
  }
@@ -745,10 +755,10 @@ export class Lock {
745
755
 
746
756
  async apiError(e: any): Promise<void> {
747
757
  if (!this.device.lock?.hide_contactsensor) {
748
- this.contactSensorService?.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
758
+ this.contactSensorService?.updateCharacteristic(this.hap.Characteristic.ContactSensorState, e);
749
759
  }
750
- this.lockService.updateCharacteristic(this.platform.Characteristic.LockTargetState, e);
751
- this.lockService.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
760
+ this.lockService.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
761
+ this.lockService.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
752
762
  }
753
763
 
754
764
  async context() {
@@ -773,7 +783,7 @@ export class Lock {
773
783
  }
774
784
  }
775
785
 
776
- async config(device: device & devicesConfig): Promise<void> {
786
+ async deviceConfig(device: device & devicesConfig): Promise<void> {
777
787
  let config = {};
778
788
  if (device.lock) {
779
789
  config = device.lock;
@@ -798,7 +808,7 @@ export class Lock {
798
808
  }
799
809
  }
800
810
 
801
- async logs(device: device & devicesConfig): Promise<void> {
811
+ async deviceLogs(device: device & devicesConfig): Promise<void> {
802
812
  if (this.platform.debugMode) {
803
813
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
804
814
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);