@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
@@ -3,8 +3,8 @@ import { sleep } from '../utils';
3
3
  import { interval, Subject } from 'rxjs';
4
4
  import { skipWhile } from 'rxjs/operators';
5
5
  import { SwitchBotPlatform } from '../platform';
6
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
- import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '../settings';
6
+ import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
7
+ import { device, devicesConfig, serviceData, deviceStatus, ad, Devices, SwitchBotPlatformConfig } from '../settings';
8
8
 
9
9
  /**
10
10
  * Platform Accessory
@@ -12,6 +12,10 @@ import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '.
12
12
  * Each accessory may expose multiple services of different service types.
13
13
  */
14
14
  export class Contact {
15
+ public readonly api: API;
16
+ public readonly log: Logging;
17
+ public readonly config!: SwitchBotPlatformConfig;
18
+ protected readonly hap: HAP;
15
19
  // Services
16
20
  motionService?: Service;
17
21
  batteryService: Service;
@@ -55,20 +59,27 @@ export class Contact {
55
59
  doContactUpdate!: Subject<void>;
56
60
 
57
61
  // Connection
58
- private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
59
- private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
62
+ private readonly OpenAPI: boolean;
63
+ private readonly BLE: boolean;
60
64
 
61
65
  constructor(
62
66
  private readonly platform: SwitchBotPlatform,
63
67
  private accessory: PlatformAccessory,
64
68
  public device: device & devicesConfig,
65
69
  ) {
70
+ this.api = this.platform.api;
71
+ this.log = this.platform.log;
72
+ this.config = this.platform.config;
73
+ this.hap = this.api.hap;
74
+ // Connection
75
+ this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
76
+ this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
66
77
  // default placeholders
67
- this.logs(device);
78
+ this.devicedeviceLogs(device);
68
79
  this.scan(device);
69
80
  this.refreshRate(device);
70
81
  this.context();
71
- this.config(device);
82
+ this.devicedeviceConfig(device);
72
83
 
73
84
  // this is subject we use to track when we need to POST changes to the SwitchBot API
74
85
  this.doContactUpdate = new Subject();
@@ -79,36 +90,36 @@ export class Contact {
79
90
 
80
91
  // set accessory information
81
92
  accessory
82
- .getService(this.platform.Service.AccessoryInformation)!
83
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
84
- .setCharacteristic(this.platform.Characteristic.Model, 'W1201500')
85
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
86
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
93
+ .getService(this.hap.Service.AccessoryInformation)!
94
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
95
+ .setCharacteristic(this.hap.Characteristic.Model, 'W1201500')
96
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
97
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
87
98
 
88
99
  // get the Contact service if it exists, otherwise create a new Contact service
89
100
  // you can create multiple services for each accessory
90
101
  const contactSensorservice = `${accessory.displayName} Contact Sensor`;
91
- (this.contactSensorservice = accessory.getService(this.platform.Service.ContactSensor)
92
- || accessory.addService(this.platform.Service.ContactSensor)), contactSensorservice;
102
+ (this.contactSensorservice = accessory.getService(this.hap.Service.ContactSensor)
103
+ || accessory.addService(this.hap.Service.ContactSensor)), contactSensorservice;
93
104
 
94
- this.contactSensorservice.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
95
- if (!this.contactSensorservice.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
96
- this.contactSensorservice.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
105
+ this.contactSensorservice.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
106
+ if (!this.contactSensorservice.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
107
+ this.contactSensorservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
97
108
  }
98
109
 
99
110
  // Motion Sensor Service
100
111
  if (device.contact?.hide_motionsensor) {
101
112
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
102
- this.motionService = this.accessory.getService(this.platform.Service.MotionSensor);
113
+ this.motionService = this.accessory.getService(this.hap.Service.MotionSensor);
103
114
  accessory.removeService(this.motionService!);
104
115
  } else if (!this.motionService) {
105
116
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
106
117
  const motionService = `${accessory.displayName} Motion Sensor`;
107
- (this.motionService = this.accessory.getService(this.platform.Service.MotionSensor)
108
- || this.accessory.addService(this.platform.Service.MotionSensor)), motionService;
118
+ (this.motionService = this.accessory.getService(this.hap.Service.MotionSensor)
119
+ || this.accessory.addService(this.hap.Service.MotionSensor)), motionService;
109
120
 
110
- this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
111
- this.motionService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Motion Sensor`);
121
+ this.motionService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
122
+ this.motionService.setCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Motion Sensor`);
112
123
  } else {
113
124
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Motion Sensor Service Not Added`);
114
125
  }
@@ -116,31 +127,31 @@ export class Contact {
116
127
  // Light Sensor Service
117
128
  if (device.contact?.hide_lightsensor) {
118
129
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
119
- this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
130
+ this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor);
120
131
  accessory.removeService(this.lightSensorService!);
121
132
  } else if (!this.lightSensorService) {
122
133
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
123
134
 
124
135
  const lightSensorService = `${accessory.displayName} Light Sensor`;
125
- (this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor)
126
- || this.accessory.addService(this.platform.Service.LightSensor)), lightSensorService;
136
+ (this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor)
137
+ || this.accessory.addService(this.hap.Service.LightSensor)), lightSensorService;
127
138
 
128
- this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
129
- this.lightSensorService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
139
+ this.lightSensorService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Light Sensor`);
140
+ this.lightSensorService.setCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
130
141
  } else {
131
142
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
132
143
  }
133
144
 
134
145
  // Battery Service
135
146
  const batteryService = `${accessory.displayName} Battery`;
136
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery)
137
- || accessory.addService(this.platform.Service.Battery)), batteryService;
147
+ (this.batteryService = this.accessory.getService(this.hap.Service.Battery)
148
+ || accessory.addService(this.hap.Service.Battery)), batteryService;
138
149
 
139
- this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
140
- if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
141
- this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
150
+ this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
151
+ if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
152
+ this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
142
153
  }
