@switchbot/homebridge-switchbot 3.5.0-beta.62 → 3.5.0-beta.64

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 (113) hide show
  1. package/dist/device/blindtilt.d.ts.map +1 -1
  2. package/dist/device/blindtilt.js +9 -6
  3. package/dist/device/blindtilt.js.map +1 -1
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +33 -22
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/ceilinglight.d.ts.map +1 -1
  8. package/dist/device/ceilinglight.js +4 -3
  9. package/dist/device/ceilinglight.js.map +1 -1
  10. package/dist/device/colorbulb.js +3 -2
  11. package/dist/device/colorbulb.js.map +1 -1
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +14 -10
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts.map +1 -1
  16. package/dist/device/curtain.js +11 -8
  17. package/dist/device/curtain.js.map +1 -1
  18. package/dist/device/device.js +11 -10
  19. package/dist/device/device.js.map +1 -1
  20. package/dist/device/fan.d.ts.map +1 -1
  21. package/dist/device/fan.js +7 -5
  22. package/dist/device/fan.js.map +1 -1
  23. package/dist/device/hub.d.ts.map +1 -1
  24. package/dist/device/hub.js +9 -6
  25. package/dist/device/hub.js.map +1 -1
  26. package/dist/device/humidifier.d.ts.map +1 -1
  27. package/dist/device/humidifier.js +6 -4
  28. package/dist/device/humidifier.js.map +1 -1
  29. package/dist/device/iosensor.d.ts.map +1 -1
  30. package/dist/device/iosensor.js +10 -6
  31. package/dist/device/iosensor.js.map +1 -1
  32. package/dist/device/lightstrip.d.ts.map +1 -1
  33. package/dist/device/lightstrip.js +3 -2
  34. package/dist/device/lightstrip.js.map +1 -1
  35. package/dist/device/lock.d.ts.map +1 -1
  36. package/dist/device/lock.js +12 -8
  37. package/dist/device/lock.js.map +1 -1
  38. package/dist/device/meter.d.ts.map +1 -1
  39. package/dist/device/meter.js +8 -5
  40. package/dist/device/meter.js.map +1 -1
  41. package/dist/device/meterplus.d.ts.map +1 -1
  42. package/dist/device/meterplus.js +9 -6
  43. package/dist/device/meterplus.js.map +1 -1
  44. package/dist/device/motion.d.ts.map +1 -1
  45. package/dist/device/motion.js +10 -6
  46. package/dist/device/motion.js.map +1 -1
  47. package/dist/device/plug.d.ts.map +1 -1
  48. package/dist/device/plug.js +3 -2
  49. package/dist/device/plug.js.map +1 -1
  50. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  51. package/dist/device/robotvacuumcleaner.js +6 -4
  52. package/dist/device/robotvacuumcleaner.js.map +1 -1
  53. package/dist/device/waterdetector.d.ts.map +1 -1
  54. package/dist/device/waterdetector.js +6 -4
  55. package/dist/device/waterdetector.js.map +1 -1
  56. package/dist/irdevice/airconditioner.d.ts +1 -1
  57. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  58. package/dist/irdevice/airconditioner.js +65 -83
  59. package/dist/irdevice/airconditioner.js.map +1 -1
  60. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  61. package/dist/irdevice/airpurifier.js +37 -19
  62. package/dist/irdevice/airpurifier.js.map +1 -1
  63. package/dist/irdevice/camera.d.ts.map +1 -1
  64. package/dist/irdevice/camera.js +13 -11
  65. package/dist/irdevice/camera.js.map +1 -1
  66. package/dist/irdevice/fan.d.ts.map +1 -1
  67. package/dist/irdevice/fan.js +25 -15
  68. package/dist/irdevice/fan.js.map +1 -1
  69. package/dist/irdevice/light.d.ts.map +1 -1
  70. package/dist/irdevice/light.js +50 -24
  71. package/dist/irdevice/light.js.map +1 -1
  72. package/dist/irdevice/other.d.ts +1 -1
  73. package/dist/irdevice/other.d.ts.map +1 -1
  74. package/dist/irdevice/other.js +180 -138
  75. package/dist/irdevice/other.js.map +1 -1
  76. package/dist/irdevice/tv.d.ts.map +1 -1
  77. package/dist/irdevice/tv.js +50 -59
  78. package/dist/irdevice/tv.js.map +1 -1
  79. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.js +13 -10
  81. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  82. package/dist/irdevice/waterheater.d.ts.map +1 -1
  83. package/dist/irdevice/waterheater.js +14 -13
  84. package/dist/irdevice/waterheater.js.map +1 -1
  85. package/package.json +1 -1
  86. package/src/device/blindtilt.ts +9 -6
  87. package/src/device/bot.ts +33 -22
  88. package/src/device/ceilinglight.ts +4 -3
  89. package/src/device/colorbulb.ts +3 -3
  90. package/src/device/contact.ts +14 -10
  91. package/src/device/curtain.ts +11 -8
  92. package/src/device/device.ts +11 -11
  93. package/src/device/fan.ts +7 -5
  94. package/src/device/hub.ts +9 -6
  95. package/src/device/humidifier.ts +6 -4
  96. package/src/device/iosensor.ts +10 -6
  97. package/src/device/lightstrip.ts +3 -2
  98. package/src/device/lock.ts +12 -8
  99. package/src/device/meter.ts +8 -5
  100. package/src/device/meterplus.ts +9 -6
  101. package/src/device/motion.ts +10 -6
  102. package/src/device/plug.ts +3 -2
  103. package/src/device/robotvacuumcleaner.ts +6 -4
  104. package/src/device/waterdetector.ts +6 -4
  105. package/src/irdevice/airconditioner.ts +73 -86
  106. package/src/irdevice/airpurifier.ts +43 -23
  107. package/src/irdevice/camera.ts +14 -13
  108. package/src/irdevice/fan.ts +26 -18
  109. package/src/irdevice/light.ts +65 -45
  110. package/src/irdevice/other.ts +210 -154
  111. package/src/irdevice/tv.ts +57 -70
  112. package/src/irdevice/vacuumcleaner.ts +14 -12
  113. package/src/irdevice/waterheater.ts +15 -16
