homebridge-lib 6.0.2 → 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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/cli/hap.js +1 -1
  3. package/cli/json.js +1 -1
  4. package/cli/sysinfo.js +1 -1
  5. package/cli/upnp.js +1 -1
  6. package/index.js +1 -1
  7. package/lib/AccessoryDelegate.js +30 -27
  8. package/lib/AdaptiveLighting.js +1 -1
  9. package/lib/CharacteristicDelegate.js +22 -36
  10. package/lib/Colour.js +1 -1
  11. package/lib/CommandLineParser.js +1 -1
  12. package/lib/CommandLineTool.js +1 -1
  13. package/lib/CustomHomeKitTypes.js +1 -1
  14. package/lib/Delegate.js +31 -33
  15. package/lib/EveHomeKitTypes.js +62 -52
  16. package/lib/HttpClient.js +1 -1
  17. package/lib/JsonFormatter.js +1 -1
  18. package/lib/MyHomeKitTypes.js +88 -97
  19. package/lib/OptionParser.js +27 -2
  20. package/lib/Platform.js +3 -17
  21. package/lib/PropertyDelegate.js +8 -11
  22. package/lib/ServiceDelegate/AccessoryInformation.js +1 -1
  23. package/lib/ServiceDelegate/Battery.js +1 -1
  24. package/lib/ServiceDelegate/Dummy.js +1 -1
  25. package/lib/ServiceDelegate/History/Consumption.js +31 -49
  26. package/lib/ServiceDelegate/History/Contact.js +14 -22
  27. package/lib/ServiceDelegate/History/Light.js +15 -23
  28. package/lib/ServiceDelegate/History/LightLevel.js +113 -0
  29. package/lib/ServiceDelegate/History/Motion.js +67 -80
  30. package/lib/ServiceDelegate/History/On.js +27 -33
  31. package/lib/ServiceDelegate/History/Power.js +46 -52
  32. package/lib/ServiceDelegate/History/Room.js +28 -50
  33. package/lib/ServiceDelegate/History/Thermo.js +19 -33
  34. package/lib/ServiceDelegate/History/Weather.js +33 -56
  35. package/lib/ServiceDelegate/History/index.js +155 -182
  36. package/lib/ServiceDelegate/ServiceLabel.js +1 -1
  37. package/lib/ServiceDelegate/index.js +13 -10
  38. package/lib/SystemInfo.js +3 -2
  39. package/lib/UiServer.js +1 -1
  40. package/lib/UpnpClient.js +1 -1
  41. package/package.json +2 -2
@@ -1,20 +1,13 @@
1
1
  // homebridge-lib/lib/ServiceDelegate/History/Motion.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2022 Erik Baauw. All rights reserved.
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 { ServiceDelegate } = homebridgeLib
16
- const { History } = ServiceDelegate
17
- const { swap16, swap32, numToHex } = History
10
+ const { History } = homebridgeLib.ServiceDelegate
18
11
 
19
12
  /** Class for an Eve Motion _History_ service delegate.
20
13
  *
@@ -33,6 +26,10 @@ const { swap16, swap32, numToHex } = History
33
26
  * This delegate creates the history from the associated
34
27
  * `Characteristics.hap.MotionDetected` characteristic. It updates the
35
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`.
36
33
  * @extends ServiceDelegate.History
37
34
  * @memberof ServiceDelegate.History
38
35
  */
