@switchbot/homebridge-switchbot 2.0.0-beta.4 → 2.0.0-beta.41

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 (119) hide show
  1. package/CHANGELOG.md +12 -2
  2. package/README.md +3 -2
  3. package/config.schema.json +108 -20
  4. package/dist/device/bot.d.ts +34 -28
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +657 -648
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.d.ts +137 -0
  9. package/dist/device/ceilinglight.d.ts.map +1 -0
  10. package/dist/device/ceilinglight.js +1127 -0
  11. package/dist/device/ceilinglight.js.map +1 -0
  12. package/dist/device/colorbulb.d.ts +36 -19
  13. package/dist/device/colorbulb.d.ts.map +1 -1
  14. package/dist/device/colorbulb.js +486 -309
  15. package/dist/device/colorbulb.js.map +1 -1
  16. package/dist/device/contact.d.ts +18 -8
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +306 -237
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts +23 -16
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +566 -502
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/humidifier.d.ts +24 -18
  25. package/dist/device/humidifier.d.ts.map +1 -1
  26. package/dist/device/humidifier.js +453 -369
  27. package/dist/device/humidifier.js.map +1 -1
  28. package/dist/device/lock.d.ts +27 -8
  29. package/dist/device/lock.d.ts.map +1 -1
  30. package/dist/device/lock.js +305 -148
  31. package/dist/device/lock.js.map +1 -1
  32. package/dist/device/meter.d.ts +22 -16
  33. package/dist/device/meter.d.ts.map +1 -1
  34. package/dist/device/meter.js +367 -267
  35. package/dist/device/meter.js.map +1 -1
  36. package/dist/device/meterplus.d.ts +24 -12
  37. package/dist/device/meterplus.d.ts.map +1 -1
  38. package/dist/device/meterplus.js +381 -213
  39. package/dist/device/meterplus.js.map +1 -1
  40. package/dist/device/motion.d.ts +18 -8
  41. package/dist/device/motion.d.ts.map +1 -1
  42. package/dist/device/motion.js +279 -216
  43. package/dist/device/motion.js.map +1 -1
  44. package/dist/device/plug.d.ts +27 -17
  45. package/dist/device/plug.d.ts.map +1 -1
  46. package/dist/device/plug.js +295 -251
  47. package/dist/device/plug.js.map +1 -1
  48. package/dist/device/striplight.d.ts +43 -19
  49. package/dist/device/striplight.d.ts.map +1 -1
  50. package/dist/device/striplight.js +506 -262
  51. package/dist/device/striplight.js.map +1 -1
  52. package/dist/irdevice/airconditioner.d.ts +9 -12
  53. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  54. package/dist/irdevice/airconditioner.js +278 -230
  55. package/dist/irdevice/airconditioner.js.map +1 -1
  56. package/dist/irdevice/airpurifier.d.ts +5 -3
  57. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  58. package/dist/irdevice/airpurifier.js +154 -104
  59. package/dist/irdevice/airpurifier.js.map +1 -1
  60. package/dist/irdevice/camera.d.ts +11 -8
  61. package/dist/irdevice/camera.d.ts.map +1 -1
  62. package/dist/irdevice/camera.js +133 -86
  63. package/dist/irdevice/camera.js.map +1 -1
  64. package/dist/irdevice/fan.d.ts +10 -7
  65. package/dist/irdevice/fan.d.ts.map +1 -1
  66. package/dist/irdevice/fan.js +160 -109
  67. package/dist/irdevice/fan.js.map +1 -1
  68. package/dist/irdevice/light.d.ts +11 -8
  69. package/dist/irdevice/light.d.ts.map +1 -1
  70. package/dist/irdevice/light.js +137 -103
  71. package/dist/irdevice/light.js.map +1 -1
  72. package/dist/irdevice/other.d.ts +11 -8
  73. package/dist/irdevice/other.d.ts.map +1 -1
  74. package/dist/irdevice/other.js +145 -98
  75. package/dist/irdevice/other.js.map +1 -1
  76. package/dist/irdevice/tv.d.ts +12 -9
  77. package/dist/irdevice/tv.d.ts.map +1 -1
  78. package/dist/irdevice/tv.js +143 -93
  79. package/dist/irdevice/tv.js.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.d.ts +9 -10
  81. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  82. package/dist/irdevice/vacuumcleaner.js +132 -89
  83. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  84. package/dist/irdevice/waterheater.d.ts +8 -9
  85. package/dist/irdevice/waterheater.d.ts.map +1 -1
  86. package/dist/irdevice/waterheater.js +132 -89
  87. package/dist/irdevice/waterheater.js.map +1 -1
  88. package/dist/platform.d.ts +15 -12
  89. package/dist/platform.d.ts.map +1 -1
  90. package/dist/platform.js +574 -454
  91. package/dist/platform.js.map +1 -1
  92. package/dist/settings.d.ts +21 -11
  93. package/dist/settings.d.ts.map +1 -1
  94. package/dist/settings.js.map +1 -1
  95. package/homebridge-ui/public/index.html +1 -0
  96. package/package.json +13 -11
  97. package/src/device/bot.ts +656 -659
  98. package/src/device/ceilinglight.ts +1208 -0
  99. package/src/device/colorbulb.ts +490 -344
  100. package/src/device/contact.ts +309 -241
  101. package/src/device/curtain.ts +571 -516
  102. package/src/device/humidifier.ts +456 -403
  103. package/src/device/lock.ts +314 -149
  104. package/src/device/meter.ts +378 -280
  105. package/src/device/meterplus.ts +391 -219
  106. package/src/device/motion.ts +285 -222
  107. package/src/device/plug.ts +299 -260
  108. package/src/device/striplight.ts +522 -289
  109. package/src/irdevice/airconditioner.ts +282 -241
  110. package/src/irdevice/airpurifier.ts +151 -103
  111. package/src/irdevice/camera.ts +131 -85
  112. package/src/irdevice/fan.ts +157 -106
  113. package/src/irdevice/light.ts +135 -103
  114. package/src/irdevice/other.ts +143 -97
  115. package/src/irdevice/tv.ts +142 -93
  116. package/src/irdevice/vacuumcleaner.ts +131 -89
  117. package/src/irdevice/waterheater.ts +130 -89
  118. package/src/platform.ts +567 -476
  119. package/src/settings.ts +22 -11