@@ -67,8 +67,9 @@ export class BlindTilt extends deviceBase {
67
67
  this.setNewTarget = false;
68
68
 
69
69
  // Initialize WindowCovering Service
70
+ accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
70
71
  this.WindowCovering = {
71
- Name: accessory.context.WindowCoveringName ?? accessory.displayName,
72
+ Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
72
73
  Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
73
74
  PositionState: accessory.context.PositionState ?? this.hap.Characteristic.PositionState.STOPPED,
74
75
  TargetPosition: accessory.context.TargetPosition ?? 100,
@@ -76,6 +77,7 @@ export class BlindTilt extends deviceBase {
76
77
  TargetHorizontalTiltAngle: accessory.context.TargetHorizontalTiltAngle ?? 90,
77
78
  CurrentHorizontalTiltAngle: accessory.context.CurrentHorizontalTiltAngle ?? 90,
78
79
  };
80
+ accessory.context.WindowCovering = this.WindowCovering as object;
79
81
 
80
82
  // Initialize WindowCovering Characteristics
81
83
  this.WindowCovering.Service
@@ -117,7 +119,6 @@ export class BlindTilt extends deviceBase {
117
119
  return this.WindowCovering.TargetHorizontalTiltAngle;
118
120
  })
119
121
  .onSet(this.TargetHorizontalTiltAngleSet.bind(this));
120
- accessory.context.WindowCoveringName = this.WindowCovering.Name;
121
122
 
122
123
  // Initialize WindowCovering CurrentHorizontalTiltAngle Characteristic
123
124
  this.WindowCovering.Service
@@ -132,19 +133,20 @@ export class BlindTilt extends deviceBase {
132
133
  });
133
134
 
134
135
  // Initialize Battery Service
136
+ accessory.context.Battery = accessory.context.Battery ?? {};
135
137
  this.Battery = {
136
- Name: accessory.context.BatteryName ?? `${accessory.displayName} Battery`,
138
+ Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
137
139
  Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
138
140
  BatteryLevel: accessory.context.BatteryLevel ?? 100,
139
141
  StatusLowBattery: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
140
142
  ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGING,
141
143
  };
144
+ accessory.context.Battery = this.Battery as object;
142
145
 
143
146
  // Initialize Battery Name Characteristic
144
147
  this.Battery.Service
145
148
  .setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
146
149
  .setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
147
- accessory.context.BatteryName = this.Battery.Name;
148
150
 
149
151
  // Initialize LightSensor Service