@@ -57,7 +54,12 @@ class Motion extends History {
57
54
  * to the delegate of the associated `Characteristics.hap.CurrentTemperature`
58
55
  * characteristic.
59
56
  * For PIR sensors (like the Hue motion sensor) that report temperature in
60
- * addition to motion.
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.
61
63
  */
62
64
  constructor (accessoryDelegate, params) {
63
65
  super(accessoryDelegate, params)
@@ -67,88 +69,73 @@ class Motion extends History {
67
69
  if (!(params.lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
68
70
  throw new TypeError('params.lastActivationDelegate: not a CharacteristicDelegate')
69
71
  }
70
- if (
71
- params.lightLevelDelegate != null &&
72
- !(params.lightLevelDelegate instanceof homebridgeLib.CharacteristicDelegate)
73
- ) {
74
- throw new TypeError('params.lightLevelDelegate: not a CharacteristicDelegate')
75
- }
76
- if (
77
- params.temperatureDelegate != null &&
78
- !(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)
79
- ) {
80
- throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
81
- }
82
- this._entry = { time: 0, status: params.motionDelegate.value }
72
+ this.entry = { m: params.motionDelegate.value ? 1 : 0 }
83
73
  params.motionDelegate.on('didSet', (value) => {
84
- const now = Math.round(new Date().valueOf() / 1000)
85
- params.lastActivationDelegate.value = now - this._h.initialTime
86
- this._entry.status = value
87
- if (this._entry.temp != null) {
88
- const lightlevel = this._entry.lightlevel
89
- const temp = this._entry.temp
90
- this._entry.lightlevel = null
91
- this._entry.temp = null
92
- this._addEntry(now)
93
- this._entry.lightlevel = lightlevel
94
- this._entry.temp = temp
95
- } else {
96
- this._addEntry(now)
97
- }
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 })
98
78
  })
99
79
  if (params.lightLevelDelegate != null) {
100
- this._entry.lightlevel = params.lightLevelDelegate.value
80
+ if (!(params.lightLevelDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
81
+ throw new TypeError('params.lightLevelDelegate: not a CharacteristicDelegate')
82
+ }
83
+ this.entry.l = params.lightLevelDelegate.value
101
84
  params.lightLevelDelegate.on('didSet', (value) => {
102
- this._entry.lightlevel = value
103
- })
104
- }
105
- if (params.temperatureDelegate != null) {
106
- this._entry.temp = params.temperatureDelegate.value
107
- params.temperatureDelegate.on('didSet', (value) => {
108
- this._entry.temp = value
85
+ this.entry.l = value
109
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
+ }
110
105
  }
111
106
  }
112
107
 
113
- get _fingerPrint () {
114
- return '03 1C01 3002 0102'
108
+ get fingerPrint () {
109
+ return '04 1C01 3002 0102 0202'
115
110
  }
116
111
 
117
- _entryStream (entry) {
118
- if (entry.temp == null) {
119
- if (entry.lightlevel == null) {
120
- return util.format(
121
- '|0b %s %s 01 %s',
122
- numToHex(swap32(this._h.currentEntry), 8),
123
- numToHex(swap32(entry.time - this._h.initialTime), 8),
124
- numToHex(entry.status, 2)
125
- )
126
- }
127
- return util.format(
128
- '|0d %s %s 03 %s %s',
129
- numToHex(swap32(this._h.currentEntry), 8),
130
- numToHex(swap32(entry.time - this._h.initialTime), 8),
131
- numToHex(entry.status, 2),
132
- numToHex(swap16(entry.lightlevel), 4)
133
- )
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)
134
125
  }
135
- if (entry.lightlevel == null) {
136
- return util.format(
137
- '|0d %s %s 05 %s %s',
138
- numToHex(swap32(this._h.currentEntry), 8),
139
- numToHex(swap32(entry.time - this._h.initialTime), 8),
140
- numToHex(entry.status, 2),
141
- numToHex(swap16(entry.temp * 100), 4)
142
- )
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)
143
132
  }
144
- return util.format(
145
- '|0f %s %s 07 %s %s %s',
146
- numToHex(swap32(this._h.currentEntry), 8),
147
- numToHex(swap32(entry.time - this._h.initialTime), 8),
148
- numToHex(entry.status, 2),
149
- numToHex(swap16(entry.lightlevel), 4),
150
- numToHex(swap16(entry.temp * 100), 4)
151
- )
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)
152
139
  }
153
140
  }
154
141
 
@@ -1,20 +1,13 @@
1
1
  // homebridge-lib/lib/ServiceDelegate/History/On.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2022 Erik Baauw. All rights reserved.
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 { ServiceDelegate } = homebridgeLib
16
- const { History } = ServiceDelegate
17
- const { swap32, numToHex } = History
10
+ const { History } = homebridgeLib.ServiceDelegate
18
11
 