@@ -8,6 +8,7 @@ const https_1 = __importDefault(require("https"));
8
8
  const crypto_1 = __importDefault(require("crypto"));
9
9
  const rxjs_1 = require("rxjs");
10
10
  const operators_1 = require("rxjs/operators");
11
+ const super_stringify_1 = __importDefault(require("super-stringify"));
11
12
  const settings_1 = require("../settings");
12
13
  /**
13
14
  * Platform Accessory
@@ -19,12 +20,15 @@ class Contact {
19
20
  this.platform = platform;
20
21
  this.accessory = accessory;
21
22
  this.device = device;
23
+ // Connection
24
+ this.BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
25
+ this.OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
22
26
  // default placeholders
23
27
  this.logs(device);
24
28
  this.scan(device);
25
29
  this.refreshRate(device);
26
30
  this.config(device);
27
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
31
+ this.context();
28
32
  // this is subject we use to track when we need to POST changes to the SwitchBot API
29
33
  this.doContactUpdate = new rxjs_1.Subject();
30
34
  this.contactUbpdateInProgress = false;
@@ -54,50 +58,50 @@ class Contact {
54
58
  // see https://developers.homebridge.io/#/service/ContactSensor
55
59
  // Motion Sensor Service
56
60
  if (device.contact?.hide_motionsensor) {
57
- this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Motion Sensor Service`);
61
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
58
62
  this.motionService = this.accessory.getService(this.platform.Service.MotionSensor);
59
63
  accessory.removeService(this.motionService);
60
64
  }
61
65
  else if (!this.motionService) {
62
- this.debugLog(`Contact Sensor: ${accessory.displayName} Add Motion Sensor Service`);
66
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
63
67
  (this.motionService =
64
68
  this.accessory.getService(this.platform.Service.MotionSensor) || this.accessory.addService(this.platform.Service.MotionSensor)),
65
69
  `${accessory.displayName} Motion Sensor`;
66
70
  this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
67
71
  }
68
72
  else {
69
- this.debugLog(`Contact Sensor: ${accessory.displayName} Motion Sensor Service Not Added`);
73
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Motion Sensor Service Not Added`);
70
74
  }
71
75
  // Light Sensor Service
72
76
  if (device.contact?.hide_lightsensor) {
73
- this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Light Sensor Service`);
77
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
74
78
  this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
75
79
  accessory.removeService(this.lightSensorService);
76
80
  }
77
81
  else if (!this.lightSensorService) {
78
- this.debugLog(`Contact Sensor: ${accessory.displayName} Add Light Sensor Service`);
82
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
79
83
  (this.lightSensorService =
80
84
  this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
81
85
  `${accessory.displayName} Light Sensor`;
82
86
  this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
83
87
  }
84
88
  else {
85
- this.debugLog(`Contact Sensor: ${accessory.displayName} Light Sensor Service Not Added`);
89
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
86
90
  }
87
91
  // Battery Service
88
- if (!device.ble) {
89
- this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Battery Service`);
92
+ if (!this.BLE) {
93
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
90
94
  this.batteryService = this.accessory.getService(this.platform.Service.Battery);
91
95
  accessory.removeService(this.batteryService);
92
96
  }
93
- else if (device.ble && !this.batteryService) {
94
- this.debugLog(`Contact Sensor: ${accessory.displayName} Add Battery Service`);
97
+ else if (this.BLE && !this.batteryService) {
98
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
95
99
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
96
100
  `${accessory.displayName} Battery`;
97
101
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
98
102
  }
99
103
  else {
100
- this.debugLog(`Contact Sensor: ${accessory.displayName} Battery Service Not Added`);
104
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
101
105
  }
102
106
  // Retrieve initial values and updateHomekit
103
107
  this.updateHomeKitCharacteristics();
@@ -112,15 +116,19 @@ class Contact {
112
116
  * Parse the device status from the SwitchBot api
113
117
  */
