Skip to content

Commit 85b9e86

Browse files
committed
fix eve characteristics for hb 2
1 parent bc01462 commit 85b9e86

File tree

2 files changed

+114
-97
lines changed

2 files changed

+114
-97
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to homebridge-ewelink will be documented in this file.
77
### Notable Changes
88

99
- fix custom plugin config modal styles in ui 5
10+
- fix eve characteristics for hb 2
1011

1112
### Other Changes
1213

lib/utils/eve-chars.js

Lines changed: 113 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { inherits } from 'node:util'
2-
31
export default class {
42
constructor(api) {
5-
this.hapServ = api.hap.Service
6-
this.hapChar = api.hap.Characteristic
73
this.uuids = {
84
currentConsumption: 'E863F10D-079E-48FF-8F27-9C2605A29F52',
95
totalConsumption: 'E863F10C-079E-48FF-8F27-9C2605A29F52',
@@ -15,108 +11,128 @@ export default class {
1511
closedDuration: 'E863F119-079E-48FF-8F27-9C2605A29F52',
1612
timesOpened: 'E863F129-079E-48FF-8F27-9C2605A29F52',
1713
}
18-
const self = this
19-
this.CurrentConsumption = function CurrentConsumption() {
20-
self.hapChar.call(this, 'Current Consumption', self.uuids.currentConsumption)
21-
this.setProps({
22-
format: api.hap.Formats.UINT16,
23-
unit: 'W',
24-
maxValue: 100000,
25-
minValue: 0,
26-
minStep: 1,
27-
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
28-
})
29-
this.value = this.getDefaultValue()
14+
15+
const uuids = this.uuids
16+
17+
this.CurrentConsumption = class extends api.hap.Characteristic {
18+
constructor() {
19+
super('Current Consumption', uuids.currentConsumption)
20+
this.setProps({
21+
format: api.hap.Formats.UINT16,
22+
unit: 'W',
23+
maxValue: 100000,
24+
minValue: 0,
25+
minStep: 1,
26+
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
27+
})
28+
this.value = this.getDefaultValue()
29+
}
3030
}
31-
this.TotalConsumption = function TotalConsumption() {
32-
self.hapChar.call(this, 'Total Consumption', self.uuids.totalConsumption)
33-
this.setProps({
34-
format: api.hap.Formats.FLOAT,
35-
unit: 'kWh',
36-
maxValue: 100000000000,
37-
minValue: 0,
38-
minStep: 0.01,
39-
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
40-
})
41-
this.value = this.getDefaultValue()
31+
32+
this.TotalConsumption = class extends api.hap.Characteristic {
33+
constructor() {
34+
super('Total Consumption', uuids.totalConsumption)
35+
this.setProps({
36+
format: api.hap.Formats.FLOAT,
37+
unit: 'kWh',
38+
maxValue: 100000000000,
39+
minValue: 0,
40+
minStep: 0.01,
41+
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
42+
})
43+
this.value = this.getDefaultValue()
44+
}
4245
}
43-
this.Voltage = function Voltage() {
44-
self.hapChar.call(this, 'Voltage', self.uuids.voltage)
45-
this.setProps({
46-
format: api.hap.Formats.FLOAT,
47-
unit: 'V',
48-
maxValue: 100000000000,
49-
minValue: 0,
50-
minStep: 1,
51-
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
52-
})
53-
this.value = this.getDefaultValue()
46+
47+
this.Voltage = class extends api.hap.Characteristic {
48+
constructor() {
49+
super('Voltage', uuids.voltage)
50+
this.setProps({
51+
format: api.hap.Formats.FLOAT,
52+
unit: 'V',
53+
maxValue: 100000000000,
54+
minValue: 0,
55+
minStep: 1,
56+
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
57+
})
58+
this.value = this.getDefaultValue()
59+
}
5460
}
55-
this.ElectricCurrent = function ElectricCurrent() {
56-
self.hapChar.call(this, 'Electric Current', self.uuids.electricCurrent)
57-
this.setProps({
58-
format: api.hap.Formats.FLOAT,
59-
unit: 'A',
60-
maxValue: 100000000000,
61-
minValue: 0,
62-
minStep: 0.1,
63-
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
64-
})
65-
this.value = this.getDefaultValue()
61+
62+
this.ElectricCurrent = class extends api.hap.Characteristic {
63+
constructor() {
64+
super('Electric Current', uuids.electricCurrent)
65+
this.setProps({
66+
format: api.hap.Formats.FLOAT,
67+
unit: 'A',
68+
maxValue: 100000000000,
69+
minValue: 0,
70+
minStep: 0.1,
71+
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
72+
})
73+
this.value = this.getDefaultValue()
74+
}
6675
}
67-
this.ResetTotal = function ResetTotal() {
68-
self.hapChar.call(this, 'Reset Total', self.uuids.resetTotal)
69-
this.setProps({
70-
format: api.hap.Formats.UINT32,
71-
unit: api.hap.Units.seconds,
72-
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY, api.hap.Perms.PAIRED_WRITE],
73-
})
74-
this.value = this.getDefaultValue()
76+
77+
this.ResetTotal = class extends api.hap.Characteristic {
78+
constructor() {
79+
super('Reset Total', uuids.resetTotal)
80+
this.setProps({
81+
format: api.hap.Formats.UINT32,
82+
unit: api.hap.Units.seconds,
83+
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY, api.hap.Perms.PAIRED_WRITE],
84+
})
85+
this.value = this.getDefaultValue()
86+
}
7587
}
76-
this.LastActivation = function LastActivation() {
77-
self.hapChar.call(this, 'Last Activation', self.uuids.lastActivation)
78-
this.setProps({
79-
format: api.hap.Formats.UINT32,
80-
unit: api.hap.Units.SECONDS,
81-
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
82-
})
83-
this.value = this.getDefaultValue()
88+
89+
this.LastActivation = class extends api.hap.Characteristic {
90+
constructor() {
91+
super('Last Activation', uuids.lastActivation)
92+
this.setProps({
93+
format: api.hap.Formats.UINT32,
94+
unit: api.hap.Units.SECONDS,
95+
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
96+
})
97+
this.value = this.getDefaultValue()
98+
}
8499
}
85-
this.OpenDuration = function OpenDuration() {
86-
self.hapChar.call(this, 'Open Duration', self.uuids.openDuration)
87-
this.setProps({
88-
format: api.hap.Formats.UINT32,
89-
unit: api.hap.Units.SECONDS,
90-
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY, api.hap.Perms.PAIRED_WRITE],
91-
})
92-
this.value = this.getDefaultValue()
100+
101+
this.OpenDuration = class extends api.hap.Characteristic {
102+
constructor() {
103+
super('Open Duration', uuids.openDuration)
104+
this.setProps({
105+
format: api.hap.Formats.UINT32,
106+
unit: api.hap.Units.SECONDS,
107+
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY, api.hap.Perms.PAIRED_WRITE],
108+
})
109+
this.value = this.getDefaultValue()
110+
}
93111
}
94-
this.ClosedDuration = function ClosedDuration() {
95-
self.hapChar.call(this, 'Closed Duration', self.uuids.closedDuration)
96-
this.setProps({
97-
format: api.hap.Formats.UINT32,
98-
unit: api.hap.Units.SECONDS,
99-
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY, api.hap.Perms.PAIRED_WRITE],
100-
})
101-
this.value = this.getDefaultValue()
112+
113+
this.ClosedDuration = class extends api.hap.Characteristic {
114+
constructor() {
115+
super('Closed Duration', uuids.closedDuration)
116+
this.setProps({
117+
format: api.hap.Formats.UINT32,
118+
unit: api.hap.Units.SECONDS,
119+
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY, api.hap.Perms.PAIRED_WRITE],
120+
})
121+
this.value = this.getDefaultValue()
122+
}
102123
}
103-
this.TimesOpened = function TimesOpened() {
104-
self.hapChar.call(this, 'Times Opened', self.uuids.timesOpened)
105-
this.setProps({
106-
format: api.hap.Formats.UINT32,
107-
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
108-
})
109-
this.value = this.getDefaultValue()
124+
125+
this.TimesOpened = class extends api.hap.Characteristic {
126+
constructor() {
127+
super('Times Opened', uuids.timesOpened)
128+
this.setProps({
129+
format: api.hap.Formats.UINT32,
130+
perms: [api.hap.Perms.PAIRED_READ, api.hap.Perms.NOTIFY],
131+
})
132+
this.value = this.getDefaultValue()
133+
}
110134
}
111-
inherits(this.CurrentConsumption, this.hapChar)
112-
inherits(this.TotalConsumption, this.hapChar)
113-
inherits(this.Voltage, this.hapChar)
114-
inherits(this.ElectricCurrent, this.hapChar)
115-
inherits(this.LastActivation, this.hapChar)
116-
inherits(this.ResetTotal, this.hapChar)
117-
inherits(this.OpenDuration, this.hapChar)
118-
inherits(this.ClosedDuration, this.hapChar)
119-
inherits(this.TimesOpened, this.hapChar)
135+
120136
this.CurrentConsumption.UUID = this.uuids.currentConsumption
121137
this.TotalConsumption.UUID = this.uuids.totalConsumption
122138
this.Voltage.UUID = this.uuids.voltage

0 commit comments

Comments
 (0)