homebridge-lib 6.0.2 → 6.2.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/README.md +1 -1
- package/cli/hap.js +1 -1
- package/cli/json.js +1 -1
- package/cli/sysinfo.js +1 -1
- package/cli/upnp.js +1 -1
- package/index.js +1 -1
- package/lib/AccessoryDelegate.js +30 -27
- package/lib/AdaptiveLighting.js +1 -1
- package/lib/CharacteristicDelegate.js +22 -36
- package/lib/Colour.js +1 -1
- package/lib/CommandLineParser.js +1 -1
- package/lib/CommandLineTool.js +1 -1
- package/lib/CustomHomeKitTypes.js +1 -1
- package/lib/Delegate.js +31 -33
- package/lib/EveHomeKitTypes.js +62 -52
- package/lib/HttpClient.js +1 -1
- package/lib/JsonFormatter.js +1 -1
- package/lib/MyHomeKitTypes.js +88 -97
- package/lib/OptionParser.js +27 -2
- package/lib/Platform.js +12 -20
- package/lib/PropertyDelegate.js +8 -11
- package/lib/ServiceDelegate/AccessoryInformation.js +1 -1
- package/lib/ServiceDelegate/Battery.js +1 -1
- package/lib/ServiceDelegate/Dummy.js +1 -1
- package/lib/ServiceDelegate/History/Consumption.js +28 -49
- package/lib/ServiceDelegate/History/Light.js +15 -23
- package/lib/ServiceDelegate/History/On.js +29 -33
- package/lib/ServiceDelegate/History/Power.js +43 -52
- package/lib/ServiceDelegate/History/Sensor.js +215 -0
- package/lib/ServiceDelegate/History/Thermo.js +19 -33
- package/lib/ServiceDelegate/History/index.js +137 -186
- package/lib/ServiceDelegate/ServiceLabel.js +1 -1
- package/lib/ServiceDelegate/index.js +13 -11
- package/lib/SystemInfo.js +3 -2
- package/lib/UiServer.js +1 -1
- package/lib/UpnpClient.js +1 -1
- package/package.json +2 -2
- package/lib/ServiceDelegate/History/Contact.js +0 -96
- package/lib/ServiceDelegate/History/Motion.js +0 -155
- package/lib/ServiceDelegate/History/Room.js +0 -112
- package/lib/ServiceDelegate/History/Weather.js +0 -124
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// homebridge-lib/lib/ServiceDelegate/History/Sensor.js
|
|
2
|
+
//
|
|
3
|
+
// Library for Homebridge plugins.
|
|
4
|
+
// Copyright © 2023 Erik Baauw. All rights reserved.
|
|
5
|
+
|
|
6
|
+
'use strict'
|
|
7
|
+
|
|
8
|
+
const homebridgeLib = require('../../../index')
|
|
9
|
+
|
|
10
|
+
const { History } = homebridgeLib.ServiceDelegate
|
|
11
|
+
|
|
12
|
+
/** Class for an Eve _History_ service delegate for a generic sensor accessory.
|
|
13
|
+
*
|
|
14
|
+
* This delegate sets up a `Services.eve.History` HomeKit service
|
|
15
|
+
* with keys for the following HomeKit characteristics:
|
|
16
|
+
*
|
|
17
|
+
* key | Characteristic
|
|
18
|
+
* ---------------- | ----------------------------------
|
|
19
|
+
* `name` | `Characteristics.hap.Name`
|
|
20
|
+
* `historyRequest` | `Characteristics.eve.HistoryRequest`
|
|
21
|
+
* `setTime` | `Characteristics.eve.SetTime`
|
|
22
|
+
* `historyStatus` | `Characteristics.eve.HistoryStatus`
|
|
23
|
+
* `historyEntries` | `Characteristics.eve.HistoryEntries`
|
|
24
|
+
* `resetTotal` | `Characteristics.eve.ResetTotal`
|
|
25
|
+
*
|
|
26
|
+
* This delegate creates the history for a generic sensor, combining the features of the
|
|
27
|
+
* following accessories:
|
|
28
|
+
* - Eve Door & Window (contact);
|
|
29
|
+
* - Eve Motion Sensor (motion, lightLevel, temperature);
|
|
30
|
+
* - Eve Weather (temperature, humidiy. airPressure);
|
|
31
|
+
* - Eve Room (temperature, humidity, vocDensity).
|
|
32
|
+
*
|
|
33
|
+
* @extends ServiceDelegate.History
|
|
34
|
+
* @memberof ServiceDelegate.History
|
|
35
|
+
*/
|
|
36
|
+
class Sensor extends History {
|
|
37
|
+
/** Create a new instance of an Eve Motion _History_ service delegate.
|
|
38
|
+
* @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
|
|
39
|
+
* corresponding HomeKit accessory.
|
|
40
|
+
* @param {!object} params - The parameters for the
|
|
41
|
+
* _History_ HomeKit service.
|
|
42
|
+
* @param {?CharacteristicDelegate} params.contactDelegate - A reference to
|
|
43
|
+
* the delegate of the associated `Characteristics.hap.ContactSensorState`
|
|
44
|
+
* characteristic for a _Contact Sensor_ service.
|
|
45
|
+
* @param {?CharacteristicDelegate} params.timesOpenedDelegate - A reference
|
|
46
|
+
* to the delegate of the associated `Characteristics.eve.TimesOpened`
|
|
47
|
+
* characteristic for the _Contact Sensor_ service.
|
|
48
|
+
* @param {?CharacteristicDelegate} params.lastContactDelegate - A reference
|
|
49
|
+
* to the delegate of the associated `Characteristics.eve.LastActivation`
|
|
50
|
+
* characteristic for the _Contact Sensor_ service.
|
|
51
|
+
* @param {?CharacteristicDelegate} params.motionDelegate - A reference to
|
|
52
|
+
* the delegate of the associated `Characteristics.hap.MotionDetected`
|
|
53
|
+
* characteristic for a _Motion Sensor_ service.
|
|
54
|
+
* @param {?CharacteristicDelegate} params.lastMotionDelegate - A reference
|
|
55
|
+
* to the delegate of the associated `Characteristics.eve.LastActivation`
|
|
56
|
+
* characteristic for the _Motion Sensor_ service.
|
|
57
|
+
* @param {?CharacteristicDelegate} params.lightLevelDelegate - A reference
|
|
58
|
+
* to the delegate of the associated
|
|
59
|
+
* `Characteristics.hap.CurrentAmbientLightLevel` characteristic for a
|
|
60
|
+
* _Light Level Sensor_ service.
|
|
61
|
+
* @param {?CharacteristicDelegate} params.temperatureDelegate - A reference
|
|
62
|
+
* to the delegate of the associated `Characteristics.hap.CurrentTemperature`
|
|
63
|
+
* characteristic for a _Temperature Sensor_ service.
|
|
64
|
+
* @param {?CharacteristicDelegate} params.humidityDelegate - A reference
|
|
65
|
+
* to the delegate of the associated `Characteristics.hap.CurrentRelativeHumidity`
|
|
66
|
+
* characteristic for a _Humidity Sensor_ service.
|
|
67
|
+
* @param {?CharacteristicDelegate} params.airPressureDelegate - A reference to
|
|
68
|
+
* the delegate of the associated `Characteristics.eve.AirPressure`
|
|
69
|
+
* characteristic for an _Air Pressure Sensor_ service.
|
|
70
|
+
* @param {?CharacteristicDelegate} params.vocDensityDelegate - A reference
|
|
71
|
+
* to the delegate of the associated `Characteristics.hap.VOCDensity`
|
|
72
|
+
* characteristic for an _Air Qualility Sensor_ service.
|
|
73
|
+
*/
|
|
74
|
+
constructor (accessoryDelegate, params) {
|
|
75
|
+
super(accessoryDelegate, params)
|
|
76
|
+
this.entry = {}
|
|
77
|
+
|
|
78
|
+
if (params.contactDelegate != null) {
|
|
79
|
+
if (!(params.contactDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
80
|
+
throw new TypeError('params.contactDelegate: not a CharacteristicDelegate')
|
|
81
|
+
}
|
|
82
|
+
if (!(params.timesOpenedDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
83
|
+
throw new TypeError('params.timesOpenedDelegate: not a CharacteristicDelegate')
|
|
84
|
+
}
|
|
85
|
+
if (!(params.lastContactDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
86
|
+
throw new TypeError('params.lastContactDelegate: not a CharacteristicDelegate')
|
|
87
|
+
}
|
|
88
|
+
this.entry.c = params.contactDelegate.value ? 1 : 0
|
|
89
|
+
params.contactDelegate.on('didSet', (value) => {
|
|
90
|
+
const now = History.now()
|
|
91
|
+
params.timesOpenedDelegate.value += value
|
|
92
|
+
params.lastContactDelegate.value = this.lastActivationValue(now)
|
|
93
|
+
this.entry.c = value ? 1 : 0
|
|
94
|
+
this.addEntry({ time: now, c: this.entry.c })
|
|
95
|
+
})
|
|
96
|
+
this.addCharacteristicDelegate({
|
|
97
|
+
key: 'resetTotal',
|
|
98
|
+
Characteristic: this.Characteristics.eve.ResetTotal,
|
|
99
|
+
value: params.resetTotal
|
|
100
|
+
}).on('didSet', (value) => {
|
|
101
|
+
params.timesOpenedDelegate.value = 0
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (params.motionDelegate != null) {
|
|
106
|
+
if (!(params.motionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
107
|
+
throw new TypeError('params.motionDelegate: not a CharacteristicDelegate')
|
|
108
|
+
}
|
|
109
|
+
if (!(params.lastMotionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
110
|
+
throw new TypeError('params.lastMotionDelegate: not a CharacteristicDelegate')
|
|
111
|
+
}
|
|
112
|
+
this.entry.m = params.motionDelegate.value ? 1 : 0
|
|
113
|
+
params.motionDelegate.on('didSet', (value) => {
|
|
114
|
+
const now = History.now()
|
|
115
|
+
params.lastMotionDelegate.value = this.lastActivationValue(now)
|
|
116
|
+
this.entry.m = value ? 1 : 0
|
|
117
|
+
this.addEntry({ time: now, m: this.entry.m })
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (params.lightLevelDelegate != null) {
|
|
122
|
+
if (!(params.lightLevelDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
123
|
+
throw new TypeError('params.lightLevelDelegate: not a CharacteristicDelegate')
|
|
124
|
+
}
|
|
125
|
+
this.entry.l = params.lightLevelDelegate.value
|
|
126
|
+
params.lightLevelDelegate.on('didSet', (value) => {
|
|
127
|
+
this.entry.l = value
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (params.temperatureDelegate != null) {
|
|
132
|
+
if (!(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
133
|
+
throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
|
|
134
|
+
}
|
|
135
|
+
this.entry.t = params.temperatureDelegate.value * 100
|
|
136
|
+
params.temperatureDelegate.on('didSet', (value) => {
|
|
137
|
+
this.entry.t = value * 100
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (params.humidityDelegate != null) {
|
|
142
|
+
if (!(params.humidityDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
143
|
+
throw new TypeError('params.humidityDelegate: not a CharacteristicDelegate')
|
|
144
|
+
}
|
|
145
|
+
this.entry.h = params.humidityDelegate.value * 100
|
|
146
|
+
params.humidityDelegate.on('didSet', (value) => {
|
|
147
|
+
this.entry.h = value * 100
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (params.airPressureDelegate != null) {
|
|
152
|
+
if (!(params.airPressureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
153
|
+
throw new TypeError('params.airPressureDelegate: not a CharacteristicDelegate')
|
|
154
|
+
}
|
|
155
|
+
this.entry.a = params.airPressureDelegate.value * 10
|
|
156
|
+
params.airPressureDelegate.on('didSet', (value) => {
|
|
157
|
+
this.entry.a = value * 10
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (params.vocDensityDelegate != null) {
|
|
162
|
+
if (!(params.vocDensityDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
163
|
+
throw new TypeError('params.vocDensityDelegate: not a CharacteristicDelegate')
|
|
164
|
+
}
|
|
165
|
+
this.entry.v = params.vocDensityDelegate.value
|
|
166
|
+
params.vocDensityDelegate.on('didSet', (value) => {
|
|
167
|
+
this.entry.v = value
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
get fingerPrint () {
|
|
173
|
+
// entry: c m l t h a v
|
|
174
|
+
// mask: 0x01 0x02 0x04 0x08 0x10 0x20 0x40
|
|
175
|
+
return '07 0601 1C01 3002 0102 0202 0302 2202'
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
entryToBuffer (entry) {
|
|
179
|
+
const buffer = Buffer.alloc(16)
|
|
180
|
+
let mask = 0
|
|
181
|
+
let o = 1
|
|
182
|
+
if (entry.c != null) {
|
|
183
|
+
mask |= 0x01
|
|
184
|
+
buffer.writeUInt8(entry.c, o); o += 1
|
|
185
|
+
}
|
|
186
|
+
if (entry.m != null) {
|
|
187
|
+
mask |= 0x02
|
|
188
|
+
buffer.writeUInt8(entry.m, o); o += 1
|
|
189
|
+
}
|
|
190
|
+
if (entry.l != null) {
|
|
191
|
+
mask |= 0x04
|
|
192
|
+
buffer.writeUInt16LE(entry.l, o); o += 2
|
|
193
|
+
}
|
|
194
|
+
if (entry.t != null) {
|
|
195
|
+
mask |= 0x08
|
|
196
|
+
buffer.writeUInt16LE(entry.t, o); o += 2
|
|
197
|
+
}
|
|
198
|
+
if (entry.h != null) {
|
|
199
|
+
mask |= 0x10
|
|
200
|
+
buffer.writeUInt16LE(entry.h, o); o += 2
|
|
201
|
+
}
|
|
202
|
+
if (entry.a != null) {
|
|
203
|
+
mask |= 0x20
|
|
204
|
+
buffer.writeUInt16LE(entry.a, o); o += 2
|
|
205
|
+
}
|
|
206
|
+
if (entry.v != null) {
|
|
207
|
+
mask |= 0x40
|
|
208
|
+
buffer.writeUInt16LE(entry.v, o); o += 2
|
|
209
|
+
}
|
|
210
|
+
buffer.writeUInt8(mask, 0)
|
|
211
|
+
return buffer.slice(0, o)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
module.exports = Sensor
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
// homebridge-lib/lib/ServiceDelegate/History/Thermo.js
|
|
2
2
|
//
|
|
3
3
|
// Library for Homebridge plugins.
|
|
4
|
-
// Copyright © 2017-
|
|
5
|
-
//
|
|
6
|
-
// The logic for handling Eve history was copied from Simone Tisa's
|
|
7
|
-
// fakagato-history repository, copyright © 2017 simont77.
|
|
8
|
-
// See https://github.com/simont77/fakegato-history.
|
|
4
|
+
// Copyright © 2017-2023 Erik Baauw. All rights reserved.
|
|
9
5
|
|
|
10
6
|
'use strict'
|
|
11
7
|
|
|
12
8
|
const homebridgeLib = require('../../../index')
|
|
13
|
-
const util = require('util')
|
|
14
9
|
|
|
15
|
-
const {
|
|
16
|
-
const { History } = ServiceDelegate
|
|
17
|
-
const { swap16, swap32, numToHex } = History
|
|
10
|
+
const { History } = homebridgeLib.ServiceDelegate
|
|
18
11
|
|
|
19
12
|
/** Class for an Eve Thermo _History_ service delegate.
|
|
20
13
|
*
|
|
@@ -36,7 +29,7 @@ const { swap16, swap32, numToHex } = History
|
|
|
36
29
|
* @extends ServiceDelegate.History
|
|
37
30
|
* @memberof ServiceDelegate.History
|
|
38
31
|
*/
|
|
39
|
-
class Thermo extends
|
|
32
|
+
class Thermo extends History {
|
|
40
33
|
/** Create a new instance of an Eve Thermo _History_ service delegate.
|
|
41
34
|
* @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
|
|
42
35
|
* corresponding HomeKit accessory.
|
|
@@ -63,39 +56,32 @@ class Thermo extends ServiceDelegate.History {
|
|
|
63
56
|
if (!(params.valvePositionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
64
57
|
throw new TypeError('params.valvePositionDelegate: not a CharacteristicDelegate')
|
|
65
58
|
}
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
valvePosition: params.valvePositionDelegate.value
|
|
59
|
+
this.entry = {
|
|
60
|
+
t: params.temperatureDelegate.value * 100,
|
|
61
|
+
s: params.targetTemperatureDelegate.value * 100,
|
|
62
|
+
v: params.valvePositionDelegate.value
|
|
71
63
|
}
|
|
72
64
|
params.temperatureDelegate.on('didSet', (value) => {
|
|
73
|
-
this.
|
|
65
|
+
this.entry.t = value * 100
|
|
74
66
|
})
|
|
75
67
|
params.targetTemperatureDelegate.on('didSet', (value) => {
|
|
76
|
-
this.
|
|
68
|
+
this.entry.s = value * 100
|
|
77
69
|
})
|
|
78
70
|
params.valvePositionDelegate.on('didSet', (value) => {
|
|
79
|
-
this.
|
|
71
|
+
this.entry.v = value
|
|
80
72
|
})
|
|
81
73
|
}
|
|
82
74
|
|
|
83
|
-
|
|
84
|
-
// look like Eve displays any history for these.
|
|
85
|
-
// As of v3.8.1, Eve no longer shows the valve position history.
|
|
86
|
-
// get _fingerPrint () { return '05 0102 1102 1001 1201 1d01' }
|
|
87
|
-
get _fingerPrint () { return '03 0102 1102 1001' }
|
|
75
|
+
get fingerPrint () { return '03 0102 1102 1001' }
|
|
88
76
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
numToHex(entry.valvePosition, 2)
|
|
98
|
-
)
|
|
77
|
+
entryToBuffer (entry) {
|
|
78
|
+
const buffer = Buffer.alloc(6)
|
|
79
|
+
let o = 1
|
|
80
|
+
buffer.writeUInt16LE(entry.t, o); o += 2
|
|
81
|
+
buffer.writeUInt16LE(entry.s, o); o += 2
|
|
82
|
+
buffer.writeUInt8(entry.v, o); o += 1
|
|
83
|
+
buffer.writeUInt8(0x07, 0)
|
|
84
|
+
return buffer.slice(0, o)
|
|
99
85
|
}
|
|
100
86
|
}
|
|
101
87
|
|