114
118
  async parseStatus() {
115
- if (this.SwitchToOpenAPI || !this.device.ble) {
119
+ if (this.BLE) {
120
+ await this.BLEparseStatus();
121
+ }
122
+ else if (this.OpenAPI && this.platform.config.credentials?.token) {
116
123
  await this.openAPIparseStatus();
117
124
  }
118
125
  else {
119
- await this.BLEparseStatus();
126
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
127
+ + ` ${this.device.connectionType}, parseStatus will not happen.`);
120
128
  }
121
129
  }
122
130
  async BLEparseStatus() {
123
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE parseStatus`);
131
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
124
132
  // Door State
125
133
  switch (this.doorState) {
126
134
  case 'open':
@@ -132,12 +140,12 @@ class Contact {
132
140
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
133
141
  break;
134
142
  default:
135
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
143
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
136
144
  }
137
145
  // Movement
138
146
  if (!this.device.contact?.hide_motionsensor) {
139
147
  this.MotionDetected = Boolean(this.movement);
140
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
148
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
141
149
  }
142
150
  // Light Level
143
151
  if (!this.device.contact?.hide_lightsensor) {
@@ -151,7 +159,7 @@ class Contact {
151
159
  default:
152
160
  this.CurrentAmbientLightLevel = this.set_maxLux;
153
161
  }
154
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
162
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
155
163
  ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
156
164
  }
157
165
  // Battery
@@ -165,60 +173,60 @@ class Contact {
165
173
  else {
166
174
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
167
175
  }
168
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
176
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, `
177
+ + `StatusLowBattery: ${this.StatusLowBattery}`);
169
178
  }