19
12
  /** Class for a Raspberry Pi _History_ service delegate.
20
13
  *
@@ -61,41 +54,42 @@ class On extends History {
61
54
  ) {
62
55
  throw new TypeError('params.lastActivationDelegate: not a CharacteristicDelegate')
63
56
  }
64
- if (
65
- params.temperatureDelegate != null &&
66
- !(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)
67
- ) {
68
- throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
69
- }
70
- this._entry = {
71
- time: 0,
72
- on: params.onDelegate.value ? 1 : 0
73
- }
57
+
58
+ this.entry = { o: params.onDelegate.value ? 1 : 0 }
74
59
  params.onDelegate.on('didSet', (value) => {
75
- const now = Math.round(new Date().valueOf() / 1000)
60
+ const now = History.now()
76
61
  if (params.lastActivationDelegate != null) {
77
- params.lastActivationDelegate.value = now - this._h.initialTime
62
+ params.lastActivationDelegate.value = this.lastActivationValue(now)
78
63
  }
79
- this._entry.on = value ? 1 : 0
80
- this._addEntry(now)
64
+ this.entry.o = value ? 1 : 0
65
+ this.addEntry({ time: now, o: this.entry.o })
81
66
  })
67
+
82
68
  if (params.temperatureDelegate != null) {
83
- this._entry.temp = params.temperatureDelegate.value
69
+ if (!(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
70
+ throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
71
+ }
72
+ this.entry.t = params.temperatureDelegate.value
84
73
  params.temperatureDelegate.on('didSet', (value) => {
85
- this._entry.temp = value
74
+ this.entry.t = value
86
75
  })
87
76
  }
88
77
  }
89
78
 
90
- get _fingerPrint () { return '01 0E01' }
79
+ get fingerPrint () { return '01 0E01 0102' }
91
80
 
92
- _entryStream (entry) {
93
- return util.format(
94
- '|0b %s %s 01 %s',
95
- numToHex(swap32(this._h.currentEntry), 8),
96
- numToHex(swap32(entry.time - this._h.initialTime), 8),
97
- numToHex(entry.on, 2)
98
- )
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
86
+ buffer.writeUInt8(entry.o, o); o += 1
87
+ return buffer.slice(0, o)
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
92
+ return buffer.slice(0, o)
99
93
  }
100
94
  }
101
95
 
@@ -1,20 +1,13 @@
1
1
  // homebridge-lib/lib/ServiceDelegate/History/Power.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2022 Erik Baauw. All rights reserved.
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 { ServiceDelegate } = homebridgeLib
16
- const { History } = ServiceDelegate
17
- const { swap16, swap32, numToHex } = History
10
+ const { History } = homebridgeLib.ServiceDelegate
18
11
 
19
12
  /** Class for an Eve Energy _History_ service delegate.
20
13
  *
@@ -49,8 +42,11 @@ class Power extends History {
49
42
  * @param {!CharacteristicDelegate} params.consumptionDelegate - A reference
50
43
  * to the delegate of the associated `Characteristics.eve.TotalConsumption`
51
44
  * characteristic.
52
- * @param {!CharacteristicDelegate} params.onDelegate - A reference to the
45
+ * @param {?CharacteristicDelegate} params.onDelegate - A reference to the
53
46
  * delegate of the associated `Characteristics.hap.On` characteristic.
47
+ * @param {?CharacteristicDelegate} params.lastActivationDelegate - A
48
+ * reference to the delegate of the associated
49
+ * `Characteristics.eve.LastActivation` characteristic.
54
50
  */
