homebridge-lib 5.2.0 → 5.2.3

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.
@@ -0,0 +1,118 @@
1
+ // homebridge-lib/lib/ServiceDelegate/History/Motion.js
2
+ //
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.
9
+
10
+ 'use strict'
11
+
12
+ const homebridgeLib = require('../../../index')
13
+ const util = require('util')
14
+
15
+ const { ServiceDelegate } = homebridgeLib
16
+ const { History } = ServiceDelegate
17
+ const { swap16, swap32, numToHex } = History
18
+
19
+ /** Class for an Eve Motion _History_ service delegate.
20
+ *
21
+ * This delegate sets up a `Services.eve.History` HomeKit service
22
+ * with keys for the following HomeKit characteristics:
23
+ *
24
+ * key | Characteristic
25
+ * ---------------- | ----------------------------------
26
+ * `name` | `Characteristics.hap.Name`
27
+ * `historyRequest` | `Characteristics.eve.HistoryRequest`
28
+ * `setTime` | `Characteristics.eve.SetTime`
29
+ * `historyStatus` | `Characteristics.eve.HistoryStatus`
30
+ * `historyEntries` | `Characteristics.eve.HistoryEntries`
31
+ * `resetTotal` | `Characteristics.eve.ResetTotal`
32
+ *
33
+ * This delegate creates the history from the associated
34
+ * `Characteristics.hap.MotionDetected` characteristic. It updates the
35
+ * value of the associated `Characteristics.eve.LastActivation` characteristic.
36
+ * @extends ServiceDelegate.History
37
+ * @memberof ServiceDelegate.History
38
+ */
39
+ class Motion extends History {
40
+ /** Create a new instance of an Eve Motion _History_ service delegate.
41
+ * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
42
+ * corresponding HomeKit accessory.
43
+ * @param {!object} params - The parameters for the
44
+ * _History_ HomeKit service.
45
+ * @param {!CharacteristicDelegate} motionDelegate - A reference to the
46
+ * delegate of the associated `Characteristics.hap.MotionDetected`
47
+ * characteristic.
48
+ * @param {!CharacteristicDelegate} lastActivationDelegate - A reference to the
49
+ * delegate of the associated `Characteristics.eve.LastActivation`
50
+ * characteristic.
51
+ * @param {?CharacteristicDelegate} temperatureDelegate - A reference to the
52
+ * delegate of the associated `Characteristics.hap.CurrentTemperature`
53
+ * characteristic. For PIR sensors (like the Hue motion sensor) that report
54
+ * temperature in addition to motion.
55
+ */
56
+ constructor (
57
+ accessoryDelegate, params,
58
+ motionDelegate, lastActivationDelegate, temperatureDelegate
59
+ ) {
60
+ super(accessoryDelegate, params)
61
+ if (!(motionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
62
+ throw new TypeError('motionDelegate: not a CharacteristicDelegate')
63
+ }
64
+ if (!(lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
65
+ throw new TypeError('lastActivationDelegate: not a CharacteristicDelegate')
66
+ }
67
+ if (
68
+ temperatureDelegate != null &&
69
+ !(temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)
70
+ ) {
71
+ throw new TypeError('temperatureDelegate: not a CharacteristicDelegate')
72
+ }
73
+ this._entry = { time: 0, status: motionDelegate.value }
74
+ motionDelegate.on('didSet', (value) => {
75
+ const now = Math.round(new Date().valueOf() / 1000)
76
+ lastActivationDelegate.value = now - this._h.initialTime
77
+ this._entry.status = value
78
+ if (this._entry.temp != null) {
79
+ const temp = this._entry.temp
80
+ this._entry.temp = null
81
+ this._addEntry(now)
82
+ this._entry.temp = temp
83
+ } else {
84
+ this._addEntry(now)
85
+ }
86
+ })
87
+ if (temperatureDelegate != null) {
88
+ this._entry.temp = temperatureDelegate.value
89
+ temperatureDelegate.on('didSet', (value) => {
90
+ this._entry.temp = value
91
+ })
92
+ }
93
+ }
94
+
95
+ get _fingerPrint () {
96
+ return '02 1c01 0102'
97
+ }
98
+
99
+ _entryStream (entry) {
100
+ if (entry.temp == null) {
101
+ return util.format(
102
+ '|0b %s %s 01 %s',
103
+ numToHex(swap32(this._h.currentEntry), 8),
104
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
105
+ numToHex(entry.status, 2)
106
+ )
107
+ }
108
+ return util.format(
109
+ '|0d %s %s 03 %s %s',
110
+ numToHex(swap32(this._h.currentEntry), 8),
111
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
112
+ numToHex(entry.status, 2),
113
+ numToHex(swap16(entry.temp * 100), 4)
114
+ )
115
+ }
116
+ }
117
+
118
+ module.exports = Motion
@@ -0,0 +1,86 @@
1
+ // homebridge-lib/lib/ServiceDelegate/History/On.js
2
+ //
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.
9
+
10
+ 'use strict'
11
+
12
+ const homebridgeLib = require('../../../index')
13
+ const util = require('util')
14
+
15
+ const { ServiceDelegate } = homebridgeLib
16
+ const { History } = ServiceDelegate
17
+ const { swap32, numToHex } = History
18
+
19
+ /** Class for a Raspberry Pi _History_ service delegate.
20
+ *
21
+ * This delegate sets up a `Services.eve.History` HomeKit service
22
+ * with keys for the following HomeKit characteristics:
23
+ *
24
+ * key | Characteristic
25
+ * ---------------- | ----------------------------------
26
+ * `name` | `Characteristics.hap.Name`
27
+ * `historyRequest` | `Characteristics.eve.HistoryRequest`
28
+ * `setTime` | `Characteristics.eve.SetTime`
29
+ * `historyStatus` | `Characteristics.eve.HistoryStatus`
30
+ * `historyEntries` | `Characteristics.eve.HistoryEntries`
31
+ *
32
+ * This delegate creates the history from the associated
33
+ * `Characteristics.hap.On` characteristic.
34
+ * @extends ServiceDelegate.History
35
+ * @memberof ServiceDelegate.History
36
+ */
37
+ class On extends History {
38
+ /** Create a new instance of a Raspberry Pi _History_ service delegate.
39
+ * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
40
+ * corresponding HomeKit accessory.
41
+ * @param {!object} params - The parameters for the
42
+ * _History_ HomeKit service.
43
+ * @param {!CharacteristicDelegate} onDelegate - A reference to the
44
+ * delegate of the associated `Characteristics.hap.On`
45
+ * characteristic.
46
+ */
47
+ constructor (accessoryDelegate, params, onDelegate, temperatureDelegate) {
48
+ super(accessoryDelegate, params)
49
+ if (!(onDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
50
+ throw new TypeError('onDelegate: not a CharacteristicDelegate')
51
+ }
52
+ if (
53
+ temperatureDelegate != null &&
54
+ !(temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)
55
+ ) {
56
+ throw new TypeError('temperatureDelegate: not a CharacteristicDelegate')
57
+ }
58
+ this._entry = {
59
+ time: 0,
60
+ on: onDelegate.value ? 1 : 0
61
+ }
62
+ onDelegate.on('didSet', (value) => {
63
+ this._entry.on = value ? 1 : 0
64
+ this._addEntry()
65
+ })
66
+ if (temperatureDelegate != null) {
67
+ this._entry.temp = temperatureDelegate.value
68
+ temperatureDelegate.on('didSet', (value) => {
69
+ this._entry.temp = value
70
+ })
71
+ }
72
+ }
73
+
74
+ get _fingerPrint () { return '01 0e01' }
75
+
76
+ _entryStream (entry) {
77
+ return util.format(
78
+ '|0b %s %s 01 %s',
79
+ numToHex(swap32(this._h.currentEntry), 8),
80
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
81
+ numToHex(entry.on, 2)
82
+ )
83
+ }
84
+ }
85
+
86
+ module.exports = On
@@ -0,0 +1,121 @@
1
+ // homebridge-lib/lib/ServiceDelegate/History/Power.js
2
+ //
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.
9
+
10
+ 'use strict'
11
+
12
+ const homebridgeLib = require('../../../index')
13
+ const util = require('util')
14
+
15
+ const { ServiceDelegate } = homebridgeLib
16
+ const { History } = ServiceDelegate
17
+ const { swap16, swap32, numToHex } = History
18
+
19
+ /** Class for an Eve Energy _History_ service delegate.
20
+ *
21
+ * This delegate sets up a `Services.eve.History` HomeKit service
22
+ * with keys for the following HomeKit characteristics:
23
+ *
24
+ * key | Characteristic
25
+ * ---------------- | ----------------------------------
26
+ * `name` | `Characteristics.hap.Name`
27
+ * `historyRequest` | `Characteristics.eve.HistoryRequest`
28
+ * `setTime` | `Characteristics.eve.SetTime`
29
+ * `historyStatus` | `Characteristics.eve.HistoryStatus`
30
+ * `historyEntries` | `Characteristics.eve.HistoryEntries`
31
+ * `resetTotal` | `Characteristics.eve.ResetTotal`
32
+ *
33
+ * This delegate is for sensors that don't report life-time consumption. The
34
+ * history from the value of the associated
35
+ * `Characteristics.eve.CurrentConsumption` over time. It updates the value of
36
+ * the associated `Characteristics.eve.TotalConsumption` characteristic.
37
+ * @extends ServiceDelegate.History
38
+ * @memberof ServiceDelegate.History
39
+ */
40
+ class Power extends History {
41
+ /** Create a new instance of an Eve Energy _History_ service delegate.
42
+ * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
43
+ * corresponding HomeKit accessory.
44
+ * @param {!object} params - The parameters for the
45
+ * _History_ HomeKit service.
46
+ * @param {!CharacteristicDelegate} powerDelegate - A reference to the
47
+ * delegate of the associated `Characteristics.eve.CurrentConsumption`
48
+ * characteristic.
49
+ * @param {!CharacteristicDelegate} consumptionDelegate - A reference to the
50
+ * delegate of the associated `Characteristics.eve.TotalConsumption`
51
+ * characteristic.
52
+ */
53
+ constructor (
54
+ accessoryDelegate, params,
55
+ powerDelegate, consumptionDelegate
56
+ ) {
57
+ super(accessoryDelegate, params)
58
+ if (!(powerDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
59
+ throw new TypeError('powerDelegate: not a CharacteristicDelegate')
60
+ }
61
+ if (!(consumptionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
62
+ throw new TypeError('consumptionDelegate: not a CharacteristicDelegate')
63
+ }
64
+ this._powerDelegate = powerDelegate
65
+ this._consumptionDelegate = consumptionDelegate
66
+ this._entry = { time: 0, power: 0 }
67
+ this._runningConsumption = 0 // 10-min-interval running value
68
+ this._totalConsumption = consumptionDelegate.value // life-time value
69
+ powerDelegate.on('didSet', (value) => {
70
+ const now = Math.round(new Date().valueOf() / 1000)
71
+ if (this._time != null) {
72
+ const delta = this._power * (now - this._time) // Ws
73
+ this._runningConsumption += Math.round(delta / 600.0) // W * 10 min
74
+ this._totalConsumption += Math.round(delta / 3600.0) // Wh
75
+ }
76
+ this._power = value
77
+ this._time = now
78
+ })
79
+ this.addCharacteristicDelegate({
80
+ key: 'resetTotal',
81
+ Characteristic: this.Characteristics.eve.ResetTotal,
82
+ value: params.resetTotal
83
+ })
84
+ this._characteristicDelegates.resetTotal.on('didSet', (value) => {
85
+ this._runningConsumption = 0
86
+ this._totalConsumption = 0
87
+ this._consumptionDelegate.value = this._totalConsumption
88
+ })
89
+ }
90
+
91
+ _addEntry () {
92
+ // Sensor delivers currentConsumption, compute totalConsumption
93
+ const now = Math.round(new Date().valueOf() / 1000)
94
+ if (this._time != null) {
95
+ const delta = this._power * (now - this._time) // Ws
96
+ this._runningConsumption += Math.round(delta / 600.0) // W * 10 min
97
+ this._totalConsumption += Math.round(delta / 3600.0) // Wh
98
+ this._consumptionDelegate.value = this._totalConsumption
99
+ this._entry.power = this._runningConsumption
100
+ super._addEntry(now)
101
+ }
102
+ this._power = this._powerDelegate.value
103
+ this._time = now
104
+ this._runningConsumption = 0
105
+ }
106
+
107
+ // get _fingerPrint () { return '04 0102 0202 0702 0f03' }
108
+ get _fingerPrint () { return '01 0702' }
109
+
110
+ _entryStream (entry) {
111
+ return util.format(
112
+ // '|14 %s %s 1f 0000 0000 %s 0000 0000',
113
+ '|0c %s %s 01 %s',
114
+ numToHex(swap32(this._h.currentEntry), 8),
115
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
116
+ numToHex(swap16(entry.power * 10), 4)
117
+ )
118
+ }
119
+ }
120
+
121
+ module.exports = Power
@@ -0,0 +1,115 @@
1
+ // homebridge-lib/lib/ServiceDelegate/History/Room.js
2
+ //
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.
9
+
10
+ 'use strict'
11
+
12
+ const homebridgeLib = require('../../../index')
13
+ const util = require('util')
14
+
15
+ const { ServiceDelegate } = homebridgeLib
16
+ const { History } = ServiceDelegate
17
+ const { swap16, swap32, numToHex } = History
18
+
19
+ /** Class for an Eve Room _History_ service delegate.
20
+ *
21
+ * This delegate sets up a `Services.eve.History` HomeKit service
22
+ * with keys for the following HomeKit characteristics:
23
+ *
24
+ * key | Characteristic
25
+ * ---------------- | ----------------------------------
26
+ * `name` | `Characteristics.hap.Name`
27
+ * `historyRequest` | `Characteristics.eve.HistoryRequest`
28
+ * `setTime` | `Characteristics.eve.SetTime`
29
+ * `historyStatus` | `Characteristics.eve.HistoryStatus`
30
+ * `historyEntries` | `Characteristics.eve.HistoryEntries`
31
+ *
32
+ * This delegate creates the history from the associated
33
+ * `Characteristics.hap.CurrentTemperature`,
34
+ * `Characteristics.hap.CurrentRelativeHumidity`, and
35
+ * `Characteristics.hap.VOCDensity` characteristics.
36
+ * @extends ServiceDelegate.History
37
+ * @memberof ServiceDelegate.History
38
+ */
39
+ class Room extends ServiceDelegate.History {
40
+ /** Create a new instance of an Eve Weather _History_ service delegate.
41
+ * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
42
+ * corresponding HomeKit accessory.
43
+ * @param {!object} params - The parameters for the
44
+ * _History_ HomeKit service.
45
+ * @param {!CharacteristicDelegate} temperatureDelegate - A reference to the
46
+ * delegate of the associated `Characteristics.hap.CurrentTemperature`
47
+ * characteristic.
48
+ * @param {?CharacteristicDelegate} humidityDelegate - A reference to the
49
+ * delegate of the associated `Characteristics.hap.CurrentRelativeHumidity`
50
+ * characteristic.
51
+ * @param {?CharacteristicDelegate} vocDensityDelegate - A reference to the
52
+ * delegate of the associated `Characteristics.eve.AirPressure`
53
+ * characteristic.
54
+ */
55
+ constructor (
56
+ accessoryDelegate, params,
57
+ temperatureDelegate, humidityDelegate, vocDensityDelegate
58
+ ) {
59
+ super(accessoryDelegate, params)
60
+ if (!(temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
61
+ throw new TypeError('temperatureDelegate: not a CharacteristicDelegate')
62
+ }
63
+ if (
64
+ humidityDelegate != null &&
65
+ !(humidityDelegate instanceof homebridgeLib.CharacteristicDelegate)
66
+ ) {
67
+ throw new TypeError('humidityDelegate: not a CharacteristicDelegate')
68
+ }
69
+ if (
70
+ vocDensityDelegate != null &&
71
+ !(vocDensityDelegate instanceof homebridgeLib.CharacteristicDelegate)
72
+ ) {
73
+ throw new TypeError('vocDensityDelegate: not a CharacteristicDelegate')
74
+ }
75
+ this._entry = {
76
+ time: 0,
77
+ temp: temperatureDelegate.value,
78
+ humidity: 0,
79
+ voc: 0
80
+ }
81
+ temperatureDelegate.on('didSet', (value) => {
82
+ this._entry.temp = value
83
+ })
84
+ if (humidityDelegate != null) {
85
+ this._entry.humidity = humidityDelegate.value
86
+ humidityDelegate.on('didSet', (value) => {
87
+ this._entry.humidity = value
88
+ })
89
+ if (vocDensityDelegate != null) {
90
+ this._entry.voc = vocDensityDelegate.value
91
+ vocDensityDelegate.on('didSet', (value) => {
92
+ this._entry.voc = value
93
+ })
94
+ }
95
+ }
96
+ }
97
+
98
+ get _fingerPrint () {
99
+ // return '07 0102 0202 2202 2901 2501 2302 2801'
100
+ return '03 0102 0202 2202'
101
+ }
102
+
103
+ _entryStream (entry) {
104
+ return util.format(
105
+ '|10 %s %s 07 %s %s %s',
106
+ numToHex(swap32(this._h.currentEntry), 8),
107
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
108
+ numToHex(swap16(entry.temp * 100), 4),
109
+ numToHex(swap16(entry.humidity * 100), 4),
110
+ numToHex(swap16(entry.voc), 4)
111
+ )
112
+ }
113
+ }
114
+
115
+ module.exports = Room
@@ -0,0 +1,102 @@
1
+ // homebridge-lib/lib/ServiceDelegate/History/Thermo.js
2
+ //
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.
9
+
10
+ 'use strict'
11
+
12
+ const homebridgeLib = require('../../../index')
13
+ const util = require('util')
14
+
15
+ const { ServiceDelegate } = homebridgeLib
16
+ const { History } = ServiceDelegate
17
+ const { swap16, swap32, numToHex } = History
18
+
19
+ /** Class for an Eve Thermo _History_ service delegate.
20
+ *
21
+ * This delegate sets up a `Services.eve.History` HomeKit service
22
+ * with keys for the following HomeKit characteristics:
23
+ *
24
+ * key | Characteristic
25
+ * ---------------- | ----------------------------------
26
+ * `name` | `Characteristics.hap.Name`
27
+ * `historyRequest` | `Characteristics.eve.HistoryRequest`
28
+ * `setTime` | `Characteristics.eve.SetTime`
29
+ * `historyStatus` | `Characteristics.eve.HistoryStatus`
30
+ * `historyEntries` | `Characteristics.eve.HistoryEntries`
31
+ *
32
+ * This delegate creates the history from the associated
33
+ * `Characteristics.hap.CurrentTemperature`,
34
+ * `Characteristics.hap.TargetTemperature`, and
35
+ * `Characteristics.eve.ValvePosition` characteristics.
36
+ * @extends ServiceDelegate.History
37
+ * @memberof ServiceDelegate.History
38
+ */
39
+ class Thermo extends ServiceDelegate.History {
40
+ /** Create a new instance of an Eve Thermo _History_ service delegate.
41
+ * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
42
+ * corresponding HomeKit accessory.
43
+ * @param {!object} params - The parameters for the
44
+ * _History_ HomeKit service.
45
+ * @param {!CharacteristicDelegate} temperatureDelegate - A reference to the
46
+ * delegate of the associated `Characteristics.hap.CurrentTemperature`
47
+ * characteristic.
48
+ * @param {!CharacteristicDelegate} targetTemperatureDelegate - A reference
49
+ * to the delegate of the associated `Characteristics.hap.TargetTemperature`
50
+ * characteristic.
51
+ * @param {!CharacteristicDelegate} valvePositionDelegate - A reference to
52
+ * the delegate of the associated `Characteristics.eve.ValvePosition`
53
+ * characteristic.
54
+ */
55
+ constructor (
56
+ accessoryDelegate, params,
57
+ temperatureDelegate, targetTemperatureDelegate, valvePositionDelegate
58
+ ) {
59
+ super(accessoryDelegate, params)
60
+ if (!(temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
61
+ throw new TypeError('temperatureDelegate: not a CharacteristicDelegate')
62
+ }
63
+ if (!(targetTemperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
64
+ throw new TypeError('targetTemperatureDelegate: not a CharacteristicDelegate')
65
+ }
66
+ if (!(valvePositionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
67
+ throw new TypeError('valvePositionDelegate: not a CharacteristicDelegate')
68
+ }
69
+ this._entry = {
70
+ time: 0,
71
+ currentTemp: temperatureDelegate.value,
72
+ setTemp: targetTemperatureDelegate.value,
73
+ valvePosition: valvePositionDelegate.value
74
+ }
75
+ temperatureDelegate
76
+ .on('didSet', (value) => { this._entry.currentTemp = value })
77
+ targetTemperatureDelegate
78
+ .on('didSet', (value) => { this._entry.setTemp = value })
79
+ valvePositionDelegate
80
+ .on('didSet', (value) => { this._entry.valvePosition = value })
81
+ }
82
+
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' }
88
+
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
+ )
99
+ }
100
+ }
101
+
102
+ module.exports = Thermo
@@ -0,0 +1,127 @@
1
+ // homebridge-lib/lib/ServiceDelegate/History/Weather.js
2
+ //
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.
9
+
10
+ 'use strict'
11
+
12
+ const homebridgeLib = require('../../../index')
13
+ const util = require('util')
14
+
15
+ const { ServiceDelegate } = homebridgeLib
16
+ const { History } = ServiceDelegate
17
+ const { swap16, swap32, numToHex } = History
18
+
19
+ /** Class for an Eve Weather _History_ service delegate.
20
+ *
21
+ * This delegate sets up a `Services.eve.History` HomeKit service
22
+ * with keys for the following HomeKit characteristics:
23
+ *
24
+ * key | Characteristic
25
+ * ---------------- | ----------------------------------
26
+ * `name` | `Characteristics.hap.Name`
27
+ * `historyRequest` | `Characteristics.eve.HistoryRequest`
28
+ * `setTime` | `Characteristics.eve.SetTime`
29
+ * `historyStatus` | `Characteristics.eve.HistoryStatus`
30
+ * `historyEntries` | `Characteristics.eve.HistoryEntries`
31
+ *
32
+ * This delegate creates the history from the associated
33
+ * `Characteristics.hap.CurrentTemperature`,
34
+ * `Characteristics.hap.CurrentRelativeHumidity`, and
35
+ * `Characteristics.eve.AirPressure` characteristics.
36
+ * @extends ServiceDelegate.History
37
+ * @memberof ServiceDelegate.History
38
+ */
39
+ class Weather extends ServiceDelegate.History {
40
+ /** Create a new instance of an Eve Weather _History_ service delegate.
41
+ * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
42
+ * corresponding HomeKit accessory.
43
+ * @param {!object} params - The parameters for the
44
+ * _History_ HomeKit service.
45
+ * @param {!CharacteristicDelegate} temperatureDelegate - A reference to the
46
+ * delegate of the associated `Characteristics.hap.CurrentTemperature`
47
+ * characteristic.
48
+ * @param {?CharacteristicDelegate} humidityDelegate - A reference to the
49
+ * delegate of the associated `Characteristics.hap.CurrentRelativeHumidity`
50
+ * characteristic.
51
+ * @param {?CharacteristicDelegate} pressureDelegate - A reference to the
52
+ * delegate of the associated `Characteristics.eve.AirPressure`
53
+ * characteristic.
54
+ */
55
+ constructor (
56
+ accessoryDelegate, params,
57
+ temperatureDelegate, humidityDelegate, pressureDelegate
58
+ ) {
59
+ super(accessoryDelegate, params)
60
+ if (!(temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
61
+ throw new TypeError('temperatureDelegate: not a CharacteristicDelegate')
62
+ }
63
+ if (
64
+ humidityDelegate != null &&
65
+ !(humidityDelegate instanceof homebridgeLib.CharacteristicDelegate)
66
+ ) {
67
+ throw new TypeError('humidityDelegate: not a CharacteristicDelegate')
68
+ }
69
+ if (
70
+ pressureDelegate != null &&
71
+ !(pressureDelegate instanceof homebridgeLib.CharacteristicDelegate)
72
+ ) {
73
+ throw new TypeError('pressureDelegate: not a CharacteristicDelegate')
74
+ }
75
+ this._entry = {
76
+ time: 0,
77
+ temp: temperatureDelegate.value
78
+ }
79
+ temperatureDelegate.on('didSet', (value) => {
80
+ this._entry.temp = value
81
+ })
82
+ if (humidityDelegate != null) {
83
+ this._entry.humidity = humidityDelegate.value
84
+ humidityDelegate.on('didSet', (value) => {
85
+ this._entry.humidity = value
86
+ })
87
+ if (pressureDelegate != null) {
88
+ this._entry.pressure = pressureDelegate.value
89
+ pressureDelegate.on('didSet', (value) => {
90
+ this._entry.pressure = value
91
+ })
92
+ }
93
+ }
94
+ }
95
+
96
+ get _fingerPrint () { return '03 0102 0202 0302' }
97
+
98
+ _entryStream (entry) {
99
+ if (entry.humidity == null) {
100
+ return util.format(
101
+ '|0c %s %s 01 %s',
102
+ numToHex(swap32(this._h.currentEntry), 8),
103
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
104
+ numToHex(swap16(entry.temp * 100), 4)
105
+ )
106
+ }
107
+ if (entry.pressure == null) {
108
+ return util.format(
109
+ '|0e %s %s 03 %s %s',
110
+ numToHex(swap32(this._h.currentEntry), 8),
111
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
112
+ numToHex(swap16(entry.temp * 100), 4),
113
+ numToHex(swap16(entry.humidity * 100), 4)
114
+ )
115
+ }
116
+ return util.format(
117
+ '|10 %s %s 07 %s %s %s',
118
+ numToHex(swap32(this._h.currentEntry), 8),
119
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
120
+ numToHex(swap16(entry.temp * 100), 4),
121
+ numToHex(swap16(entry.humidity * 100), 4),
122
+ numToHex(swap16(entry.pressure * 10), 4)
123
+ )
124
+ }
125
+ }
126
+
127
+ module.exports = Weather