170
179
  async openAPIparseStatus() {
171
- if (this.device.ble) {
172
- this.SwitchToOpenAPI = false;
180
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
181
+ // Contact State
182
+ if (this.openState === 'open') {
183
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
184
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
173
185
  }
174
- if (this.platform.config.credentials?.token) {
175
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
176
- // Contact State
177
- if (this.openState === 'open') {
178
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
179
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
180
- }
181
- else if (this.openState === 'close') {
182
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
183
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
184
- }
185
- else {
186
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} openState: ${this.openState}`);
187
- }
188
- // Motion State
189
- if (!this.device.contact?.hide_motionsensor) {
190
- this.MotionDetected = this.moveDetected;
191
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
192
- }
193
- // Light Level
194
- if (!this.device.contact?.hide_lightsensor) {
195
- this.set_minLux = this.minLux();
196
- this.set_maxLux = this.maxLux();
197
- switch (this.brightness) {
198
- case 'dim':
199
- this.CurrentAmbientLightLevel = this.set_minLux;
200
- break;
201
- case 'bright':
202
- default:
203
- this.CurrentAmbientLightLevel = this.set_maxLux;
204
- }
205
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
186
+ else if (this.openState === 'close') {
187
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
188
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
189
+ }
190
+ else {
191
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.openState}`);
192
+ }
193
+ // Motion State
194
+ if (!this.device.contact?.hide_motionsensor) {
195
+ this.MotionDetected = this.moveDetected;
196
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
197
+ }
198
+ // Light Level
199
+ if (!this.device.contact?.hide_lightsensor) {
200
+ this.set_minLux = this.minLux();
201
+ this.set_maxLux = this.maxLux();
202
+ switch (this.brightness) {
203
+ case 'dim':
204
+ this.CurrentAmbientLightLevel = this.set_minLux;
205
+ break;
206
+ case 'bright':
207
+ default:
208
+ this.CurrentAmbientLightLevel = this.set_maxLux;
206
209
  }
210
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
207
211
  }
208
212
  }
209
213
  /**
210
214
  * Asks the SwitchBot API for the latest device information
211
215
  */
212
216
  async refreshStatus() {
213
- if (this.device.ble) {
217
+ if (this.BLE) {
214
218
  await this.BLERefreshStatus();
215
219
  }
216
- else {
220
+ else if (this.OpenAPI) {
217
221
  await this.openAPIRefreshStatus();
218
222
  }
223
+ else {
224
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
225
+ + ` ${this.device.connectionType}, refreshStatus will not happen.`);
226
+ }
219
227
  }
220
228
  async BLERefreshStatus() {
221
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE refreshStatus`);
229
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
222
230
  const switchbot = await this.platform.connectBLE();
223
231
  // Convert to BLE Address
224
232
  this.device.bleMac =
@@ -227,7 +235,7 @@ class Contact {
227
235
  .deviceId.match(/.{1,2}/g)
228
236
  .join(':')
229
237
  .toLowerCase();
230
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
238
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
231
239
  this.getCustomBLEAddress(switchbot);
232
240
  // Start to monitor advertisement packets
233
241
  if (switchbot !== false) {
@@ -240,27 +248,23 @@ class Contact {
240
248
  // Set an event hander
241
249
  switchbot.onadvertisement = (ad) => {
242
250
  this.address = ad.address;
243
- if (this.deviceLogging.includes('debug')) {
244
- this.infoLog(this.address);
245
- this.infoLog(this.device.bleMac);
246
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
247
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
248
- }
251
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
252
+ + ` BLE Address Found: ${this.address}`);
249
253
  this.serviceData = ad.serviceData;
250
254
  this.movement = ad.serviceData.movement;
251
255
  this.doorState = ad.serviceData.doorState;
252
256
  this.lightLevel = ad.serviceData.lightLevel;
253
257
  this.battery = ad.serviceData.battery;
254
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
255
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
258
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
259
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
256
260
  `${ad.serviceData.doorState}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
257
261
  if (this.serviceData) {
258
262
  this.connected = true;
259
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
263
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
260
264
  }
261
265
  else {
262
266
  this.connected = false;
263
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
267
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
264
268
  }
265
269
  };
266
270
  // Wait 2 seconds
@@ -270,114 +274,77 @@ class Contact {
270
274
  // Stop to monitor
271
275
  switchbot.stopScan();
272
276
  if (this.connected) {
273
- this.parseStatus();
277
+ this.BLEparseStatus();
274
278
  this.updateHomeKitCharacteristics();
275
279
  }
276
280
  else {
277
- await this.BLEconnection(switchbot);
281
+ await this.BLERefreshConnection(switchbot);
278
282
  }
279
283
  })
