homebridge-lib 6.1.0 → 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/lib/Platform.js CHANGED
@@ -28,7 +28,9 @@ const context = {
28
28
  recommendedHomebridgeVersion:
29
29
  semver.minVersion(libPackageJson.engines.homebridge).toString(),
30
30
  saveInterval: 3600,
31
- checkInterval: 7 * 24 * 3600
31
+ checkInterval: 7 * 24 * 3600,
32
+ driftDebugThreshold: 250,
33
+ driftWarningThreshold: 2500
32
34
  }
33
35
 
34
36
  /** Homebridge dynamic platform plugin.
@@ -266,8 +268,12 @@ class Platform extends homebridgeLib.Delegate {
266
268
  this.debug('last heartbeat %d, drift %d', beat, drift)
267
269
  return
268
270
  }
269
- if (drift < -250 || drift > 250) {
270
- this.warn('heartbeat %d, drift %d', beat, drift)
271
+ if (drift < -context.driftDebugThreshold || drift > context.driftDebugThreshold) {
272
+ if (drift < -context.driftWarningThreshold || drift > context.driftWarningThreshold) {
273
+ this.warn('heartbeat %d, drift %d', beat, drift)
274
+ } else {
275
+ this.debug('heartbeat %d, drift %d', beat, drift)
276
+ }
271
277
  }
272
278
  setTimeout(() => {
273
279
  this._beat(beat)
@@ -111,21 +111,18 @@ class Consumption extends History {
111
111
  get fingerPrint () { return '02 0702 0E01' }
112
112
 
113
113
  entryToBuffer (entry) {
114
- const buffer = Buffer.alloc(4)
115
- let o = 0
116
- if (entry.o == null) {
117
- buffer.writeUInt8(0x01, o); o += 1
114
+ const buffer = Buffer.alloc(16)
115
+ let mask = 0
116
+ let o = 1
117
+ if (entry.p != null) {
118
+ mask |= 0x01
118
119
  buffer.writeUInt16LE(entry.p, o); o += 2
119
- return buffer.slice(0, o)
120
120
  }
121
- if (entry.p == null) {
122
- buffer.writeUInt8(0x02, o); o += 1
121
+ if (entry.o != null) {
122
+ mask |= 0x02
123
123
  buffer.writeUInt8(entry.o, o); o += 1
124
- return buffer.slice(0, o)
125
124
  }
126
- buffer.writeUInt8(0x03, o); o += 1
127
- buffer.writeUInt16LE(entry.p, o); o += 2
128
- buffer.writeUInt8(entry.o, o); o += 1
125
+ buffer.writeUInt8(mask, 0)
129
126
  return buffer.slice(0, o)
130
127
  }
131
128
  }
@@ -69,9 +69,9 @@ class On extends History {
69
69
  if (!(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
70
70
  throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
71
71
  }
72
- this.entry.t = params.temperatureDelegate.value
72
+ this.entry.t = params.temperatureDelegate.value * 100
73
73
  params.temperatureDelegate.on('didSet', (value) => {
74
- this.entry.t = value
74
+ this.entry.t = value * 100
75
75
  })
76
76
  }
77
77
  }
@@ -79,16 +79,18 @@ class On extends History {
79
79
  get fingerPrint () { return '01 0E01 0102' }
80
80
 
81
81
  entryToBuffer (entry) {
82
- const buffer = Buffer.alloc(2)
83
- let o = 0
84
- if (entry.t == null) {
85
- buffer.writeUInt8(0x01, o); o += 1
82
+ const buffer = Buffer.alloc(16)
83
+ let mask = 0
84
+ let o = 1
85
+ if (entry.o != null) {
86
+ mask |= 0x01
86
87
  buffer.writeUInt8(entry.o, o); o += 1
87
- return buffer.slice(0, o)
88
88
  }
89
- buffer.writeUInt8(0x03, o); o += 1
90
- buffer.writeUInt8(entry.o, o); o += 1
91
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
89
+ if (entry.t != null) {
90
+ mask |= 0x02
91
+ buffer.writeUInt16LE(entry.t, o); o += 2
92
+ }
93
+ buffer.writeUInt8(mask, 0)
92
94
  return buffer.slice(0, o)
93
95
  }
94
96
  }
@@ -128,21 +128,18 @@ class Power extends History {
128
128
  get fingerPrint () { return '02 0702 0E01' }
129
129
 
130
130
  entryToBuffer (entry) {
131
- const buffer = Buffer.alloc(4)
132
- let o = 0
133
- if (entry.o == null) {
134
- buffer.writeUInt8(0x01, o); o += 1
131
+ const buffer = Buffer.alloc(16)
132
+ let mask = 0
133
+ let o = 1
134
+ if (entry.p != null) {
135
+ mask |= 0x01
135
136
  buffer.writeUInt16LE(entry.p, o); o += 2
136
- return buffer.slice(0, o)
137
137
  }
138
- if (entry.p == null) {
139
- buffer.writeUInt8(0x02, o); o += 1
138
+ if (entry.o != null) {
139
+ mask |= 0x02
140
140
  buffer.writeUInt8(entry.o, o); o += 1
141
- return buffer.slice(0, o)
142
141
  }
143
- buffer.writeUInt8(0x03, o); o += 1
144
- buffer.writeUInt16LE(entry.p, o); o += 2
145
- buffer.writeUInt8(entry.o, o); o += 1
142
+ buffer.writeUInt8(mask, 0)
146
143
  return buffer.slice(0, o)
147
144
  }
148
145
  }
@@ -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
@@ -57,15 +57,15 @@ class Thermo extends History {
57
57
  throw new TypeError('params.valvePositionDelegate: not a CharacteristicDelegate')
58
58
  }
59
59
  this.entry = {
60
- t: params.temperatureDelegate.value,
61
- s: params.targetTemperatureDelegate.value,
60
+ t: params.temperatureDelegate.value * 100,
61
+ s: params.targetTemperatureDelegate.value * 100,
62
62
  v: params.valvePositionDelegate.value
63
63
  }
64
64
  params.temperatureDelegate.on('didSet', (value) => {
65
- this.entry.t = value
65
+ this.entry.t = value * 100
66
66
  })
67
67
  params.targetTemperatureDelegate.on('didSet', (value) => {
68
- this.entry.s = value
68
+ this.entry.s = value * 100
69
69
  })
70
70
  params.valvePositionDelegate.on('didSet', (value) => {
71
71
  this.entry.v = value
@@ -76,11 +76,11 @@ class Thermo extends History {
76
76
 
77
77
  entryToBuffer (entry) {
78
78
  const buffer = Buffer.alloc(6)
79
- let o = 0
80
- buffer.writeUInt8(0x07, o); o += 1
81
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
82
- buffer.writeUInt16LE(entry.s * 100, o); o += 2
79
+ let o = 1
80
+ buffer.writeUInt16LE(entry.t, o); o += 2
81
+ buffer.writeUInt16LE(entry.s, o); o += 2
83
82
  buffer.writeUInt8(entry.v, o); o += 1
83
+ buffer.writeUInt8(0x07, 0)
84
84
  return buffer.slice(0, o)
85
85
  }
86
86
  }
@@ -20,24 +20,6 @@ const epoch = Math.round(new Date('2001-01-01T00:00:00Z').valueOf() / 1000)
20
20
 
21
21
  const defaultMemorySize = 6 * 24 * 7 * 4 // 4 weeks of 1 entry per 10 minutes
22
22
 
23
- // const historyEntryTypes = {
24
- // airPressure: { tag: 0x03, length: 2 },
25
- // consumption: { tag: 0x07, length: 2 },
26
- // contact: { tag: 0x06, length: 1, event: true },
27
- // humidity: { tag: 0x02, length: 2 },
28
- // lastActivation: { },
29
- // lightLevel: { tag: 0x30, length: 2 },
30
- // motion: { tag: 0x1C, length: 1, event: true },
31
- // on: { tag: 0x0E, length: 1, event: true },
32
- // power: { tag: 0x07, length: 2 },
33
- // targetTemperature: { tag: 0x11, length: 2 },
34
- // currentTemperature: { tag: 0x01, length: 2 },
35
- // timesOpened: { },
36
- // totalConsumption: { },
37
- // valvePosition: { tag: 0x10, length: 1 },
38
- // vocDensity: { tag: 0x22, length: 2 }
39
- // }
40
-
41
23
  /** Convert date (in # seconds since NodeJS epoch) to string.
42
24
  * @param {integer} d - # seconds since NodeJS epoch.
43
25
  * @returns {string} Human readable date string.
@@ -64,15 +46,11 @@ function dateToString (d) {
64
46
  */