150
152
  if (device.blindTilt?.hide_lightsensor) {
@@ -152,11 +154,13 @@ export class BlindTilt extends deviceBase {
152
154
  this.LightSensor!.Service = accessory.getService(this.hap.Service.LightSensor) as Service;
153
155
  accessory.removeService(this.LightSensor!.Service);
154
156
  } else {
157
+ accessory.context.LightSensor = accessory.context.LightSensor ?? {};
155
158
  this.LightSensor = {
156
- Name: accessory.context.LightSensorName ?? `${accessory.displayName} Light Sensor`,
159
+ Name: accessory.context.LightSensor.Name ?? `${accessory.displayName} Light Sensor`,
157
160
  Service: accessory.getService(this.hap.Service.LightSensor) ?? accessory.addService(this.hap.Service.LightSensor) as Service,
158
161
  CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
159
162
  };
163
+ accessory.context.LightSensor = this.LightSensor as object;
160
164
 
161
165
  // Initialize LightSensor Characteristics
162
166
  this.LightSensor.Service
@@ -166,7 +170,6 @@ export class BlindTilt extends deviceBase {
166
170
  .onGet(() => {
167
171
  return this.LightSensor?.CurrentAmbientLightLevel ?? 0.0001;
168
172
  });
169
- accessory.context.LightSensorName = this.LightSensor.Name;
170
173
  }
171
174
 
172
175
  // Retrieve initial values and updateHomekit
package/src/device/bot.ts CHANGED
@@ -111,29 +111,32 @@ export class Bot extends deviceBase {
111
111
  this.doBotUpdate = new Subject();
112
112
  this.botUpdateInProgress = false;
113
113
 
114
+ accessory.context.Battery = accessory.context.Battery ?? {};
114
115
  // Initialize Battery property
115
116
  this.Battery = {
116
- Name: accessory.context.BatteryName ?? `${accessory.displayName} Battery`,
117
+ Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
117
118
  Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
118
119
  BatteryLevel: accessory.context.BatteryLevel ?? 100,
119
120
  StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
120
121
  };
122
+ accessory.context.Battery = this.Battery as object;
121
123
 
122
124
  // Initialize Battery Characteristics
123
125
  this.Battery.Service
124
126
  .setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
125
127
  .setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
126
128
  .setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
127
- accessory.context.BatteryName = this.Battery.Name;
128
129
 
129
130
  // deviceType
130
131
  if (this.botDeviceType === 'switch') {
131
132
  // Initialize Switch Service
133
+ accessory.context.Switch = accessory.context.Switch ?? {};
132
134
  this.Switch = {
133
- Name: accessory.context.Name ?? accessory.displayName,
135
+ Name: accessory.context.Switch.Name ?? accessory.displayName,
134
136
  Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
135
137
  On: accessory.context.On ?? false,
136
138
  };
139
+ accessory.context.Switch = this.Switch as object;
137
140
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
138
141
 
139
142
  // Initialize Switch Characteristics
@@ -145,7 +148,6 @@ export class Bot extends deviceBase {
145
148
  return this.Switch!.On;
146
149
  })
147
150
  .onSet(this.OnSet.bind(this));
148
- accessory.context.Name = this.Switch.Name;
149
151
 
150
152
  // Remove other services
151
153
  this.removeFanService(accessory);
@@ -159,11 +161,13 @@ export class Bot extends deviceBase {
159
161
  this.removeStatefulProgrammableSwitchService(accessory);
160
162
  } else if (this.botDeviceType === 'garagedoor') {
161
163
  // Initialize GarageDoor Service
164
+ accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
162
165
  this.GarageDoor = {
163
- Name: accessory.context.Name ?? accessory.displayName,
166
+ Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
164
167
  Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener) as Service,
165
168
  On: accessory.context.On ?? false,
166
169
  };
170
+ accessory.context.GarageDoor = this.GarageDoor as object;
167
171
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
168
172
 
169
173
  // Initialize GarageDoor Characteristics
@@ -180,7 +184,6 @@ export class Bot extends deviceBase {
180
184
  return this.GarageDoor!.On;
181
185
  })
182
186
  .onSet(this.OnSet.bind(this));
183
- accessory.context.Name = this.GarageDoor.Name;
184
187
 
185
188
  // Remove other services
186
189
  this.removeFanService(accessory);
@@ -194,11 +197,13 @@ export class Bot extends deviceBase {
194
197
  this.removeStatefulProgrammableSwitchService(accessory);
195
198
  } else if (this.botDeviceType === 'door') {
196
199
  // Initialize Door Service
200
+ accessory.context.Door = accessory.context.Door ?? {};
197
201
  this.Door = {
198
- Name: accessory.context.Name ?? accessory.displayName,
202
+ Name: accessory.context.Door.Name ?? accessory.displayName,
199
203
  Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door) as Service,
200
204
  On: accessory.context.On ?? false,
201
205
  };
206
+ accessory.context.Door = this.Door as object;
202
207
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
203
208
 
204
209
  // Initialize Door Characteristics
@@ -215,7 +220,6 @@ export class Bot extends deviceBase {
215
220
  return this.Door!.On;
216
221
  })
217
222
  .onSet(this.OnSet.bind(this));
218
- accessory.context.Name = this.Door.Name;
219
223
 
220
224
  // Remove other services
221
225
  this.removeFanService(accessory);
@@ -229,11 +233,13 @@ export class Bot extends deviceBase {
229
233
  this.removeStatefulProgrammableSwitchService(accessory);
230
234
  } else if (this.botDeviceType === 'window') {
231
235
  // Initialize Window Service
236
+ accessory.context.Window = accessory.context.Window ?? {};
232
237
  this.Window = {
233
- Name: accessory.context.Name ?? accessory.displayName,
238
+ Name: accessory.context.Window.Name ?? accessory.displayName,
234
239
  Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window) as Service,
235
240
  On: accessory.context.On ?? false,
236
241
  };
242
+ accessory.context.Window = this.Window as object;
237
243
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
238
244
 
239
245
  // Initialize Window Characteristics
@@ -250,7 +256,6 @@ export class Bot extends deviceBase {
250
256
  return this.Window!.On;
251
257
  })
