homebridge-lib 6.2.1 → 6.3.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/ServiceDelegate/History.js +679 -0
- package/package.json +1 -1
- package/lib/ServiceDelegate/History/Consumption.js +0 -130
- package/lib/ServiceDelegate/History/Light.js +0 -74
- package/lib/ServiceDelegate/History/On.js +0 -98
- package/lib/ServiceDelegate/History/Power.js +0 -147
- package/lib/ServiceDelegate/History/Sensor.js +0 -215
- package/lib/ServiceDelegate/History/Thermo.js +0 -88
- package/lib/ServiceDelegate/History/index.js +0 -310
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// homebridge-lib/lib/ServiceDelegate/History/Consumption.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 Energy _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 is for sensors that report life-time consumption. The history
|
|
26
|
-
* is computed from the changes to the value of the associated
|
|
27
|
-
* `Characteristics.eve.TotalConsumption` characteristic. If the sensor doesn't
|
|
28
|
-
* also report power, this delegate can update the the value of the associated
|
|
29
|
-
* `Characteristics.eve.CurrentConsumption` characteristic.
|
|
30
|
-
*
|
|
31
|
-
* Note that the key in the history entry is called `power`, but its value
|
|
32
|
-
* is the consumption in Wh since the previous entry.
|
|
33
|
-
*
|
|
34
|
-
* @extends ServiceDelegate.History
|
|
35
|
-
* @memberof ServiceDelegate.History
|
|
36
|
-
*/
|
|
37
|
-
class Consumption extends History {
|
|
38
|
-
/** Create a new instance of an Eve Energy _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} params.consumptionDelegate - A reference
|
|
44
|
-
* to the delegate of the associated `Characteristics.eve.TotalConsumption`
|
|
45
|
-
* characteristic.
|
|
46
|
-
* @param {?CharacteristicDelegate} params.powerDelegate - A reference to the
|
|
47
|
-
* delegate of the associated `Characteristics.eve.CurrentConsumption`
|
|
48
|
-
* characteristic.
|
|
49
|
-
* @param {?CharacteristicDelegate} params.onDelegate - A reference to the
|
|
50
|
-
* delegate of the associated `Characteristics.hap.On` characteristic.
|
|
51
|
-
* @param {?CharacteristicDelegate} params.lastActivationDelegate - A
|
|
52
|
-
* reference to the delegate of the associated
|
|
53
|
-
* `Characteristics.eve.LastActivation` characteristic.
|
|
54
|
-
*/
|
|
55
|
-
constructor (accessoryDelegate, params = {}) {
|
|
56
|
-
super(accessoryDelegate, params)
|
|
57
|
-
if (!(params.consumptionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
58
|
-
throw new TypeError('params.consumptionDelegate: not a CharacteristicDelegate')
|
|
59
|
-
}
|
|
60
|
-
if (
|
|
61
|
-
params.powerDelegate != null &&
|
|
62
|
-
!(params.powerDelegate instanceof homebridgeLib.CharacteristicDelegate)
|
|
63
|
-
) {
|
|
64
|
-
throw new TypeError('params.powerDelegate: not a CharacteristicDelegate')
|
|
65
|
-
}
|
|
66
|
-
if (
|
|
67
|
-
params.onDelegate != null &&
|
|
68
|
-
!(params.onDelegate instanceof homebridgeLib.CharacteristicDelegate)
|
|
69
|
-
) {
|
|
70
|
-
throw new TypeError('params.onDelegate: not a CharacteristicDelegate')
|
|
71
|
-
}
|
|
72
|
-
if (
|
|
73
|
-
params.lastActivationDelegate != null &&
|
|
74
|
-
!(params.lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)
|
|
75
|
-
) {
|
|
76
|
-
throw new TypeError('params.lastActivationDelegate: not a CharacteristicDelegate')
|
|
77
|
-
}
|
|
78
|
-
this._consumptionDelegate = params.consumptionDelegate
|
|
79
|
-
this._powerDelegate = params.powerDelegate
|
|
80
|
-
|
|
81
|
-
this.entry = { p: 0 }
|
|
82
|
-
if (params.onDelegate != null) {
|
|
83
|
-
this.entry.o = params.onDelegate.value ? 1 : 0
|
|
84
|
-
params.onDelegate.on('didSet', (value) => {
|
|
85
|
-
const now = History.now()
|
|
86
|
-
if (params.lastActivationDelegate != null) {
|
|
87
|
-
params.lastActivationDelegate.value = this.lastActivationValue(now)
|
|
88
|
-
}
|
|
89
|
-
this.entry.o = value ? 1 : 0
|
|
90
|
-
super.addEntry({ time: now, o: this.entry.o })
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
addEntry (entry) {
|
|
96
|
-
// Sensor deliveres totalConsumption, optionally compute currentConsumption
|
|
97
|
-
if (this._consumption != null && this._time != null) {
|
|
98
|
-
const delta = this._consumptionDelegate.value - this._consumption // kWh
|
|
99
|
-
const period = entry.time - this._time // s
|
|
100
|
-
const power = 1000 * 3600 * delta / period // W
|
|
101
|
-
if (this._powerDelegate != null) {
|
|
102
|
-
this._powerDelegate.value = Math.round(power) // W
|
|
103
|
-
}
|
|
104
|
-
entry.p = Math.round(power * 10) // 0.1 W * 10 min
|
|
105
|
-
}
|
|
106
|
-
super.addEntry(entry)
|
|
107
|
-
this._consumption = this._consumptionDelegate.value
|
|
108
|
-
this._time = entry.time
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
get fingerPrint () { return '02 0702 0E01' }
|
|
112
|
-
|
|
113
|
-
entryToBuffer (entry) {
|
|
114
|
-
const buffer = Buffer.alloc(16)
|
|
115
|
-
let mask = 0
|
|
116
|
-
let o = 1
|
|
117
|
-
if (entry.p != null) {
|
|
118
|
-
mask |= 0x01
|
|
119
|
-
buffer.writeUInt16LE(entry.p, o); o += 2
|
|
120
|
-
}
|
|
121
|
-
if (entry.o != null) {
|
|
122
|
-
mask |= 0x02
|
|
123
|
-
buffer.writeUInt8(entry.o, o); o += 1
|
|
124
|
-
}
|
|
125
|
-
buffer.writeUInt8(mask, 0)
|
|
126
|
-
return buffer.slice(0, o)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
module.exports = Consumption
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
// homebridge-lib/lib/ServiceDelegate/History/On.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 Light Strip _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.On` characteristic. It updates the
|
|
27
|
-
* values of the associated `Characteristics.eve.LastActivation`
|
|
28
|
-
* characteristic.
|
|
29
|
-
* Note that the Eve Light Strip doesn't actually provide history entries;
|
|
30
|
-
* the _History_ service is used only to provide a reference time for
|
|
31
|
-
* last `LastActivation`.
|
|
32
|
-
* @extends ServiceDelegate.History
|
|
33
|
-
* @memberof ServiceDelegate.History
|
|
34
|
-
*/
|
|
35
|
-
class Light extends History {
|
|
36
|
-
/** Create a new instance of a Raspberry Pi _History_ service delegate.
|
|
37
|
-
* @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
|
|
38
|
-
* corresponding HomeKit accessory.
|
|
39
|
-
* @param {!object} params - The parameters for the
|
|
40
|
-
* _History_ HomeKit service.
|
|
41
|
-
* @param {!CharacteristicDelegate} params.onDelegate - A reference to the
|
|
42
|
-
* delegate of the associated `Characteristics.hap.On`
|
|
43
|
-
* characteristic.
|
|
44
|
-
* @param {!CharacteristicDelegate} params.lastActivationDelegate - A
|
|
45
|
-
* reference to the delegate of the associated
|
|
46
|
-
* `Characteristics.eve.LastActivation` characteristic.
|
|
47
|
-
*/
|
|
48
|
-
constructor (accessoryDelegate, params) {
|
|
49
|
-
params.memorySize = 0
|
|
50
|
-
super(accessoryDelegate, params)
|
|
51
|
-
if (!(params.onDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
52
|
-
throw new TypeError('params.onDelegate: not a CharacteristicDelegate')
|
|
53
|
-
}
|
|
54
|
-
if (!(params.lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
55
|
-
throw new TypeError('params.lastActivationDelegate: not a CharacteristicDelegate')
|
|
56
|
-
}
|
|
57
|
-
this.entry = { }
|
|
58
|
-
params.onDelegate.on('didSet', (value) => {
|
|
59
|
-
const now = History.now()
|
|
60
|
-
if (params.lastActivationDelegate != null) {
|
|
61
|
-
params.lastActivationDelegate.value = this.lastActivationValue(now)
|
|
62
|
-
}
|
|
63
|
-
this.addEntry({ time: now })
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get fingerPrint () { return '00' }
|
|
68
|
-
|
|
69
|
-
entryToBuffer (entry) {
|
|
70
|
-
return Buffer.alloc(0)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
module.exports = Light
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// homebridge-lib/lib/ServiceDelegate/History/On.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 a Raspberry Pi _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.On` characteristic.
|
|
27
|
-
* @extends ServiceDelegate.History
|
|
28
|
-
* @memberof ServiceDelegate.History
|
|
29
|
-
*/
|
|
30
|
-
class On extends History {
|
|
31
|
-
/** Create a new instance of a Raspberry Pi _History_ service delegate.
|
|
32
|
-
* @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
|
|
33
|
-
* corresponding HomeKit accessory.
|
|
34
|
-
* @param {!object} params - The parameters for the
|
|
35
|
-
* _History_ HomeKit service.
|
|
36
|
-
* @param {!CharacteristicDelegate} params.onDelegate - A reference to the
|
|
37
|
-
* delegate of the associated `Characteristics.hap.On`
|
|
38
|
-
* characteristic.
|
|
39
|
-
* @param {?CharacteristicDelegate} params.lastActivationDelegate - A
|
|
40
|
-
* reference to the delegate of the associated
|
|
41
|
-
* `Characteristics.eve.LastActivation` characteristic.
|
|
42
|
-
* @param {?CharacteristicDelegate} params.temperatureDelegate - A reference
|
|
43
|
-
* to the delegate of the associated `Characteristics.hap.CurrentTemperature`
|
|
44
|
-
* characteristic.
|
|
45
|
-
*/
|
|
46
|
-
constructor (accessoryDelegate, params) {
|
|
47
|
-
super(accessoryDelegate, params)
|
|
48
|
-
if (!(params.onDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
49
|
-
throw new TypeError('params.onDelegate: not a CharacteristicDelegate')
|
|
50
|
-
}
|
|
51
|
-
if (
|
|
52
|
-
params.lastActivationDelegate != null &&
|
|
53
|
-
!(params.lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)
|
|
54
|
-
) {
|
|
55
|
-
throw new TypeError('params.lastActivationDelegate: not a CharacteristicDelegate')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
this.entry = { o: params.onDelegate.value ? 1 : 0 }
|
|
59
|
-
params.onDelegate.on('didSet', (value) => {
|
|
60
|
-
const now = History.now()
|
|
61
|
-
if (params.lastActivationDelegate != null) {
|
|
62
|
-
params.lastActivationDelegate.value = this.lastActivationValue(now)
|
|
63
|
-
}
|
|
64
|
-
this.entry.o = value ? 1 : 0
|
|
65
|
-
this.addEntry({ time: now, o: this.entry.o })
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
if (params.temperatureDelegate != null) {
|
|
69
|
-
if (!(params.temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
70
|
-
throw new TypeError('params.temperatureDelegate: not a CharacteristicDelegate')
|
|
71
|
-
}
|
|
72
|
-
this.entry.t = params.temperatureDelegate.value * 100
|
|
73
|
-
params.temperatureDelegate.on('didSet', (value) => {
|
|
74
|
-
this.entry.t = value * 100
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get fingerPrint () { return '01 0E01 0102' }
|
|
80
|
-
|
|
81
|
-
entryToBuffer (entry) {
|
|
82
|
-
const buffer = Buffer.alloc(16)
|
|
83
|
-
let mask = 0
|
|
84
|
-
let o = 1
|
|
85
|
-
if (entry.o != null) {
|
|
86
|
-
mask |= 0x01
|
|
87
|
-
buffer.writeUInt8(entry.o, o); o += 1
|
|
88
|
-
}
|
|
89
|
-
if (entry.t != null) {
|
|
90
|
-
mask |= 0x02
|
|
91
|
-
buffer.writeUInt16LE(entry.t, o); o += 2
|
|
92
|
-
}
|
|
93
|
-
buffer.writeUInt8(mask, 0)
|
|
94
|
-
return buffer.slice(0, o)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
module.exports = On
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
// homebridge-lib/lib/ServiceDelegate/History/Power.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 Energy _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 is for sensors that don't report life-time consumption. The
|
|
27
|
-
* history from the value of the associated
|
|
28
|
-
* `Characteristics.eve.CurrentConsumption` over time. It updates the value of
|
|
29
|
-
* the associated `Characteristics.eve.TotalConsumption` characteristic.
|
|
30
|
-
* @extends ServiceDelegate.History
|
|
31
|
-
* @memberof ServiceDelegate.History
|
|
32
|
-
*/
|
|
33
|
-
class Power extends History {
|
|
34
|
-
/** Create a new instance of an Eve Energy _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.powerDelegate - A reference to the
|
|
40
|
-
* delegate of the associated `Characteristics.eve.CurrentConsumption`
|
|
41
|
-
* characteristic.
|
|
42
|
-
* @param {!CharacteristicDelegate} params.consumptionDelegate - A reference
|
|
43
|
-
* to the delegate of the associated `Characteristics.eve.TotalConsumption`
|
|
44
|
-
* characteristic.
|
|
45
|
-
* @param {?CharacteristicDelegate} params.onDelegate - A reference to the
|
|
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.
|
|
50
|
-
*/
|
|
51
|
-
constructor (accessoryDelegate, params) {
|
|
52
|
-
super(accessoryDelegate, params)
|
|
53
|
-
if (!(params.powerDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
54
|
-
throw new TypeError('params.powerDelegate: not a CharacteristicDelegate')
|
|
55
|
-
}
|
|
56
|
-
if (!(params.consumptionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
57
|
-
throw new TypeError('params.consumptionDelegate: not a CharacteristicDelegate')
|
|
58
|
-
}
|
|
59
|
-
if (
|
|
60
|
-
params.onDelegate != null &&
|
|
61
|
-
!(params.onDelegate instanceof homebridgeLib.CharacteristicDelegate)
|
|
62
|
-
) {
|
|
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')
|
|
70
|
-
}
|
|
71
|
-
this._powerDelegate = params.powerDelegate
|
|
72
|
-
this._consumptionDelegate = params.consumptionDelegate
|
|
73
|
-
|
|
74
|
-
this.entry = { p: 0 }
|
|
75
|
-
this._runningConsumption = 0 // 10-min-interval running value
|
|
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
|
|
79
|
-
params.powerDelegate.on('didSet', (value) => {
|
|
80
|
-
const now = History.now
|
|
81
|
-
if (this._time != null) {
|
|
82
|
-
const delta = this._power * (now - this._time) // Ws
|
|
83
|
-
this._runningConsumption += Math.round(delta / 60.0) // 0.1W * 10 min
|
|
84
|
-
this._totalConsumption += delta / 36000.0 // 0.01 kWh
|
|
85
|
-
}
|
|
86
|
-
this._power = value
|
|
87
|
-
this._time = now
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
this.addCharacteristicDelegate({
|
|
91
|
-
key: 'resetTotal',
|
|
92
|
-
Characteristic: this.Characteristics.eve.ResetTotal,
|
|
93
|
-
value: params.resetTotal
|
|
94
|
-
}).on('didSet', (value) => {
|
|
95
|
-
this._runningConsumption = 0
|
|
96
|
-
this._totalConsumption = 0
|
|
97
|
-
this._consumptionDelegate.value = this._totalConsumption
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
if (params.onDelegate != null) {
|
|
101
|
-
this.entry.o = params.onDelegate.value ? 1 : 0
|
|
102
|
-
params.onDelegate.on('didSet', (value) => {
|
|
103
|
-
const now = History.now
|
|
104
|
-
if (params.lastActivationDelegate != null) {
|
|
105
|
-
params.lastActivationDelegate.value = this.lastActivationValue(now)
|
|
106
|
-
}
|
|
107
|
-
this.entry.o = value ? 1 : 0
|
|
108
|
-
super.addEntry({ time: now, o: this.entry.o })
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
addEntry (entry) {
|
|
114
|
-
// Sensor delivers currentConsumption, compute totalConsumption
|
|
115
|
-
if (this._time != null) {
|
|
116
|
-
const delta = this._power * (entry.time - this._time) // Ws
|
|
117
|
-
this._runningConsumption += delta / 60.0 // 0.1 W * 10 min
|
|
118
|
-
this._totalConsumption += delta / 36000.0 // 0.01 kWh
|
|
119
|
-
this._consumptionDelegate.value = Math.round(this._totalConsumption) / 100.0 // kWh
|
|
120
|
-
entry.p = Math.round(this._runningConsumption) // 0.1 W * 10 min
|
|
121
|
-
}
|
|
122
|
-
super.addEntry(entry)
|
|
123
|
-
this._power = this._powerDelegate.value
|
|
124
|
-
this._time = entry.time
|
|
125
|
-
this._runningConsumption = 0
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
get fingerPrint () { return '02 0702 0E01' }
|
|
129
|
-
|
|
130
|
-
entryToBuffer (entry) {
|
|
131
|
-
const buffer = Buffer.alloc(16)
|
|
132
|
-
let mask = 0
|
|
133
|
-
let o = 1
|
|
134
|
-
if (entry.p != null) {
|
|
135
|
-
mask |= 0x01
|
|
136
|
-
buffer.writeUInt16LE(entry.p, o); o += 2
|
|
137
|
-
}
|
|
138
|
-
if (entry.o != null) {
|
|
139
|
-
mask |= 0x02
|
|
140
|
-
buffer.writeUInt8(entry.o, o); o += 1
|
|
141
|
-
}
|
|
142
|
-
buffer.writeUInt8(mask, 0)
|
|
143
|
-
return buffer.slice(0, o)
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
module.exports = Power
|
|
@@ -1,215 +0,0 @@
|
|
|
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
|