55
51
  constructor (accessoryDelegate, params) {
56
52
  super(accessoryDelegate, params)
@@ -64,15 +60,24 @@ class Power extends History {
64
60
  params.onDelegate != null &&
65
61
  !(params.onDelegate instanceof homebridgeLib.CharacteristicDelegate)
66
62
  ) {
67
- throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
63
+ throw new TypeError('params.onDelegate: not a CharacteristicDelegate')
64
+ }
65
+ if (
66
+ params.lastActivationDelegate != null &&
67
+ !(params.lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)
68
+ ) {
69
+ throw new TypeError('params.lastActivationDelegate: not a CharacteristicDelegate')
68
70
  }
69
71
  this._powerDelegate = params.powerDelegate
70
72
  this._consumptionDelegate = params.consumptionDelegate
71
- this._entry = { time: 0, power: 0 }
73
+
74
+ this.entry = { p: 0 }
72
75
  this._runningConsumption = 0 // 10-min-interval running value
73
76
  this._totalConsumption = params.consumptionDelegate.value // life-time value
77
+ this._power = params.powerDelegate.value // current power
78
+ this._time = History.now // start time of current power
74
79
  params.powerDelegate.on('didSet', (value) => {
75
- const now = Math.round(new Date().valueOf() / 1000)
80
+ const now = History.now
76
81
  if (this._time != null) {
77
82
  const delta = this._power * (now - this._time) // Ws
78
83
  this._runningConsumption += Math.round(delta / 60.0) // 0.1W * 10 min
@@ -81,6 +86,7 @@ class Power extends History {
81
86
  this._power = value
82
87
  this._time = now
83
88
  })
89
+
84
90
  this.addCharacteristicDelegate({
85
91
  key: 'resetTotal',
86
92
  Characteristic: this.Characteristics.eve.ResetTotal,
@@ -90,66 +96,54 @@ class Power extends History {
90
96
  this._totalConsumption = 0
91
97
  this._consumptionDelegate.value = this._totalConsumption
92
98
  })
99
+
93
100
  if (params.onDelegate != null) {
94
- this._entry.on = params.onDelegate.value ? 1 : 0
101
+ this.entry.o = params.onDelegate.value ? 1 : 0
95
102
  params.onDelegate.on('didSet', (value) => {
96
- const now = Math.round(new Date().valueOf() / 1000)
103
+ const now = History.now
97
104
  if (params.lastActivationDelegate != null) {
98
- params.lastActivationDelegate.value = now - this._h.initialTime
105
+ params.lastActivationDelegate.value = this.lastActivationValue(now)
99
106
  }
100
- this._entry.on = value ? 1 : 0
101
- const power = this._entry.power
102
- this._entry.power = null
103
- super._addEntry(now)
104
- this._entry.power = power
107
+ this.entry.o = value ? 1 : 0
108
+ super.addEntry({ time: now, o: this.entry.o })
105
109
  })
106
110
  }
107
111
  }
108
112
 
109
- _addEntry () {
110
- const now = Math.round(new Date().valueOf() / 1000)
113
+ addEntry (entry) {
111
114
  // Sensor delivers currentConsumption, compute totalConsumption
112
115
  if (this._time != null) {
113
- const delta = this._power * (now - this._time) // Ws
116
+ const delta = this._power * (entry.time - this._time) // Ws
114
117
  this._runningConsumption += delta / 60.0 // 0.1 W * 10 min
115
118
  this._totalConsumption += delta / 36000.0 // 0.01 kWh
116
119
  this._consumptionDelegate.value = Math.round(this._totalConsumption) / 100.0 // kWh
117
- this._entry.power = Math.round(this._runningConsumption) // 0.1 W * 10 min
118
- super._addEntry(now)
119
- } else if (this._entry.on != null) {
120
- super._addEntry(now)
120
+ entry.p = Math.round(this._runningConsumption) // 0.1 W * 10 min
121
121
  }
122
+ super.addEntry(entry)
122
123
  this._power = this._powerDelegate.value
123
- this._time = now
124
+ this._time = entry.time
124
125
  this._runningConsumption = 0
125
126
  }
126
127
 
127
- get _fingerPrint () { return '02 0702 0E01' }
128
+ get fingerPrint () { return '02 0702 0E01' }
128
129
 
129
- _entryStream (entry) {
130
- if (entry.on == null) {
131
- return util.format(
132
- '|0c %s %s 01 %s',
133
- numToHex(swap32(this._h.currentEntry), 8),
134
- numToHex(swap32(entry.time - this._h.initialTime), 8),
135
- numToHex(swap16(entry.power), 4)
136
- )
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
135
+ buffer.writeUInt16LE(entry.p, o); o += 2
136
+ return buffer.slice(0, o)
137
137
  }
138
- if (entry.power == null) {
139
- return util.format(
140
- '|0b %s %s 02 %s',
141
- numToHex(swap32(this._h.currentEntry), 8),
142
- numToHex(swap32(entry.time - this._h.initialTime), 8),
143
- numToHex(entry.on, 2)
144
- )
138
+ if (entry.p == null) {
139
+ buffer.writeUInt8(0x02, o); o += 1
140
+ buffer.writeUInt8(entry.o, o); o += 1
141
+ return buffer.slice(0, o)
145
142
  }
146
- return util.format(
147
- '|0d %s %s 03 %s %s',
148
- numToHex(swap32(this._h.currentEntry), 8),
149
- numToHex(swap32(entry.time - this._h.initialTime), 8),
150
- numToHex(swap16(entry.power), 4),
151
- numToHex(entry.on, 2)
152
- )
143
+ buffer.writeUInt8(0x03, o); o += 1
144
+ buffer.writeUInt16LE(entry.p, o); o += 2
145
+ buffer.writeUInt8(entry.o, o); o += 1
146
+ return buffer.slice(0, o)
153
147
  }
154
148
  }
155
149
 
@@ -1,20 +1,13 @@
1
1
  // homebridge-lib/lib/ServiceDelegate/History/Room.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2022 Erik Baauw. All rights reserved.
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 { ServiceDelegate } = homebridgeLib
16
- const { History } = ServiceDelegate
17
- const { swap16, swap32, numToHex } = History
10
+ const { History } = homebridgeLib.ServiceDelegate
18
11
 
19
12
  /** Class for an Eve Room _History_ service delegate.
20
13
  *
@@ -36,8 +29,8 @@ const { swap16, swap32, numToHex } = History
36
29
  * @extends ServiceDelegate.History
37
30
  * @memberof ServiceDelegate.History
38
31
  */
39
- class Room extends ServiceDelegate.History {
40
- /** Create a new instance of an Eve Weather _History_ service delegate.
32
+ class Room extends History {
33
+ /** Create a new instance of an Eve Room _History_ service delegate.
41
34
  * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
42
35
  * corresponding HomeKit accessory.
43
36
  * @param {!object} params - The parameters for the
@@ -45,10 +38,10 @@ class Room extends ServiceDelegate.History {
45
38
  * @param {!CharacteristicDelegate} params.temperatureDelegate - A reference
46
39
  * to the delegate of the associated `Characteristics.hap.CurrentTemperature`
47
40
  * characteristic.
48
- * @param {?CharacteristicDelegate} params.humidityDelegate - A reference to
41
+ * @param {!CharacteristicDelegate} params.humidityDelegate - A reference to
49
42
  * the delegate of the associated
50
43
  * `Characteristics.hap.CurrentRelativeHumidity` characteristic.
51
- * @param {?CharacteristicDelegate} params.vocDensityDelegate - A reference
44
+ * @param {!CharacteristicDelegate} params.vocDensityDelegate - A reference
52
45
  * to the delegate of the associated `Characteristics.eve.AirPressure`
53
46
  * characteristic.
54
47
  */
@@ -57,55 +50,40 @@ class Room extends ServiceDelegate.History {
57
50
  if (!(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
58
51
  throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
59
52
  }
60
- if (
61
- params.humidityDelegate != null &&
62
- !(params.humidityDelegate instanceof homebridgeLib.CharacteristicDelegate)
63
- ) {
53
+ if (!(params.humidityDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
64
54
  throw new TypeError('params.humidityDelegate: not a CharacteristicDelegate')
65
55
  }
66
- if (
67
- params.vocDensityDelegate != null &&
68
- !(params.vocDensityDelegate instanceof homebridgeLib.CharacteristicDelegate)
69
- ) {
56
+ if (!(params.vocDensityDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
70
57
  throw new TypeError('params.vocDensityDelegate: not a CharacteristicDelegate')
71
58
  }
72
- this._entry = {
73
- time: 0,
74
- temp: params.temperatureDelegate.value,
75
- humidity: 0,
76
- voc: 0
59
+ this.entry = {
60
+ t: params.temperatureDelegate.value,
61
+ h: params.humidityDelegate.value,
62
+ v: params.vocDensityDelegate.value
77
63
  }
78
64
  params.temperatureDelegate.on('didSet', (value) => {
79
- this._entry.temp = 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
80
72
  })
81
- if (params.humidityDelegate != null) {
82
- this._entry.humidity = params.humidityDelegate.value
83
- params.humidityDelegate.on('didSet', (value) => {
84
- this._entry.humidity = value
85
- })
86
- if (params.vocDensityDelegate != null) {
87
- this._entry.voc = params.vocDensityDelegate.value
88
- params.vocDensityDelegate.on('didSet', (value) => {
89
- this._entry.voc = value
90
- })
91
- }
92
- }
93
73
  }
94
74
 
95
- get _fingerPrint () {
96
- // return '07 0102 0202 2202 2901 2501 2302 2801'
75
+ get fingerPrint () {
97
76
  return '03 0102 0202 2202'
98
77
  }
99
78
 
100
- _entryStream (entry) {
101
- return util.format(
102
- '|10 %s %s 07 %s %s %s',
103
- numToHex(swap32(this._h.currentEntry), 8),
104
- numToHex(swap32(entry.time - this._h.initialTime), 8),
105
- numToHex(swap16(entry.temp * 100), 4),
106
- numToHex(swap16(entry.humidity * 100), 4),
107
- numToHex(swap16(entry.voc), 4)
108
- )
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)
109
87
  }
110
88
  }
111
89
 
@@ -1,20 +1,13 @@
1
1
  // homebridge-lib/lib/ServiceDelegate/History/Thermo.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2022 Erik Baauw. All rights reserved.
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 { ServiceDelegate } = homebridgeLib
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 ServiceDelegate.History {
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._entry = {
67
- time: 0,
68
- currentTemp: params.temperatureDelegate.value,
69
- setTemp: params.targetTemperatureDelegate.value,
70
- valvePosition: params.valvePositionDelegate.value
59
+ this.entry = {
60
+ t: params.temperatureDelegate.value,
61
+ s: params.targetTemperatureDelegate.value,
62
+ v: params.valvePositionDelegate.value
71
63
  }
72
64
  params.temperatureDelegate.on('didSet', (value) => {
73
- this._entry.currentTemp = value
65
+ this.entry.t = value
74
66
  })
75
67
  params.targetTemperatureDelegate.on('didSet', (value) => {
76
- this._entry.setTemp = value
68
+ this.entry.s = value
77
69
  })
78
70
  params.valvePositionDelegate.on('didSet', (value) => {
79
- this._entry.valvePosition = value
71
+ this.entry.v = value
80
72
  })
81
73
  }
82
74
 
83
- // I think 1201 and 1d01 are for current mode and target more, but it doesn't
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
- _entryStream (entry) {
90
- return util.format(
91
- // '|11 %s %s 1f %s %s %s 00 00',
92
- '|0f %s %s 07 %s %s %s',
93
- numToHex(swap32(this._h.currentEntry), 8),
94
- numToHex(swap32(entry.time - this._h.initialTime), 8),
95
- numToHex(swap16(entry.currentTemp * 100), 4),
96
- numToHex(swap16(entry.setTemp * 100), 4),
97
- numToHex(entry.valvePosition, 2)
98
- )
77
+ entryToBuffer (entry) {
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
83
+ buffer.writeUInt8(entry.v, o); o += 1
84
+ return buffer.slice(0, o)
99
85
  }
100
86
  }
101
87