homebridge-lib 5.4.1 → 5.6.1-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.
package/lib/Platform.js CHANGED
@@ -62,8 +62,6 @@ class Platform extends homebridgeLib.Delegate {
62
62
  static loadPlatform (homebridge, packageJson, platformName, Platform) {
63
63
  if (context.homebridge == null) {
64
64
  context.homebridge = homebridge
65
- context.packageJson = packageJson
66
- context.platformName = platformName
67
65
  context.homebridgeVersion = homebridge.serverVersion
68
66
  context.PlatformAccessory = homebridge.platformAccessory
69
67
  const hap = {
@@ -103,6 +101,10 @@ class Platform extends homebridgeLib.Delegate {
103
101
  my: Object.freeze(my.Characteristics)
104
102
  })
105
103
  }
104
+ context[Platform.name] = {
105
+ packageJson: packageJson,
106
+ platformName: platformName
107
+ }
106
108
  homebridge.registerPlatform(
107
109
  packageJson.name, platformName, Platform, true
108
110
  )
@@ -116,6 +118,12 @@ class Platform extends homebridgeLib.Delegate {
116
118
 
117
119
  get Characteristics () { return context.Characteristics }
118
120
 
121
+ /** Content of the plugin's package.json file.
122
+ * @type {object}
123
+ * @readonly
124
+ */
125
+ get packageJson () { return this._myContext.packageJson }
126
+
119
127
  /** Create a new instance of the platform plugin.
120
128
  *
121
129
  * Called by Homebridge when initialising the plugin from `config.json`.
@@ -134,19 +142,21 @@ class Platform extends homebridgeLib.Delegate {
134
142
  this._log = log
135
143
  this._configJson = configJson
136
144
  this._homebridge = homebridge
137
- this._platformName = context.platformName
138
- this._pluginName = context.packageJson.name
139
- this._pluginVersion = context.packageJson.version
145
+ this._myContext = context[this.className]
146
+ this._platformName = this._myContext.platformName
147
+ this._pluginName = this._myContext.packageJson.name
148
+ this._pluginVersion = this._myContext.packageJson.version
140
149
 
141
150
  this._accessories = {}
142
151
  this._accessoryDelegates = {}
143
152
 
144
- if (context.platform != null) {
153
+ if (this._myContext.platform != null) {
145
154
  this.fatal(
146
- 'config.json: duplicate entry for %s platform', context.platformName
155
+ 'config.json: duplicate entry for %s platform',
156
+ this._myContext.platformName
147
157
  )
148
158
  }
149
- context.platform = this
159
+ this._myContext.platform = this
150
160
  this._identify()
151
161
 
152
162
  this._homebridge
@@ -48,6 +48,10 @@ class Motion extends History {
48
48
  * @param {!CharacteristicDelegate} lastActivationDelegate - A reference to the
49
49
  * delegate of the associated `Characteristics.eve.LastActivation`
50
50
  * characteristic.
51
+ * @param {?CharacteristicDelegate} lightLevelDelegate - A reference to the
52
+ * delegate of the associated `Characteristics.hap.CurrentAmbientLightLevel`
53
+ * characteristic. For PIR sensors (like the Hue motion sensor) that report
54
+ * light level in addition to motion.
51
55
  * @param {?CharacteristicDelegate} temperatureDelegate - A reference to the
52
56
  * delegate of the associated `Characteristics.hap.CurrentTemperature`
53
57
  * characteristic. For PIR sensors (like the Hue motion sensor) that report
@@ -55,7 +59,8 @@ class Motion extends History {
55
59
  */
56
60
  constructor (
57
61
  accessoryDelegate, params,
58
- motionDelegate, lastActivationDelegate, temperatureDelegate
62
+ motionDelegate, lastActivationDelegate,
63
+ lightLevelDelegate, temperatureDelegate
59
64
  ) {
60
65
  super(accessoryDelegate, params)
61
66
  if (!(motionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
@@ -64,6 +69,12 @@ class Motion extends History {
64
69
  if (!(lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
65
70
  throw new TypeError('lastActivationDelegate: not a CharacteristicDelegate')
66
71
  }
72
+ if (
73
+ lightLevelDelegate != null &&
74
+ !(lightLevelDelegate instanceof homebridgeLib.CharacteristicDelegate)
75
+ ) {
76
+ throw new TypeError('lightLevelDelegate: not a CharacteristicDelegate')
77
+ }
67
78
  if (
68
79
  temperatureDelegate != null &&
69
80
  !(temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)
@@ -76,14 +87,23 @@ class Motion extends History {
76
87
  lastActivationDelegate.value = now - this._h.initialTime
77
88
  this._entry.status = value
78
89
  if (this._entry.temp != null) {
90
+ const lightlevel = this._entry.lightlevel
79
91
  const temp = this._entry.temp
92
+ this._entry.lightlevel = null
80
93
  this._entry.temp = null
81
94
  this._addEntry(now)
95
+ this._entry.lightlevel = lightlevel
82
96
  this._entry.temp = temp
83
97
  } else {
84
98
  this._addEntry(now)
85
99
  }
86
100
  })
101
+ if (lightLevelDelegate != null) {
102
+ this._entry.lightlevel = lightLevelDelegate.value
103
+ lightLevelDelegate.on('didSet', (value) => {
104
+ this._entry.lightlevel = value
105
+ })
106
+ }
87
107
  if (temperatureDelegate != null) {
88
108
  this._entry.temp = temperatureDelegate.value
89
109
  temperatureDelegate.on('didSet', (value) => {
@@ -93,23 +113,42 @@ class Motion extends History {
93
113
  }
94
114
 
95
115
  get _fingerPrint () {
96
- return '02 1c01 0102'
116
+ return '03 1c01 3002 0102'
97
117
  }
98
118
 
99
119
  _entryStream (entry) {
100
120
  if (entry.temp == null) {
121
+ if (entry.lightlevel == null) {
122
+ return util.format(
123
+ '|0b %s %s 01 %s',
124
+ numToHex(swap32(this._h.currentEntry), 8),
125
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
126
+ numToHex(entry.status, 2)
127
+ )
128
+ }
129
+ return util.format(
130
+ '|0d %s %s 03 %s %s',
131
+ numToHex(swap32(this._h.currentEntry), 8),
132
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
133
+ numToHex(entry.status, 2),
134
+ numToHex(swap16(entry.lightlevel), 4)
135
+ )
136
+ }
137
+ if (entry.lightlevel == null) {
101
138
  return util.format(
102
- '|0b %s %s 01 %s',
139
+ '|0d %s %s 05 %s %s',
103
140
  numToHex(swap32(this._h.currentEntry), 8),
104
141
  numToHex(swap32(entry.time - this._h.initialTime), 8),
105
- numToHex(entry.status, 2)
142
+ numToHex(entry.status, 2),
143
+ numToHex(swap16(entry.temp * 100), 4)
106
144
  )
107
145
  }
108
146
  return util.format(
109
- '|0d %s %s 03 %s %s',
147
+ '|0f %s %s 07 %s %s %s',
110
148
  numToHex(swap32(this._h.currentEntry), 8),
111
149
  numToHex(swap32(entry.time - this._h.initialTime), 8),
112
150
  numToHex(entry.status, 2),
151
+ numToHex(swap16(entry.lightlevel), 4),
113
152
  numToHex(swap16(entry.temp * 100), 4)
114
153
  )
115
154
  }
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.4.1",
6
+ "version": "5.6.1-0",
7
7
  "keywords": [
8
8
  "homekit",
9
9
  "homebridge"
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "engines": {
24
24
  "homebridge": "^1.4.1",
25
- "node": "^16.15.0"
25
+ "node": "^16.15.1"
26
26
  },
27
27
  "dependencies": {
28
28
  "@homebridge/plugin-ui-utils": "~0.0.19",