homebridge-lib 5.5.0 → 5.6.1
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 +13 -9
- package/lib/ServiceDelegate/History/Motion.js +44 -5
- package/package.json +2 -2
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
|
)
|
|
@@ -120,7 +122,7 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
120
122
|
* @type {object}
|
|
121
123
|
* @readonly
|
|
122
124
|
*/
|
|
123
|
-
get packageJson () { return
|
|
125
|
+
get packageJson () { return this._myContext.packageJson }
|
|
124
126
|
|
|
125
127
|
/** Create a new instance of the platform plugin.
|
|
126
128
|
*
|
|
@@ -140,19 +142,21 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
140
142
|
this._log = log
|
|
141
143
|
this._configJson = configJson
|
|
142
144
|
this._homebridge = homebridge
|
|
143
|
-
this.
|
|
144
|
-
this.
|
|
145
|
-
this.
|
|
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
|
|
146
149
|
|
|
147
150
|
this._accessories = {}
|
|
148
151
|
this._accessoryDelegates = {}
|
|
149
152
|
|
|
150
|
-
if (
|
|
153
|
+
if (this._myContext.platform != null) {
|
|
151
154
|
this.fatal(
|
|
152
|
-
'config.json: duplicate entry for %s platform',
|
|
155
|
+
'config.json: duplicate entry for %s platform',
|
|
156
|
+
this._myContext.platformName
|
|
153
157
|
)
|
|
154
158
|
}
|
|
155
|
-
|
|
159
|
+
this._myContext.platform = this
|
|
156
160
|
this._identify()
|
|
157
161
|
|
|
158
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,
|
|
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 '
|
|
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
|
-
'|
|
|
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
|
-
'|
|
|
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.
|
|
6
|
+
"version": "5.6.1",
|
|
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.
|
|
25
|
+
"node": "^16.15.1"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@homebridge/plugin-ui-utils": "~0.0.19",
|