homebridge-lib 5.1.24-1 → 5.1.24-2

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 (2) hide show
  1. package/lib/Platform.js +28 -17
  2. package/package.json +1 -1
package/lib/Platform.js CHANGED
@@ -498,19 +498,8 @@ class Platform extends homebridgeLib.Delegate {
498
498
  id: id,
499
499
  name: name,
500
500
  logLevel: this.logLevel,
501
- notExposed: true,
502
501
  context: {}
503
502
  }
504
- } else {
505
- // Allow for plugin to change delegate class, version, and name.
506
- accessory.context.className = className
507
- accessory.context.version = version
508
- accessory.context.name = name
509
- if (accessory.context.logLevel == null) {
510
- accessory.context.logLevel = this.logLevel
511
- }
512
- }
513
- if (accessory.context.notExposed) {
514
503
  delegate.once('initialised', () => {
515
504
  try {
516
505
  if (params.externalAccessory) {
@@ -522,11 +511,31 @@ class Platform extends homebridgeLib.Delegate {
522
511
  this._pluginName, this._platformName, [accessory]
523
512
  )
524
513
  }
525
- delete accessory.context.notExposed
526
514
  } catch (error) {
527
- this.error(error)
515
+ this.warn(error)
516
+ try {
517
+ // Make sure the accessory won't be persisted, since it will fail
518
+ // to be exposed again on restore, causing `configureAccessory()`
519
+ // not to be called.
520
+ this._homebridge.unregisterPlatformAccessories(
521
+ this._pluginName, this._platformName, [accessory]
522
+ )
523
+ } catch (error) {}
524
+ /** Emitted when associated accessory could not be exposed.
525
+ * @event AccessoryDelegate#exposeError
526
+ * @param {Error} error - The error trying to expose the accessory.
527
+ */
528
+ delegate.emit('exposeError', error)
528
529
  }
529
530
  })
531
+ } else {
532
+ // Allow for plugin to change delegate class, version, and name.
533
+ accessory.context.className = className
534
+ accessory.context.version = version
535
+ accessory.context.name = name
536
+ if (accessory.context.logLevel == null) {
537
+ accessory.context.logLevel = this.logLevel
538
+ }
530
539
  }
531
540
  this._accessoryDelegates[id] = delegate
532
541
  return accessory
@@ -543,14 +552,16 @@ class Platform extends homebridgeLib.Delegate {
543
552
  this.debug('remove history file %s', historyFile)
544
553
  fs.unlink(historyFile, (error) => {
545
554
  if (error) {
546
- this.error(error)
555
+ this.warn(error)
547
556
  }
548
557
  })
549
558
  }
550
559
  this.debug('%s: remove %s %s', name, className, id)
551
- this._homebridge.unregisterPlatformAccessories(
552
- this._pluginName, this._platformName, [accessory]
553
- )
560
+ try {
561
+ this._homebridge.unregisterPlatformAccessories(
562
+ this._pluginName, this._platformName, [accessory]
563
+ )
564
+ } catch (error) { this.warn(error) }
554
565
  delete this._accessoryDelegates[id]
555
566
  delete this._accessories[id]
556
567
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Library for homebridge plugins",
4
4
  "author": "Erik Baauw",
5
5
  "license": "Apache-2.0",
6
- "version": "5.1.24-1",
6
+ "version": "5.1.24-2",
7
7
  "keywords": [
8
8
  "homekit",
9
9
  "homebridge"