143
- this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
154
+ this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
144
155
 
145
156
  // Retrieve initial values and updateHomekit
146
157
  this.updateHomeKitCharacteristics();
@@ -161,9 +172,9 @@ export class Contact {
161
172
  const { detectionState, brightness, openState } = context;
162
173
  const { MotionDetected, CurrentAmbientLightLevel, ContactSensorState } = this;
163
174
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
164
- '(detectionState, brightness, openState) = ' +
165
- `Webhook:(${detectionState}, ${brightness}, ${openState}), ` +
166
- `current:(${MotionDetected}, ${CurrentAmbientLightLevel}, ${ContactSensorState})`);
175
+ '(detectionState, brightness, openState) = ' +
176
+ `Webhook:(${detectionState}, ${brightness}, ${openState}), ` +
177
+ `current:(${MotionDetected}, ${CurrentAmbientLightLevel}, ${ContactSensorState})`);
167
178
  this.set_minLux = this.minLux();
168
179
  this.set_maxLux = this.maxLux();
169
180
  this.MotionDetected = detectionState === 'DETECTED' ? true : false;
@@ -172,7 +183,7 @@ export class Contact {
172
183
  this.updateHomeKitCharacteristics();
173
184
  } catch (e: any) {
174
185
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
175
- + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
186
+ + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
176
187
  }
177
188
  };
178
189
  }
@@ -202,11 +213,11 @@ export class Contact {
202
213
  switch (this.BLE_ContactSensorState) {
203
214
  case 'open':
204
215
  case 1:
205
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
216
+ this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
206
217
  break;
207
218
  case 'close':
208
219
  case 0:
209
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
220
+ this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
210
221
  break;
211
222
  default:
212
223
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.BLE_ContactSensorState}`);
@@ -214,7 +225,7 @@ export class Contact {
214
225
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
215
226
  if (
216
227
  this.ContactSensorState !== this.accessory.context.ContactSensorState &&
217
- this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
228
+ this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
218
229
  ) {
219
230
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Opened`);
220
231
  }
@@ -251,9 +262,9 @@ export class Contact {
251
262
  }
252
263
  this.BatteryLevel = Number(this.BLE_BateryLevel);
253
264
  if (this.BatteryLevel < 10) {
254
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
265
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
255
266
  } else {
256
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
267
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
257
268
  }