65
47
  class History extends ServiceDelegate {
66
48
  static get Consumption () { return require('./Consumption') }
67
- static get Contact () { return require('./Contact') }
68
49
  static get Light () { return require('./Light') }
69
- static get LightLevel () { return require('./LightLevel') }
70
- static get Motion () { return require('./Motion') }
71
50
  static get On () { return require('./On') }
72
51
  static get Power () { return require('./Power') }
73
- static get Room () { return require('./Room') }
52
+ static get Sensor () { return require('./Sensor') }
74
53
  static get Thermo () { return require('./Thermo') }
75
- static get Weather () { return require('./Weather') }
76
54
 
77
55
  /** Create a new instance of an Eve _History_ service delegate.
78
56
  * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
@@ -145,7 +145,6 @@ class ServiceDelegate extends homebridgeLib.Delegate {
145
145
  }
146
146
 
147
147
  this.once('initialised', () => {
148
- this.values.configuredName = this.name
149
148
  const staleCharacteristics = []
150
149
  for (const uuid in this._service.characteristics) {
151
150
  const characteristic = this._service.characteristics[uuid]
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": "6.1.0",
6
+ "version": "6.2.0",
7
7
  "keywords": [
8
8
  "homekit",
9
9
  "homebridge"
@@ -1,88 +0,0 @@
1
- // homebridge-lib/lib/ServiceDelegate/History/Contact.js
2
- //
3
- // Library for Homebridge plugins.
4
- // Copyright © 2017-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 Door _History_ service delegate.
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 from the associated
27
- * `Characteristics.hap.ContactSensorState` characteristic. It updates the
28
- * values of the associated `Characteristics.eve.TimesOpened` and
29
- * `Characteristics.eve.LastActivation` characteristics.
30
- * @extends ServiceDelegate.History
31
- * @memberof ServiceDelegate.History
32
- */
33
- class Contact extends History {
34
- /** Create a new instance of an Eve Door & Window _History_ service delegate.
35
- * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
36
- * corresponding HomeKit accessory.
37
- * @param {!object} params - The parameters for the
38
- * _History_ HomeKit service.
39
- * @param {!CharacteristicDelegate} params.contactDelegate - A reference to
40
- * thedelegate of the associated `Characteristics.hap.ContactSensorState`
41
- * characteristic.
42
- * @param {!CharacteristicDelegate} params.timesOpenedDelegate - A reference
43
- * to the delegate of the associated `Characteristics.eve.TimesOpened`
44
- * characteristic.
45
- * @param {!CharacteristicDelegate} params.lastActivationDelegate - A
46
- * reference to the delegate of the associated
47
- * `Characteristics.eve.LastActivation` characteristic.
48
- */
49
- constructor (accessoryDelegate, params) {
50
- super(accessoryDelegate, params)
51
- if (!(params.contactDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
52
- throw new TypeError('params.contactDelegate: not a CharacteristicDelegate')
53
- }
54
- if (!(params.timesOpenedDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
55
- throw new TypeError('params.timesOpenedDelegate: not a CharacteristicDelegate')
56
- }
57
- if (!(params.lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
58
- throw new TypeError('params.lastActivationDelegate: not a CharacteristicDelegate')
59
- }
60
- this.entry = { c: params.contactDelegate.value ? 1 : 0 }
61
- params.contactDelegate.on('didSet', (value) => {
62
- const now = History.now()
63
- params.timesOpenedDelegate.value += value
64
- params.lastActivationDelegate.value = this.lastActivationValue(now)
65
- this.entry.c = value ? 1 : 0
66
- this.addEntry({ time: now, c: this.entry.c })
67
- })
68
- this.addCharacteristicDelegate({
69
- key: 'resetTotal',
70
- Characteristic: this.Characteristics.eve.ResetTotal,
71
- value: params.resetTotal
72
- }).on('didSet', (value) => {
73
- params.timesOpenedDelegate.value = 0
74
- })
75
- }
76
-
77
- get fingerPrint () { return '01 0601' }
78
-
79
- entryToBuffer (entry) {
80
- const buffer = Buffer.alloc(2)
81
- let o = 0
82
- buffer.writeUInt8(0x01, o); o += 1
83
- buffer.writeUInt8(entry.c, o); o += 1
84
- return buffer.slice(0, o)
85
- }
86
- }
87
-
88
- module.exports = Contact
@@ -1,113 +0,0 @@
1
- // homebridge-lib/lib/ServiceDelegate/History/LightLevel.js
2
- //
3
- // Library for Homebridge plugins.
4
- // Copyright © 2017-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 Motion _History_ service delegate.
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 from the associated
27
- * `Characteristics.hap.MotionDetected` characteristic. It updates the
28
- * value of the associated `Characteristics.eve.LastActivation` characteristic.
29
- * Optionally, this delegate also mainatins history for
30
- * `Characteristics.hap.CurrentAmbientLightLevel`,
31
- * `Characteristics.hap.CurrentTemperature`, and
32
- * `Characteristics.hap.CurrentRelativeHumidity`.
33
- * @extends ServiceDelegate.History
34
- * @memberof ServiceDelegate.History
35
- */
36
- class LightLevel 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.lightLevelDelegate - A reference
43
- * to the delegate of the associated
44
- * `Characteristics.hap.CurrentAmbientLightLevel` characteristic.
45
- * For PIR sensors (like the Hue motion sensor) that report light level in
46
- * addition to motion.
47
- * @param {?CharacteristicDelegate} params.temperatureDelegate - A reference
48
- * to the delegate of the associated `Characteristics.hap.CurrentTemperature`
49
- * characteristic.
50
- * For PIR sensors (like the Hue motion sensor) that report temperature in
51
- * addition to motion and light level.
52
- * @param {?CharacteristicDelegate} params.humidityDelegate - A reference
53
- * to the delegate of the associated `Characteristics.hap.CurrentRelativeHumidity`
54
- * characteristic.
55
- * For PIR sensors (like the OWON PIR313 sensor) that report humidity in
56
- * addition to motion, light level, and temperature.
57
- */
58
- constructor (accessoryDelegate, params) {
59
- super(accessoryDelegate, params)
60
- if (!(params.lightLevelDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
61
- throw new TypeError('params.lightLevelDelegate: not a CharacteristicDelegate')
62
- }
63
- this.entry = { l: params.lightLevelDelegate.value }
64
- params.lightLevelDelegate.on('didSet', (value) => {
65
- this.entry.l = value
66
- })
67
- if (params.temperatureDelegate != null) {
68
- if (!(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
69
- throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
70
- }
71
- this.entry.t = params.temperatureDelegate.value
72
- params.temperatureDelegate.on('didSet', (value) => {
73
- this.entry.t = value
74
- })
75
- if (params.humidityDelegate != null) {
76
- if (!(params.humidityDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
77
- throw new TypeError('params.humidityDelegate: not a CharacteristicDelegate')
78
- }
79
- this.entry.h = params.humidityDelegate.value
80
- params.humidityDelegate.on('didSet', (value) => {
81
- this.entry.h = value
82
- })
83
- }
84
- }
85
- }
86
-
87
- get fingerPrint () {
88
- return '03 3002 0102 0202'
89
- }
90
-
91
- entryToBuffer (entry) {
92
- const buffer = Buffer.alloc(6)
93
- let o = 0
94
- if (entry.t == null) {
95
- buffer.writeUInt8(0x01, o); o += 1
96
- buffer.writeUInt16LE(entry.l, o); o += 2
97
- return buffer.slice(0, o)
98
- }
99
- if (entry.h == null) {
100
- buffer.writeUInt8(0x03, o); o += 1
101
- buffer.writeUInt16LE(entry.l, o); o += 2
102
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
103
- return buffer.slice(0, o)
104
- }
105
- buffer.writeUInt8(0x07, o); o += 1
106
- buffer.writeUInt16LE(entry.l, o); o += 2
107
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
108
- buffer.writeUInt16LE(entry.h * 100, o); o += 2
109
- return buffer.slice(0, o)
110
- }
111
- }
112
-
113
- module.exports = LightLevel
@@ -1,142 +0,0 @@
1
- // homebridge-lib/lib/ServiceDelegate/History/Motion.js
2
- //
3
- // Library for Homebridge plugins.
4
- // Copyright © 2017-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 Motion _History_ service delegate.
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 from the associated
27
- * `Characteristics.hap.MotionDetected` characteristic. It updates the
28
- * value of the associated `Characteristics.eve.LastActivation` characteristic.
29
- * Optionally, this delegate also mainatins history for
30
- * `Characteristics.hap.CurrentAmbientLightLevel`,
31
- * `Characteristics.hap.CurrentTemperature`, and
32
- * `Characteristics.hap.CurrentRelativeHumidity`.
33
- * @extends ServiceDelegate.History
34
- * @memberof ServiceDelegate.History
35
- */
36
- class Motion 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.motionDelegate - A reference to
43
- * the delegate of the associated `Characteristics.hap.MotionDetected`
44
- * characteristic.
45
- * @param {!CharacteristicDelegate} params.lastActivationDelegate - A
46
- * reference to the delegate of the associated
47
- * `Characteristics.eve.LastActivation` characteristic.
48
- * @param {?CharacteristicDelegate} params.lightLevelDelegate - A reference
49
- * to the delegate of the associated
50
- * `Characteristics.hap.CurrentAmbientLightLevel` characteristic.
51
- * For PIR sensors (like the Hue motion sensor) that report light level in
52
- * addition to motion.
53
- * @param {?CharacteristicDelegate} params.temperatureDelegate - A reference
54
- * to the delegate of the associated `Characteristics.hap.CurrentTemperature`
55
- * characteristic.
56
- * For PIR sensors (like the Hue motion sensor) that report temperature in
57
- * addition to motion and light level.
58
- * @param {?CharacteristicDelegate} params.humidityDelegate - A reference
59
- * to the delegate of the associated `Characteristics.hap.CurrentRelativeHumidity`
60
- * characteristic.
61
- * For PIR sensors (like the OWON PIR313 sensor) that report humidity in
62
- * addition to motion, light level, and temperature.
63
- */
64
- constructor (accessoryDelegate, params) {
65
- super(accessoryDelegate, params)
66
- if (!(params.motionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
67
- throw new TypeError('params.motionDelegate: not a CharacteristicDelegate')
68
- }
69
- if (!(params.lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
70
- throw new TypeError('params.lastActivationDelegate: not a CharacteristicDelegate')
71
- }
72
- this.entry = { m: params.motionDelegate.value ? 1 : 0 }
73
- params.motionDelegate.on('didSet', (value) => {
74
- const now = History.now()
75
- params.lastActivationDelegate.value = this.lastActivationValue(now)
76
- this.entry.m = value ? 1 : 0
77
- this.addEntry({ time: now, m: this.entry.m })
78
- })
79
- if (params.lightLevelDelegate != null) {
80
- if (!(params.lightLevelDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
81
- throw new TypeError('params.lightLevelDelegate: not a CharacteristicDelegate')
82
- }
83
- this.entry.l = params.lightLevelDelegate.value
84
- params.lightLevelDelegate.on('didSet', (value) => {
85
- this.entry.l = value
86
- })
87
- if (params.temperatureDelegate != null) {
88
- if (!(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
89
- throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
90
- }
91
- this.entry.t = params.temperatureDelegate.value
92
- params.temperatureDelegate.on('didSet', (value) => {
93
- this.entry.t = value
94
- })
95
- if (params.humidityDelegate != null) {
96
- if (!(params.humidityDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
97
- throw new TypeError('params.humidityDelegate: not a CharacteristicDelegate')
98
- }
99
- this.entry.h = params.humidityDelegate.value
100
- params.humidityDelegate.on('didSet', (value) => {
101
- this.entry.h = value
102
- })
103
- }
104
- }
105
- }
106
- }
107
-
108
- get fingerPrint () {
109
- return '04 1C01 3002 0102 0202'
110
- }
111
-
112
- entryToBuffer (entry) {
113
- const buffer = Buffer.alloc(6)
114
- let o = 0
115
- if (entry.l == null) {
116
- buffer.writeUInt8(0x01, o); o += 1
117
- buffer.writeUInt8(entry.m, o); o += 1
118
- return buffer.slice(0, o)
119
- }
120
- if (entry.t == null) {
121
- buffer.writeUInt8(0x03, o); o += 1
122
- buffer.writeUInt8(entry.m, o); o += 1
123
- buffer.writeUInt16LE(entry.l, o); o += 2
124
- return buffer.slice(0, o)
125
- }
126
- if (entry.h == null) {
127
- buffer.writeUInt8(0x07, o); o += 1
128
- buffer.writeUInt8(entry.m, o); o += 1
129
- buffer.writeUInt16LE(entry.l, o); o += 2
130
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
131
- return buffer.slice(0, o)
132
- }
133
- buffer.writeUInt8(0x0F, o); o += 1
134
- buffer.writeUInt8(entry.m, o); o += 1
135
- buffer.writeUInt16LE(entry.l, o); o += 2
136
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
137
- buffer.writeUInt16LE(entry.h * 100, o); o += 2
138
- return buffer.slice(0, o)
139
- }
140
- }
141
-
142
- module.exports = Motion
@@ -1,90 +0,0 @@
1
- // homebridge-lib/lib/ServiceDelegate/History/Room.js
2
- //
3
- // Library for Homebridge plugins.
4
- // Copyright © 2017-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 Room _History_ service delegate.
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
- *
25
- * This delegate creates the history from the associated
26
- * `Characteristics.hap.CurrentTemperature`,
27
- * `Characteristics.hap.CurrentRelativeHumidity`, and
28
- * `Characteristics.hap.VOCDensity` characteristics.
29
- * @extends ServiceDelegate.History
30
- * @memberof ServiceDelegate.History
31
- */
32
- class Room extends History {
33
- /** Create a new instance of an Eve Room _History_ service delegate.
34
- * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
35
- * corresponding HomeKit accessory.
36
- * @param {!object} params - The parameters for the
37
- * _History_ HomeKit service.
38
- * @param {!CharacteristicDelegate} params.temperatureDelegate - A reference
39
- * to the delegate of the associated `Characteristics.hap.CurrentTemperature`
40
- * characteristic.
41
- * @param {!CharacteristicDelegate} params.humidityDelegate - A reference to
42
- * the delegate of the associated
43
- * `Characteristics.hap.CurrentRelativeHumidity` characteristic.
44
- * @param {!CharacteristicDelegate} params.vocDensityDelegate - A reference
45
- * to the delegate of the associated `Characteristics.eve.AirPressure`
46
- * characteristic.
47
- */
48
- constructor (accessoryDelegate, params) {
49
- super(accessoryDelegate, params)
50
- if (!(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
51
- throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
52
- }
53
- if (!(params.humidityDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
54
- throw new TypeError('params.humidityDelegate: not a CharacteristicDelegate')
55
- }
56
- if (!(params.vocDensityDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
57
- throw new TypeError('params.vocDensityDelegate: not a CharacteristicDelegate')
58
- }
59
- this.entry = {
60
- t: params.temperatureDelegate.value,
61
- h: params.humidityDelegate.value,
62
- v: params.vocDensityDelegate.value
63
- }
64
- params.temperatureDelegate.on('didSet', (value) => {
65
- this.entry.t = value
66
- })
67
- params.humidityDelegate.on('didSet', (value) => {
68
- this.entry.h = value
69
- })
70
- params.vocDensityDelegate.on('didSet', (value) => {
71
- this.entry.v = value
72
- })
73
- }
74
-
75
- get fingerPrint () {
76
- return '03 0102 0202 2202'
77
- }
78
-
79
- entryToBuffer (entry) {
80
- const buffer = Buffer.alloc(7)
81
- let o = 0
82
- buffer.writeUInt8(0x07, o); o += 1
83
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
84
- buffer.writeUInt16LE(entry.h * 100, o); o += 2
85
- buffer.writeUInt16LE(entry.v, o); o += 2
86
- return buffer.slice(0, o)
87
- }
88
- }
89
-
90
- module.exports = Room
@@ -1,101 +0,0 @@
1
- // homebridge-lib/lib/ServiceDelegate/History/Weather.js
2
- //
3
- // Library for Homebridge plugins.
4
- // Copyright © 2017-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 Weather _History_ service delegate.
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
- *
25
- * This delegate creates the history from the associated
26
- * `Characteristics.hap.CurrentTemperature`,
27
- * `Characteristics.hap.CurrentRelativeHumidity`, and
28
- * `Characteristics.eve.AirPressure` characteristics.
29
- * @extends ServiceDelegate.History
30
- * @memberof ServiceDelegate.History
31
- */
32
- class Weather extends History {
33
- /** Create a new instance of an Eve Weather _History_ service delegate.
34
- * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
35
- * corresponding HomeKit accessory.
36
- * @param {!object} params - The parameters for the
37
- * _History_ HomeKit service.
38
- * @param {!CharacteristicDelegate} params.temperatureDelegate - A reference
39
- * to the delegate of the associated `Characteristics.hap.CurrentTemperature`
40
- * characteristic.
41
- * @param {?CharacteristicDelegate} params.humidityDelegate - A reference
42
- * to the delegate of the associated
43
- * `Characteristics.hap.CurrentRelativeHumidity` characteristic.
44
- * @param {?CharacteristicDelegate} params.airPressureDelegate - A reference to
45
- * the delegate of the associated `Characteristics.eve.AirPressure`
46
- * characteristic.
47
- */
48
- constructor (accessoryDelegate, params) {
49
- super(accessoryDelegate, params)
50
- if (!(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
51
- throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
52
- }
53
- this.entry = { t: params.temperatureDelegate.value }
54
- params.temperatureDelegate.on('didSet', (value) => {
55
- this.entry.t = value
56
- })
57
- if (params.humidityDelegate != null) {
58
- if (!(params.humidityDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
59
- throw new TypeError('params.humidityDelegate: not a CharacteristicDelegate')
60
- }
61
- this.entry.h = params.humidityDelegate.value
62
- params.humidityDelegate.on('didSet', (value) => {
63
- this.entry.h = value
64
- })
65
- if (params.airPressureDelegate != null) {
66
- if (!(params.airPressureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
67
- throw new TypeError('params.airPressureDelegate: not a CharacteristicDelegate')
68
- }
69
- this.entry.p = params.airPressureDelegate.value
70
- params.airPressureDelegate.on('didSet', (value) => {
71
- this.entry.p = value
72
- })
73
- }
74
- }
75
- }
76
-
77
- get fingerPrint () { return '03 0102 0202 0302' }
78
-
79
- entryToBuffer (entry) {
80
- const buffer = Buffer.alloc(7)
81
- let o = 0
82
- if (entry.h == null) {
83
- buffer.writeUInt8(0x01, o); o += 1
84
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
85
- return buffer.slice(0, o)
86
- }
87
- if (entry.p == null) {
88
- buffer.writeUInt8(0x03, o); o += 1
89
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
90
- buffer.writeUInt16LE(entry.h * 100, o); o += 2
91
- return buffer.slice(0, o)
92
- }
93
- buffer.writeUInt8(0x07, o); o += 1
94
- buffer.writeUInt16LE(entry.t * 100, o); o += 2
95
- buffer.writeUInt16LE(entry.h * 100, o); o += 2
96
- buffer.writeUInt16LE(entry.p * 10, o); o += 2
97
- return buffer.slice(0, o)
98
- }
99
- }
100
-
101
- module.exports = Weather