252
258
  .onSet(this.OnSet.bind(this));
253
- accessory.context.Name = this.Window.Name;
254
259
 
255
260
  // Remove other services
256
261
  this.removeFanService(accessory);
@@ -264,11 +269,13 @@ export class Bot extends deviceBase {
264
269
  this.removeStatefulProgrammableSwitchService(accessory);
265
270
  } else if (this.botDeviceType === 'windowcovering') {
266
271
  // Initialize WindowCovering Service
272
+ accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
267
273
  this.WindowCovering = {
268
- Name: accessory.context.Name ?? accessory.displayName,
274
+ Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
269
275
  Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
270
276
  On: accessory.context.On ?? false,
271
277
  };
278
+ accessory.context.WindowCovering = this.WindowCovering as object;
272
279
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
273
280
 
274
281
  // Initialize WindowCovering Characteristics
@@ -285,7 +292,6 @@ export class Bot extends deviceBase {
285
292
  return this.WindowCovering!.On;
286
293
  })
287
294
  .onSet(this.OnSet.bind(this));
288
- accessory.context.Name = this.WindowCovering.Name;
289
295
 
290
296
  // Remove other services
291
297
  this.removeFanService(accessory);
@@ -299,11 +305,13 @@ export class Bot extends deviceBase {
299
305
  this.removeStatefulProgrammableSwitchService(accessory);
300
306
  } else if (this.botDeviceType === 'lock') {
301
307
  // Initialize Lock Service
308
+ accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
302
309
  this.LockMechanism = {
303
- Name: accessory.context.Name ?? accessory.displayName,
310
+ Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
304
311
  Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
305
312
  On: accessory.context.On ?? false,
306
313
  };
314
+ accessory.context.LockMechanism = this.LockMechanism as object;
307
315
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
308
316
 
309
317
  // Initialize Lock Characteristics
@@ -314,7 +322,6 @@ export class Bot extends deviceBase {
314
322
  return this.LockMechanism!.On;
315
323
  })
316
324
  .onSet(this.OnSet.bind(this));
317
- accessory.context.Name = this.LockMechanism.Name;
318
325
 
319
326
  // Remove other services
320
327
  this.removeFanService(accessory);
@@ -328,11 +335,13 @@ export class Bot extends deviceBase {
328
335
  this.removeStatefulProgrammableSwitchService(accessory);
329
336
  } else if (this.botDeviceType === 'faucet') {
330
337
  // Initialize Faucet Service
338
+ accessory.context.Faucet = accessory.context.Faucet ?? {};
331
339
  this.Faucet = {
332
- Name: accessory.context.Name ?? accessory.displayName,
340
+ Name: accessory.context.Faucet.Name ?? accessory.displayName,
333
341
  Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet) as Service,
334
342
  On: accessory.context.On ?? false,
335
343
  };
344
+ accessory.context.Faucet = this.Faucet as object;
336
345
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
337
346
 
338
347
  // Initialize Faucet Characteristics
@@ -343,7 +352,6 @@ export class Bot extends deviceBase {
343
352
  return this.Faucet!.On;
344
353
  })
345
354
  .onSet(this.OnSet.bind(this));
346
- accessory.context.Name = this.Faucet.Name;
347
355
 
348
356
  // Remove other services
349
357
  this.removeFanService(accessory);