280
284
  .catch(async (e) => {
281
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
282
- if (this.deviceLogging.includes('debug')) {
283
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
284
- ` Error Message: ${JSON.stringify(e.message)}`);
285
- }
286
- if (this.platform.config.credentials?.token) {
287
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
288
- this.SwitchToOpenAPI = true;
289
- await this.openAPIRefreshStatus();
290
- }
291
285
  this.apiError(e);
286
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
287
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
288
+ await this.BLERefreshConnection(switchbot);
292
289
  });
293
290
  }
294
291
  else {
295
- await this.BLEconnection(switchbot);
296
- }
297
- }
298
- async getCustomBLEAddress(switchbot) {
299
- if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
300
- (async () => {
301
- // Start to monitor advertisement packets
302
- await switchbot.startScan({
303
- model: 'd',
304
- });
305
- // Set an event handler
306
- switchbot.onadvertisement = (ad) => {
307
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
308
- };
309
- await switchbot.wait(10000);
310
- // Stop to monitor
311
- switchbot.stopScan();
312
- })();
313
- }
314
- }
315
- async BLEconnection(switchbot) {
316
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
317
- if (this.platform.config.credentials?.token) {
318
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
319
- this.SwitchToOpenAPI = true;
320
- await this.openAPIRefreshStatus();
292
+ await this.BLERefreshConnection(switchbot);
321
293
  }
322
294
  }
