homebridge-lib 5.2.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,114 @@
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
+ humidity: 0,
79
+ pressure: 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 (pressureDelegate != null) {
90
+ this._entry.pressure = pressureDelegate.value
91
+ pressureDelegate.on('didSet', (value) => {
92
+ this._entry.pressure = value
93
+ })
94
+ }
95
+ }
96
+ }
97
+
98
+ get _fingerPrint () {
99
+ return '03 0102 0202 0302'
100
+ }
101
+
102
+ _entryStream (entry) {
103
+ return util.format(
104
+ '|10 %s %s 07 %s %s %s',
105
+ numToHex(swap32(this._h.currentEntry), 8),
106
+ numToHex(swap32(entry.time - this._h.initialTime), 8),
107
+ numToHex(swap16(entry.temp * 100), 4),
108
+ numToHex(swap16(entry.humidity * 100), 4),
109
+ numToHex(swap16(entry.pressure * 10), 4)
110
+ )
111
+ }
112
+ }
113
+
114
+ module.exports = Weather