@@ -357,11 +365,13 @@ export class Bot extends deviceBase {
357
365
  this.removeStatefulProgrammableSwitchService(accessory);
358
366
  } else if (this.botDeviceType === 'fan') {
359
367
  // Initialize Fan Service
368
+ accessory.context.Fan = accessory.context.Fan ?? {};
360
369
  this.Fan = {
361
- Name: accessory.context.Name ?? accessory.displayName,
370
+ Name: accessory.context.Fan.Name ?? accessory.displayName,
362
371
  Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
363
372
  On: accessory.context.On ?? false,
364
373
  };
374
+ accessory.context.Fan = this.Fan as object;
365
375
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
366
376
 
367
377
  // Initialize Fan Characteristics
@@ -372,7 +382,6 @@ export class Bot extends deviceBase {
372
382
  return this.Fan!.On;
373
383
  })
374
384
  .onSet(this.OnSet.bind(this));
375
- accessory.context.Name = this.Fan.Name;
376
385
 
377
386
  // Remove other services
378
387
  this.removeLockService(accessory);
@@ -386,12 +395,14 @@ export class Bot extends deviceBase {
386
395
  this.removeStatefulProgrammableSwitchService(accessory);
387
396
  } else if (this.botDeviceType === 'stateful') {
388
397
  // Initialize StatefulProgrammableSwitch Service
398
+ accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
389
399
  this.StatefulProgrammableSwitch = {
390
- Name: accessory.context.Name ?? accessory.displayName,
400
+ Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
391
401
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
392
402
  ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
393
403
  On: accessory.context.On ?? false,
394
404
  };
405
+ accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
395
406
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
396
407
 
397
408
  // Initialize StatefulProgrammableSwitch Characteristics
@@ -402,7 +413,6 @@ export class Bot extends deviceBase {
402
413
  return this.StatefulProgrammableSwitch!.On;
403
414
  })
404
415
  .onSet(this.OnSet.bind(this));
405
- accessory.context.Name = this.StatefulProgrammableSwitch.Name;
406
416
 
407
417
  // Remove other services
408
418
  this.removeFanService(accessory);
@@ -416,11 +426,13 @@ export class Bot extends deviceBase {
416
426
  this.removeWindowCoveringService(accessory);
417
427
  } else {
418
428
  // Initialize Switch property
429
+ accessory.context.Outlet = accessory.context.Outlet ?? {};
419
430
  this.Outlet = {
420
- Name: accessory.context.Name ?? accessory.displayName,
431
+ Name: accessory.context.Outlet.Name ?? accessory.displayName,
421
432
  Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
422
433
  On: accessory.context.On ?? false,
423
434
  };
435
+ accessory.context.Outlet = this.Outlet as object;
424
436
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
425
437
 
426
438
  // Initialize Outlet Characteristics
@@ -431,7 +443,6 @@ export class Bot extends deviceBase {
431
443
  return this.Outlet!.On;
432
444
  })
433
445
  .onSet(this.OnSet.bind(this));
434
- accessory.context.Name = this.Outlet.Name;
435
446
 
436
447
  // Remove other services
437
448
  this.removeFanService(accessory);