323
295
  async openAPIRefreshStatus() {
324
- if (this.platform.config.credentials?.token) {
325
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI refreshStatus`);
326
- try {
327
- const t = Date.now();
328
- const nonce = 'requestID';
329
- const data = this.platform.config.credentials?.token + t + nonce;
330
- const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
331
- const sign = signTerm.toString('base64');
332
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} sign: ${sign}`);
333
- const options = {
334
- hostname: settings_1.HostDomain,
335
- port: 443,
336
- path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
337
- method: 'GET',
338
- headers: {
339
- Authorization: this.platform.config.credentials?.token,
340
- sign: sign,
341
- nonce: nonce,
342
- t: t,
343
- 'Content-Type': 'application/json',
344
- },
345
- };
346
- const req = https_1.default.request(options, (res) => {
347
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
348
- let rawData = '';
349
- res.on('data', (d) => {
350
- rawData += d;
351
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} d: ${d}`);
352
- });
353
- res.on('end', () => {
354
- try {
355
- this.deviceStatus = JSON.parse(rawData);
356
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
357
- this.openState = this.deviceStatus.body.openState;
358
- this.moveDetected = this.deviceStatus.body.moveDetected;
359
- this.brightness = this.deviceStatus.body.brightness;
360
- this.parseStatus();
361
- this.updateHomeKitCharacteristics();
362
- }
363
- catch (e) {
364
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} error message: ${e.message}`);
365
- }
366
- });
296
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
297
+ try {
298
+ const t = Date.now();
299
+ const nonce = 'requestID';
300
+ const data = this.platform.config.credentials?.token + t + nonce;
301
+ const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
302
+ const sign = signTerm.toString('base64');
303
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
304
+ const options = {
305
+ hostname: settings_1.HostDomain,
306
+ port: 443,
307
+ path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
308
+ method: 'GET',
309
+ headers: {
310
+ Authorization: this.platform.config.credentials?.token,
311
+ sign: sign,
312
+ nonce: nonce,
313
+ t: t,
314
+ 'Content-Type': 'application/json',
315
+ },
316
+ };
317
+ const req = https_1.default.request(options, (res) => {
318
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
319
+ let rawData = '';
320
+ res.on('data', (d) => {
321
+ rawData += d;
322
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
367
323
  });
368
- req.on('error', (e) => {
369
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} error message: ${e.message}`);
324
+ res.on('end', () => {
325
+ try {
326
+ this.deviceStatus = JSON.parse(rawData);
327
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
328
+ this.openState = this.deviceStatus.body.openState;
329
+ this.moveDetected = this.deviceStatus.body.moveDetected;
330
+ this.brightness = this.deviceStatus.body.brightness;
331
+ this.openAPIparseStatus();
332
+ this.updateHomeKitCharacteristics();
333
+ }
334
+ catch (e) {
335
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
336
+ }
370
337
  });
371
- req.end();
372
- }
373
- catch (e) {
374
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
375
- if (this.deviceLogging.includes('debug')) {
376
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
377
- ` Error Message: ${JSON.stringify(e.message)}`);
378
- }
379
- this.apiError(e);
380
- }
338
+ });
339
+ req.on('error', (e) => {
340
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
341
+ });
342
+ req.end();
343
+ }
344
+ catch (e) {
345
+ this.apiError(e);
346
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
347
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
381
348
  }
382
349
  }
383
350
  /**
@@ -385,129 +352,169 @@ class Contact {
385
352
  */
386
353
  async updateHomeKitCharacteristics() {
387
354
  if (this.ContactSensorState === undefined) {
388
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
355
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
389
356
  }
390
357
  else {
358
+ this.accessory.context.ContactSensorState = this.ContactSensorState;
391
359
  this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
392
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
360
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
393
361
  }
394
362
  if (!this.device.contact?.hide_motionsensor) {
395
363
  if (this.MotionDetected === undefined) {
396
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
364
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
397
365
  }
398
366
  else {
367
+ this.accessory.context.MotionDetected = this.MotionDetected;
399
368
  this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
400
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
369
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
401
370
  }
402
371
  }
403
372
  if (!this.device.contact?.hide_lightsensor) {
404
373
  if (this.CurrentAmbientLightLevel === undefined) {
405
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
374
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
406
375
  }
407
376
  else {
377
+ this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
408
378
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
409
- this.debugLog(`Contact Sensor: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
379
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
380
+ + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
410
381
  }
411
382
  }
412
- if (this.device.ble) {
383
+ if (this.BLE) {
413
384
  if (this.BatteryLevel === undefined) {
414
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
385
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
415
386
  }
416
387
  else {
388
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
417
389
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
418
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
390
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
419
391
  }
420
392
  if (this.StatusLowBattery === undefined) {
421
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
393
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
422
394
  }
423
395
  else {
396
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
424
397
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
425
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
398
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
426
399
  }
427
400
  }
428
401
  }
429
- async apiError(e) {
430
- this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
431
- if (!this.device.contact?.hide_motionsensor) {
432
- this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
433
- }
434
- if (!this.device.contact?.hide_lightsensor) {
435
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
436
- }
437
- if (this.device.ble) {
438
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
439
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
402
+ async getCustomBLEAddress(switchbot) {
403
+ if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
404
+ (async () => {
405
+ // Start to monitor advertisement packets
406
+ await switchbot.startScan({
407
+ model: 'd',
408
+ });
409
+ // Set an event handler
410
+ switchbot.onadvertisement = (ad) => {
411
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
412
+ };
413
+ await switchbot.wait(10000);
414
+ // Stop to monitor
415
+ switchbot.stopScan();
416
+ })();
440
417
  }
441
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
442
418
  }
443
- async config(device) {
444
- let config = {};
445
- if (device.contact) {
446
- config = device.contact;
447
- }
448
- if (device.ble) {
449
- config['ble'] = device.ble;
450
- }
451
- if (device.logging !== undefined) {
452
- config['logging'] = device.logging;
453
- }
454
- if (device.refreshRate !== undefined) {
455
- config['refreshRate'] = device.refreshRate;
419
+ async BLERefreshConnection(switchbot) {
420
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
421
+ if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
422
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
423
+ await this.openAPIRefreshStatus();
456
424
  }
457
- if (device.scanDuration !== undefined) {
458
- config['scanDuration'] = device.scanDuration;
425
+ }
426
+ minLux() {
427
+ if (this.device.contact?.set_minLux) {
428
+ this.set_minLux = this.device.contact.set_minLux;
459
429
  }
460
- if (Object.entries(config).length !== 0) {
461
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
430
+ else {
431
+ this.set_minLux = 1;
462
432
  }
433
+ return this.set_minLux;
463
434
  }
464
- async refreshRate(device) {
465
- if (device.refreshRate) {
466
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
467
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
435
+ maxLux() {
436
+ if (this.device.contact?.set_maxLux) {
437
+ this.set_maxLux = this.device.contact.set_maxLux;
468
438
  }
469
- else if (this.platform.config.options.refreshRate) {
470
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
471
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
439
+ else {
440
+ this.set_maxLux = 6001;
472
441
  }
442
+ return this.set_maxLux;
473
443
  }
474
444
  async scan(device) {
475
445
  if (device.scanDuration) {
476
446
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
477
- if (device.ble) {
478
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
447
+ if (this.BLE) {
448
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
479
449
  }
480
450
  }
481
451
  else {
482
452
  this.scanDuration = this.accessory.context.scanDuration = 1;
483
- if (this.device.ble) {
484
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
453
+ if (this.BLE) {
454
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
485
455
  }
486
456
  }
487
457
  }
488
- async logs(device) {
489
- if (this.platform.debugMode) {
490
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
491
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
458
+ async statusCode({ res }) {
459
+ switch (res.statusCode) {
460
+ case 151:
461
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
462
+ break;
463
+ case 152:
464
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
465
+ break;
466
+ case 160:
467
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
468
+ break;
469
+ case 161:
470
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
471
+ this.offlineOff();
472
+ break;
473
+ case 171:
474
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
475
+ this.offlineOff();
476
+ break;
477
+ case 190:
478
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
479
+ ` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
480
+ break;
481
+ case 100:
482
+ if (this.platform.debugMode) {
483
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
484
+ }
485
+ break;
486
+ default:
487
+ if (this.platform.debugMode) {
488
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
489
+ }
492
490
  }
493
- else if (device.logging) {
494
- this.deviceLogging = this.accessory.context.logging = device.logging;
495
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
491
+ }
492
+ async offlineOff() {
493
+ if (this.device.offline) {
494
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
495
+ this.contactSensorservice.getCharacteristic(this.platform.Characteristic.ContactSensorState).updateValue(this.ContactSensorState);
496
+ await this.updateHomeKitCharacteristics();
496
497
  }
497
- else if (this.platform.config.options?.logging) {
498
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
499
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
498
+ }
499
+ async apiError(e) {
500
+ this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
501
+ if (!this.device.contact?.hide_motionsensor) {
502
+ this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
500
503
  }
501
- else {
502
- this.deviceLogging = this.accessory.context.logging = 'standard';
503
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
504
+ if (!this.device.contact?.hide_lightsensor) {
505
+ this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
506
+ }
507
+ if (this.BLE) {
508
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
509
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
504
510
  }
505
511
  }
506
512
  FirmwareRevision(accessory, device) {
507
513
  let FirmwareRevision;
508
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
509
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
510
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
514
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
515
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
516
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
517
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
511
518
  if (accessory.context.FirmwareRevision) {
512
519
  FirmwareRevision = accessory.context.FirmwareRevision;
513
520
  }
@@ -519,23 +526,71 @@ class Contact {
519
526
  }
520
527
  return FirmwareRevision;
521
528
  }
522
- minLux() {
523
- if (this.device.contact?.set_minLux) {
524
- this.set_minLux = this.device.contact.set_minLux;
529
+ async context() {
530
+ if (this.MotionDetected === undefined) {
531
+ this.MotionDetected = false;
525
532
  }
526
533
  else {
527
- this.set_minLux = 1;
534
+ this.MotionDetected = this.accessory.context.MotionDetected;
535
+ }
536
+ if (this.ContactSensorState === undefined) {
537
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
538
+ }
539
+ else {
540
+ this.ContactSensorState = this.accessory.context.ContactSensorState;
528
541
  }
529
- return this.set_minLux;
530
542
  }
531
- maxLux() {
532
- if (this.device.contact?.set_maxLux) {
533
- this.set_maxLux = this.device.contact.set_maxLux;
543
+ async refreshRate(device) {
544
+ if (device.refreshRate) {
545
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
546
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
547
+ }
548
+ else if (this.platform.config.options.refreshRate) {
549
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
550
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
551
+ }
552
+ }
553
+ async config(device) {
554
+ let config = {};
555
+ if (device.contact) {
556
+ config = device.contact;
557
+ }
558
+ if (device.connectionType !== undefined) {
559
+ config['connectionType'] = device.connectionType;
560
+ }
561
+ if (device.external !== undefined) {
562
+ config['external'] = device.external;
563
+ }
564
+ if (device.logging !== undefined) {
565
+ config['logging'] = device.logging;
566
+ }
567
+ if (device.refreshRate !== undefined) {
568
+ config['refreshRate'] = device.refreshRate;
569
+ }
570
+ if (device.scanDuration !== undefined) {
571
+ config['scanDuration'] = device.scanDuration;
572
+ }
573
+ if (Object.entries(config).length !== 0) {
574
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
575
+ }
576
+ }
577
+ async logs(device) {
578
+ if (this.platform.debugMode) {
579
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
580
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
581
+ }
582
+ else if (device.logging) {
583
+ this.deviceLogging = this.accessory.context.logging = device.logging;
584
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
585
+ }
586
+ else if (this.platform.config.options?.logging) {
587
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
588
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
534
589
  }
535
590
  else {
536
- this.set_maxLux = 6001;
591
+ this.deviceLogging = this.accessory.context.logging = 'standard';
592
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
537
593
  }
538
- return this.set_maxLux;
539
594
  }
540
595
  /**
541
596
  * Logging for Device
@@ -550,11 +605,25 @@ class Contact {
550
605
  this.platform.log.warn(String(...log));
551
606
  }
552
607
  }
608
+ debugWarnLog(...log) {
609
+ if (this.enablingDeviceLogging()) {
610
+ if (this.deviceLogging?.includes('debug')) {
611
+ this.platform.log.warn('[DEBUG]', String(...log));
612
+ }
613
+ }
614
+ }
553
615
  errorLog(...log) {
554
616
  if (this.enablingDeviceLogging()) {
555
617
  this.platform.log.error(String(...log));
556
618
  }
557
619
  }
620
+ debugErrorLog(...log) {
621
+ if (this.enablingDeviceLogging()) {
622
+ if (this.deviceLogging?.includes('debug')) {
623
+ this.platform.log.error('[DEBUG]', String(...log));
624
+ }
625
+ }
626
+ }
558
627
  debugLog(...log) {
559
628
  if (this.enablingDeviceLogging()) {
560
629
  if (this.deviceLogging === 'debug') {