258
269
  this.debugLog(
259
270
  `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, ` + `StatusLowBattery: ${this.StatusLowBattery}`,
@@ -264,10 +275,10 @@ export class Contact {
264
275
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
265
276
  // Contact State
266
277
  if (this.OpenAPI_ContactSensorState === 'open') {
267
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
278
+ this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
268
279
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
269
280
  } else if (this.OpenAPI_ContactSensorState === 'close') {
270
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
281
+ this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
271
282
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
272
283
  } else {
273
284
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.OpenAPI_ContactSensorState}`);
@@ -297,9 +308,9 @@ export class Contact {
297
308
  }
298
309
  this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
299
310
  if (this.BatteryLevel < 10) {
300
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
311
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
301
312
  } else {
302
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
313
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
303
314
  }
304
315
  this.debugLog(
305
316
  `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, ` + `StatusLowBattery: ${this.StatusLowBattery}`,
@@ -441,7 +452,7 @@ export class Contact {
441
452
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
442
453
  } else {
443
454
  this.accessory.context.ContactSensorState = this.ContactSensorState;
444
- this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
455
+ this.contactSensorservice.updateCharacteristic(this.hap.Characteristic.ContactSensorState, this.ContactSensorState);
445
456
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
446
457
  }
447
458
  if (!this.device.contact?.hide_motionsensor) {
@@ -449,7 +460,7 @@ export class Contact {
449
460
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
450
461
  } else {
451
462
  this.accessory.context.MotionDetected = this.MotionDetected;
452
- this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
463
+ this.motionService?.updateCharacteristic(this.hap.Characteristic.MotionDetected, this.MotionDetected);
453
464
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
454
465
  }
455
466
  }
@@ -458,7 +469,7 @@ export class Contact {
458
469
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
459
470
  } else {
460
471
  this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
461
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
472
+ this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
462
473
  this.debugLog(
463
474
  `${this.device.deviceType}: ${this.accessory.displayName}` +
464
475
  ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
@@ -469,14 +480,14 @@ export class Contact {
469
480
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
470
481
  } else {
471
482
  this.accessory.context.BatteryLevel = this.BatteryLevel;
472
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
483
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
473
484
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
474
485
  }
475
486
  if (this.StatusLowBattery === undefined) {
476
487
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
477
488
  } else {
478
489
  this.accessory.context.StatusLowBattery = this.StatusLowBattery;
479
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
490
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
480
491
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
481
492
  }
482
493
  }
@@ -599,15 +610,15 @@ export class Contact {
599
610
  }
600
611
 
601
612
  async apiError(e: any): Promise<void> {
602
- this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
613
+ this.contactSensorservice.updateCharacteristic(this.hap.Characteristic.ContactSensorState, e);
603
614
  if (!this.device.contact?.hide_motionsensor) {
604
- this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
615
+ this.motionService?.updateCharacteristic(this.hap.Characteristic.MotionDetected, e);
605
616
  }
606
617
  if (!this.device.contact?.hide_lightsensor) {
607
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
618
+ this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
608
619
  }
609
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
610
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
620
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
621
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
611
622
  }
612
623
 
613
624
  async context() {
@@ -617,7 +628,7 @@ export class Contact {
617
628
  this.MotionDetected = this.accessory.context.MotionDetected;
618
629
  }
619
630
  if (this.ContactSensorState === undefined) {
620
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
631
+ this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
621
632
  } else {
622
633
  this.ContactSensorState = this.accessory.context.ContactSensorState;
623
634
  }
@@ -637,7 +648,7 @@ export class Contact {
637
648
  }
638
649
  }
639
650
 
640
- async config(device: device & devicesConfig): Promise<void> {
651
+ async devicedeviceConfig(device: device & devicesConfig): Promise<void> {
641
652
  let config = {};
642
653
  if (device.contact) {
643
654
  config = device.contact;
@@ -662,7 +673,7 @@ export class Contact {
662
673
  }
663
674
  }
664
675
 
665
- async logs(device: device & devicesConfig): Promise<void> {
676
+ async devicedeviceLogs(device: device & devicesConfig): Promise<void> {
666
677
  if (this.platform.debugMode) {
667
678
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
668
679
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);