@@ -51,9 +51,10 @@ export class CeilingLight extends deviceBase {
51
51
  this.doCeilingLightUpdate = new Subject();
52
52
  this.ceilingLightUpdateInProgress = false;
53
53
 
54
- // Initialize LightBulb property
54
+ // Initialize LightBulb Service
55
+ accessory.context.LightBulb = accessory.context.LightBulb ?? {};
55
56
  this.LightBulb = {
56
- Name: accessory.context.LightBulbName ?? accessory.displayName,
57
+ Name: accessory.context.LightBul.bName ?? accessory.displayName,
57
58
  Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
58
59
  On: accessory.context.On ?? false,
59
60
  Hue: accessory.context.Hue ?? 0,
@@ -61,6 +62,7 @@ export class CeilingLight extends deviceBase {
61
62
  Brightness: accessory.context.Brightness ?? 0,
62
63
  ColorTemperature: accessory.context.ColorTemperature ?? 140,
63
64
  };
65
+ accessory.context.LightBulb = this.LightBulb as object;
64
66
 
65
67
  // Adaptive Lighting
66
68
  if (this.adaptiveLightingShift === -1 && accessory.context.adaptiveLighting) {
@@ -141,7 +143,6 @@ export class CeilingLight extends deviceBase {
141
143
  return this.LightBulb.Saturation;
142
144
  })
143
145
  .onSet(this.SaturationSet.bind(this));
144
- accessory.context.LightBulbName = this.LightBulb.Name;
145
146
 
146
147
  // Retrieve initial values and updateHomekit
147
148
  this.refreshStatus();
@@ -51,9 +51,8 @@ export class ColorBulb extends deviceBase {
51
51
  this.doColorBulbUpdate = new Subject();
52
52
  this.colorBulbUpdateInProgress = false;
53
53
 
54
- accessory.context.LightBulb = {};
55
-
56
54
  // Initialize LightBulb property
55
+ accessory.context.LightBulb = accessory.context.LightBulb ?? {};
57
56
  this.LightBulb = {
58
57
  Name: accessory.context.LightBulb.Name ?? accessory.displayName,
59
58
  Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
@@ -63,6 +62,8 @@ export class ColorBulb extends deviceBase {
63
62
  Brightness: accessory.context.Brightness ?? 0,
64
63
  ColorTemperature: accessory.context.ColorTemperature ?? 140,
65
64
  };
65
+ accessory.context.LightBulb = this.LightBulb as object;
66
+ this.errorLog(`${device.deviceType}: ${accessory.displayName} LightBulb Context: ${JSON.stringify(accessory.context.LightBulb)}`);
66
67
 
67
68
  // Adaptive Lighting
68
69
  if (this.adaptiveLightingShift === -1 && accessory.context.adaptiveLighting) {
@@ -139,7 +140,6 @@ export class ColorBulb extends deviceBase {
139
140
  return this.LightBulb.Saturation;
140
141
  })
141
142
  .onSet(this.SaturationSet.bind(this));
142
- accessory.context.LightBulb.Name = this.LightBulb.Name;
143
143
 
144
144
  // Retrieve initial values and updateHomekit
145
145
  this.refreshStatus();
@@ -57,12 +57,14 @@ export class Contact extends deviceBase {
57
57
  this.doContactUpdate = new Subject();
58
58
  this.contactUpdateInProgress = false;
59
59
 
60
- // Initialize Contact Sensor property
60
+ // Initialize Contact Sensor Service
61
+ accessory.context.ContactSensor = accessory.context.ContactSensor ?? {};
61
62
  this.ContactSensor = {
62
- Name: accessory.context.ContactSensorName ?? accessory.displayName,
63
+ Name: accessory.context.ContactSensor.Name ?? accessory.displayName,
63
64
  Service: accessory.getService(this.hap.Service.ContactSensor) ?? accessory.addService(this.hap.Service.ContactSensor) as Service,
64
65
  ContactSensorState: accessory.context.ContactSensorState ?? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED,
65
66
  };
67
+ accessory.context.ContactSensor = this.ContactSensor as object;
66
68
 
67
69
  // Initialize ContactSensor Characteristics
68
70
  this.ContactSensor.Service
@@ -72,15 +74,16 @@ export class Contact extends deviceBase {
72
74
  .onGet(() => {
73
75
  return this.ContactSensor.ContactSensorState;
74
76
  });
75
- accessory.context.ContactSensorName = this.ContactSensor.Name;
76
77
 
77
- // Initialize Battery property
78
+ // Initialize Battery Service
79
+ accessory.context.Battery = accessory.context.Battery ?? {};
78
80
  this.Battery = {
79
- Name: accessory.context.BatteryName ?? `${accessory.displayName} Battery`,
81
+ Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
80
82
  Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
81
83
  BatteryLevel: accessory.context.BatteryLevel ?? 100,
82
84
  StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
83
85
  };
86
+ accessory.context.Battery = this.Battery as object;
84
87
 
85
88
  // Initialize Battery Characteristics
86
89
  this.Battery.Service
@@ -97,7 +100,6 @@ export class Contact extends deviceBase {
97
100
  .onGet(() => {
98
101
  return this.Battery.StatusLowBattery;
99
102
  });
100
- accessory.context.BatteryName = this.Battery.Name;
101
103
 
102
104
  // Initialize Motion Sensor Service
103
105
  if (this.device.contact?.hide_motionsensor) {
@@ -105,11 +107,13 @@ export class Contact extends deviceBase {
105
107
  this.MotionSensor!.Service = accessory.getService(this.hap.Service.MotionSensor) as Service;
106
108
  accessory.removeService(this.MotionSensor!.Service);
107
109
  } else {
110
+ accessory.context.MotionSensor = accessory.context.MotionSensor ?? {};
108
111
  this.MotionSensor = {
109
- Name: accessory.context.MotionSensorName ?? `${accessory.displayName} Motion Sensor`,
112
+ Name: accessory.context.MotionSensor.Name ?? `${accessory.displayName} Motion Sensor`,
110
113
  Service: accessory.getService(this.hap.Service.MotionSensor) ?? accessory.addService(this.hap.Service.MotionSensor) as Service,
111
114
  MotionDetected: accessory.context.MotionDetected ?? false,
112
115
  };
116
+ accessory.context.MotionSensor = this.MotionSensor as object;
113
117
 
114
118
  // Motion Sensor Characteristics
115
119
  this.MotionSensor.Service
@@ -119,7 +123,6 @@ export class Contact extends deviceBase {
119
123
  .onGet(() => {
120
124
  return this.MotionSensor!.MotionDetected;
121
125
  });
122
- accessory.context.MotionSensorName = this.MotionSensor.Name;
123
126
  }
124
127
 
125
128
  // Initialize Light Sensor Service
@@ -128,11 +131,13 @@ export class Contact extends deviceBase {
128
131
  this.LightSensor!.Service = accessory.getService(this.hap.Service.LightSensor) as Service;
129
132
  accessory.removeService(this.LightSensor!.Service);
130
133
  } else {
134
+ accessory.context.LightSensor = accessory.context.LightSensor ?? {};
131
135
  this.LightSensor = {
132
- Name: accessory.context.LightSensorName ?? `${accessory.displayName} Light Sensor`,
136
+ Name: accessory.context.LightSensor.Name ?? `${accessory.displayName} Light Sensor`,
133
137
  Service: accessory.getService(this.hap.Service.LightSensor) ?? accessory.addService(this.hap.Service.LightSensor) as Service,
134
138
  CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
135
139
  };
140
+ accessory.context.LightSensor = this.LightSensor as object;
136
141
 
137
142
  // Light Sensor Characteristics
138
143
  this.LightSensor.Service
@@ -142,7 +147,6 @@ export class Contact extends deviceBase {
142
147
  .onGet(() => {
143
148
  return this.LightSensor!.CurrentAmbientLightLevel;
144
149
  });
145
- accessory.context.LightSensorName = this.LightSensor.Name;
146
150
  }
147
151
 
148
152
  // Retrieve initial values and updateHomekit
@@ -59,15 +59,17 @@ export class Curtain extends deviceBase {
59
59
  this.curtainUpdateInProgress = false;
60
60
  this.setNewTarget = false;
61
61
 
62
- // Initialize LightBulb property
62
+ // Initialize WindowCovering Service
63
+ accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
63
64
  this.WindowCovering = {
64
- Name: accessory.context.WindowCoveringName ?? accessory.displayName,
65
+ Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
65
66
  Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
66
67
  PositionState: accessory.context.PositionState ?? this.hap.Characteristic.PositionState.STOPPED,
67
68
  TargetPosition: accessory.context.TargetPosition ?? 100,
68
69
  CurrentPosition: accessory.context.CurrentPosition ?? 100,
69
70
  HoldPosition: accessory.context.HoldPosition ?? false,
70
71
  };
72
+ accessory.context.WindowCovering = this.WindowCovering as object;
71
73
 
72
74
  // Initialize WindowCovering Service
73
75
  this.WindowCovering.Service.
@@ -77,7 +79,6 @@ export class Curtain extends deviceBase {
77
79
  .onGet(() => {
78
80
  return this.WindowCovering.PositionState;
79
81
  });
80
- accessory.context.WindowCoveringName = this.WindowCovering.Name;
81
82
 
82
83
  // Initialize WindowCovering CurrentPosition
83
84
  this.WindowCovering.Service
@@ -114,14 +115,16 @@ export class Curtain extends deviceBase {
114
115
  })
115
116
  .onSet(this.HoldPositionSet.bind(this));
116
117
 
117
- // Initialize Battery property
118
+ // Initialize Battery Service
119
+ accessory.context.Battery = accessory.context.Battery ?? {};
118
120
  this.Battery = {
119
- Name: accessory.context.BatteryName ?? `${accessory.displayName} Battery`,
121
+ Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
120
122
  Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
121
123
  BatteryLevel: accessory.context.BatteryLevel ?? 100,
122
124
  StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
123
125
  ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGING,
124
126
  };
127
+ accessory.context.Battery = this.Battery as object;
125
128
 
126
129
  // Initialize Battery Service
127
130
  this.Battery.Service
@@ -130,7 +133,6 @@ export class Curtain extends deviceBase {
130
133
  .onGet(() => {
131
134
  return this.Battery.BatteryLevel;
132
135
  });
133
- accessory.context.BatteryName = this.Battery.Name;
134
136
 
135
137
  this.Battery.Service
136
138
  .getCharacteristic(this.hap.Characteristic.StatusLowBattery)
@@ -150,11 +152,13 @@ export class Curtain extends deviceBase {
150
152
  this.LightSensor!.Service = this.accessory.getService(this.hap.Service.LightSensor) as Service;
151
153
  accessory.removeService(this.LightSensor!.Service);
152
154
  } else {
155
+ accessory.context.LightSensor = accessory.context.LightSensor ?? {};
153
156
  this.LightSensor = {
154
- Name: accessory.context.LightSensorName ?? `${accessory.displayName} Light Sensor`,
157
+ Name: accessory.context.LightSensor.Name ?? `${accessory.displayName} Light Sensor`,
155
158
  Service: accessory.getService(this.hap.Service.LightSensor) ?? this.accessory.addService(this.hap.Service.LightSensor) as Service,
156
159
  CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
157
160
  };
161
+ accessory.context.LightSensor = this.LightSensor as object;
158
162
 
159
163
  // Initialize LightSensor Characteristic
160
164
  this.LightSensor.Service
@@ -164,7 +168,6 @@ export class Curtain extends deviceBase {
164
168
  .onGet(() => {
165
169
  return this.LightSensor!.CurrentAmbientLightLevel!;
166
170
  });
167
- accessory.context.LightSensorName = this.LightSensor.Name;
168
171
  }
169
172
 
170
173
  // Retrieve initial values and updateHomekit
@@ -549,19 +549,19 @@ export abstract class deviceBase {
549
549
  } else if (device.firmware === undefined && device.version === undefined && accessory.context.version === undefined) {
550
550
  device.version = this.platform.version;
551
551
  accessory.context.version = this.platform.version;
552
- } else {
552
+ } else if (accessory.context.device.version) {
553
+ accessory.context.version = accessory.context.device.version.replace(/^V|-.*$/g, '');
554
+ }else {
553
555
  accessory.context.version = device.version?.replace(/^V|-.*$/g, '');
554
556
  }
555
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${accessory.context.version}`);
556
- if (accessory.context.version) {
557
- this.accessory
558
- .getService(this.hap.Service.AccessoryInformation)!
559
- .setCharacteristic(this.hap.Characteristic.HardwareRevision, accessory.context.version)
560
- .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.version)
561
- .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
562
- .updateValue(this.accessory.context.version);
563
- }
564
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} Context: ${JSON.stringify(accessory.context)}`);
557
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${accessory.context.device.version}`);
558
+ this.accessory
559
+ .getService(this.hap.Service.AccessoryInformation)!
560
+ .setCharacteristic(this.hap.Characteristic.HardwareRevision, accessory.context.version)
561
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.version)
562
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
563
+ .updateValue(accessory.context.version);
564
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} Context: ${JSON.stringify(accessory.context.device)}`);
565
565
  }
566
566
 
567
567
  async statusCode(statusCode: number): Promise<void> {
package/src/device/fan.ts CHANGED
@@ -44,13 +44,15 @@ export class Fan extends deviceBase {
44
44
  this.plugUpdateInProgress = false;
45
45
 
46
46
  // Initialize Fan Service
47
+ accessory.context.Fan = accessory.context.Fan ?? {};
47
48
  this.Fan = {
48
- Name: accessory.context.FanName ?? accessory.displayName,
49
+ Name: accessory.context.Fan.Name ?? accessory.displayName,
49
50
  Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
50
51
  Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
51
52
  SwingMode: accessory.context.SwingMode ?? this.hap.Characteristic.SwingMode.SWING_DISABLED,
52
53
  RotationSpeed: accessory.context.RotationSpeed ?? 0,
53
54
  };
55
+ accessory.context.Fan = this.Fan as object;
54
56
 
55
57
  // Initialize Fan Service
56
58
  this.Fan.Service
@@ -75,16 +77,17 @@ export class Fan extends deviceBase {
75
77
  return this.Fan.SwingMode;
76
78
  })
77
79
  .onSet(this.SwingModeSet.bind(this));
78
- accessory.context.FanName = this.Fan.Name;
79
80
 
80
- // Initialize Battery property
81
+ // Initialize Battery Service
82
+ accessory.context.Battery = accessory.context.Battery ?? {};
81
83
  this.Battery = {
82
- Name: accessory.context.BatteryName ?? accessory.displayName,
84
+ Name: accessory.context.Battery.Name ?? accessory.displayName,
83
85
  Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
84
86
  BatteryLevel: accessory.context.BatteryLevel ?? 100,
85
87
  StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
86
88
  ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGING,
87
89
  };
90
+ accessory.context.Battery = this.Battery as object;
88
91
 
89
92
  // Initialize Battery Service
90
93
  this.Battery.Service
@@ -107,7 +110,6 @@ export class Fan extends deviceBase {
107
110
  .onGet(() => {
108
111
  return this.Battery.StatusLowBattery;
109
112
  });
110
- accessory.context.BatteryName = this.Battery.Name;
111
113
 
112
114
  // Retrieve initial values and updateHomekit
113
115
  this.refreshStatus();