@homebridge-plugins/homebridge-ewelink 12.3.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.
- package/CHANGELOG.md +1363 -0
- package/LICENSE +21 -0
- package/README.md +68 -0
- package/config.schema.json +1757 -0
- package/eslint.config.js +15 -0
- package/lib/connection/api.js +508 -0
- package/lib/connection/http.js +304 -0
- package/lib/connection/lan.js +318 -0
- package/lib/connection/ws.js +414 -0
- package/lib/device/curtain.js +324 -0
- package/lib/device/diffuser.js +473 -0
- package/lib/device/fan.js +349 -0
- package/lib/device/group.js +106 -0
- package/lib/device/humidifier.js +199 -0
- package/lib/device/index.js +61 -0
- package/lib/device/light-cct.js +333 -0
- package/lib/device/light-dimmer.js +257 -0
- package/lib/device/light-rgb-cct.js +809 -0
- package/lib/device/light-rgb.js +272 -0
- package/lib/device/motor.js +363 -0
- package/lib/device/outlet-multi.js +417 -0
- package/lib/device/outlet-single-inched.js +409 -0
- package/lib/device/outlet-single.js +384 -0
- package/lib/device/panel.js +382 -0
- package/lib/device/rf-bridge.js +321 -0
- package/lib/device/rf-button.js +125 -0
- package/lib/device/rf-sensor.js +173 -0
- package/lib/device/sensor-ambient.js +311 -0
- package/lib/device/sensor-contact.js +140 -0
- package/lib/device/sensor-temp-humi.js +182 -0
- package/lib/device/simulation/blind.js +253 -0
- package/lib/device/simulation/cooler.js +312 -0
- package/lib/device/simulation/door.js +253 -0
- package/lib/device/simulation/doorbell.js +190 -0
- package/lib/device/simulation/garage-eachen.js +235 -0
- package/lib/device/simulation/garage-four.js +176 -0
- package/lib/device/simulation/garage-od-switch.js +36 -0
- package/lib/device/simulation/garage-one.js +395 -0
- package/lib/device/simulation/garage-two.js +394 -0
- package/lib/device/simulation/gate-one.js +327 -0
- package/lib/device/simulation/heater.js +389 -0
- package/lib/device/simulation/index.js +75 -0
- package/lib/device/simulation/light-fan.js +258 -0
- package/lib/device/simulation/lock-eachen.js +163 -0
- package/lib/device/simulation/lock-one.js +366 -0
- package/lib/device/simulation/p-button.js +223 -0
- package/lib/device/simulation/purifier.js +289 -0
- package/lib/device/simulation/rf-blind.js +192 -0
- package/lib/device/simulation/rf-door.js +180 -0
- package/lib/device/simulation/rf-window.js +180 -0
- package/lib/device/simulation/sensor-hidden.js +105 -0
- package/lib/device/simulation/sensor-leak.js +123 -0
- package/lib/device/simulation/sensor-visible.js +231 -0
- package/lib/device/simulation/sensor.js +300 -0
- package/lib/device/simulation/switch-valve.js +351 -0
- package/lib/device/simulation/tap-one.js +283 -0
- package/lib/device/simulation/tap-two.js +266 -0
- package/lib/device/simulation/th-cooler.js +443 -0
- package/lib/device/simulation/th-dehumidifier.js +424 -0
- package/lib/device/simulation/th-heater.js +449 -0
- package/lib/device/simulation/th-humidifier.js +424 -0
- package/lib/device/simulation/th-thermostat.js +611 -0
- package/lib/device/simulation/tv.js +252 -0
- package/lib/device/simulation/valve-four.js +232 -0
- package/lib/device/simulation/valve-one.js +345 -0
- package/lib/device/simulation/valve-two.js +340 -0
- package/lib/device/simulation/window.js +253 -0
- package/lib/device/switch-man.js +106 -0
- package/lib/device/switch-mate.js +82 -0
- package/lib/device/switch-multi.js +411 -0
- package/lib/device/switch-single-inched.js +332 -0
- package/lib/device/switch-single.js +307 -0
- package/lib/device/template.js +43 -0
- package/lib/device/thermostat.js +286 -0
- package/lib/device/zigbee/index.js +27 -0
- package/lib/device/zigbee/light-cct.js +263 -0
- package/lib/device/zigbee/light-dimmer.js +148 -0
- package/lib/device/zigbee/light-rgb-cct.js +400 -0
- package/lib/device/zigbee/motor.js +301 -0
- package/lib/device/zigbee/sensor-ambient.js +177 -0
- package/lib/device/zigbee/sensor-contact.js +137 -0
- package/lib/device/zigbee/sensor-leak.js +119 -0
- package/lib/device/zigbee/sensor-motion.js +119 -0
- package/lib/device/zigbee/sensor-occupancy.js +119 -0
- package/lib/device/zigbee/sensor-smoke.js +96 -0
- package/lib/device/zigbee/switch-stateless.js +104 -0
- package/lib/device/zigbee/thermostat.js +323 -0
- package/lib/fakegato/LICENSE +21 -0
- package/lib/fakegato/fakegato-history.js +813 -0
- package/lib/fakegato/fakegato-storage.js +108 -0
- package/lib/fakegato/fakegato-timer.js +125 -0
- package/lib/fakegato/uuid.js +27 -0
- package/lib/homebridge-ui/public/index.html +365 -0
- package/lib/homebridge-ui/server.js +46 -0
- package/lib/index.js +7 -0
- package/lib/node-dns-sd/LICENSE +21 -0
- package/lib/node-dns-sd/README.md +613 -0
- package/lib/node-dns-sd/lib/dns-sd-classes.json +6 -0
- package/lib/node-dns-sd/lib/dns-sd-composer.js +83 -0
- package/lib/node-dns-sd/lib/dns-sd-parser.js +344 -0
- package/lib/node-dns-sd/lib/dns-sd-types.json +52 -0
- package/lib/node-dns-sd/lib/dns-sd.js +580 -0
- package/lib/platform.js +2156 -0
- package/lib/utils/colour.js +552 -0
- package/lib/utils/constants.js +589 -0
- package/lib/utils/custom-chars.js +33 -0
- package/lib/utils/eve-chars.js +130 -0
- package/lib/utils/functions.js +42 -0
- package/lib/utils/lang-en.js +160 -0
- package/lib/utils/lang-fr.js +163 -0
- package/lib/utils/lang-th.js +160 -0
- package/lib/utils/lang.js +5 -0
- package/package.json +75 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import platformConsts from '../utils/constants.js'
|
|
2
|
+
import { hasProperty } from '../utils/functions.js'
|
|
3
|
+
|
|
4
|
+
export default class {
|
|
5
|
+
constructor(platform, accessory) {
|
|
6
|
+
// Set up variables from the platform
|
|
7
|
+
this.cusChar = platform.cusChar
|
|
8
|
+
this.eveChar = platform.eveChar
|
|
9
|
+
this.hapChar = platform.api.hap.Characteristic
|
|
10
|
+
this.hapErr = platform.api.hap.HapStatusError
|
|
11
|
+
this.hapServ = platform.api.hap.Service
|
|
12
|
+
this.lang = platform.lang
|
|
13
|
+
this.log = platform.log
|
|
14
|
+
this.platform = platform
|
|
15
|
+
|
|
16
|
+
// Set up variables from the accessory
|
|
17
|
+
this.name = accessory.displayName
|
|
18
|
+
this.accessory = accessory
|
|
19
|
+
|
|
20
|
+
// Initially set the online flag as true (to be then updated as false if necessary)
|
|
21
|
+
this.isOnline = true
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
UIID 1/6/14/24/27/112/1009/1256/7004: single switch, no power readings
|
|
25
|
+
UIID 5: single switch, with wattage readings
|
|
26
|
+
UIID 32: single switch, with wattage, voltage and amp readings
|
|
27
|
+
UIID 77/78/81/107/112/138/160: single switch but firmware uses multiple channels (only need CH0)
|
|
28
|
+
UIID 182: single switch but multiple channels with wattage, voltage and amp readings
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
// Set up custom variables for this device type
|
|
32
|
+
const deviceConf = platform.deviceConf[accessory.context.eweDeviceId] || {}
|
|
33
|
+
this.inUsePowerThreshold = deviceConf.inUsePowerThreshold || platformConsts.defaultValues.inUsePowerThreshold
|
|
34
|
+
|
|
35
|
+
// Set the correct logging variables for this accessory
|
|
36
|
+
switch (deviceConf.overrideLogging) {
|
|
37
|
+
case 'standard':
|
|
38
|
+
this.enableLogging = true
|
|
39
|
+
this.enableDebugLogging = false
|
|
40
|
+
break
|
|
41
|
+
case 'debug':
|
|
42
|
+
this.enableLogging = true
|
|
43
|
+
this.enableDebugLogging = true
|
|
44
|
+
break
|
|
45
|
+
case 'disable':
|
|
46
|
+
this.enableLogging = false
|
|
47
|
+
this.enableDebugLogging = false
|
|
48
|
+
break
|
|
49
|
+
default:
|
|
50
|
+
this.enableLogging = !platform.config.disableDeviceLogging
|
|
51
|
+
this.enableDebugLogging = platform.config.debug
|
|
52
|
+
break
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// If the accessory has a switch service then remove it
|
|
56
|
+
if (this.accessory.getService(this.hapServ.Switch)) {
|
|
57
|
+
this.accessory.removeService(this.accessory.getService(this.hapServ.Switch))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Add the outlet service if it doesn't already exist
|
|
61
|
+
this.service = this.accessory.getService(this.hapServ.Outlet)
|
|
62
|
+
|| this.accessory.addService(this.hapServ.Outlet)
|
|
63
|
+
|
|
64
|
+
switch (this.accessory.context.eweUIID) {
|
|
65
|
+
case 5:
|
|
66
|
+
// Add Eve power characteristics
|
|
67
|
+
this.powerReadings = true
|
|
68
|
+
if (!this.service.testCharacteristic(this.hapChar.OutletInUse)) {
|
|
69
|
+
this.service.addCharacteristic(this.hapChar.OutletInUse)
|
|
70
|
+
}
|
|
71
|
+
if (!this.service.testCharacteristic(this.eveChar.CurrentConsumption)) {
|
|
72
|
+
this.service.addCharacteristic(this.eveChar.CurrentConsumption)
|
|
73
|
+
}
|
|
74
|
+
if (!this.service.testCharacteristic(this.eveChar.TotalConsumption)) {
|
|
75
|
+
this.service.addCharacteristic(this.eveChar.TotalConsumption)
|
|
76
|
+
}
|
|
77
|
+
if (!this.service.testCharacteristic(this.eveChar.ResetTotal)) {
|
|
78
|
+
this.service.addCharacteristic(this.eveChar.ResetTotal)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Remove unused Eve characteristics
|
|
82
|
+
if (this.service.testCharacteristic(this.eveChar.ElectricCurrent)) {
|
|
83
|
+
this.service.removeCharacteristic(
|
|
84
|
+
this.service.getCharacteristic(this.eveChar.ElectricCurrent),
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
if (this.service.testCharacteristic(this.eveChar.Voltage)) {
|
|
88
|
+
this.service.removeCharacteristic(this.service.getCharacteristic(this.eveChar.Voltage))
|
|
89
|
+
}
|
|
90
|
+
break
|
|
91
|
+
case 32:
|
|
92
|
+
case 182:
|
|
93
|
+
case 190:
|
|
94
|
+
// Add Eve power characteristics
|
|
95
|
+
this.powerReadings = true
|
|
96
|
+
if (!this.service.testCharacteristic(this.hapChar.OutletInUse)) {
|
|
97
|
+
this.service.addCharacteristic(this.hapChar.OutletInUse)
|
|
98
|
+
}
|
|
99
|
+
if (!this.service.testCharacteristic(this.eveChar.CurrentConsumption)) {
|
|
100
|
+
this.service.addCharacteristic(this.eveChar.CurrentConsumption)
|
|
101
|
+
}
|
|
102
|
+
if (!this.service.testCharacteristic(this.eveChar.ElectricCurrent)) {
|
|
103
|
+
this.service.addCharacteristic(this.eveChar.ElectricCurrent)
|
|
104
|
+
}
|
|
105
|
+
if (!this.service.testCharacteristic(this.eveChar.Voltage)) {
|
|
106
|
+
this.service.addCharacteristic(this.eveChar.Voltage)
|
|
107
|
+
}
|
|
108
|
+
if (!this.service.testCharacteristic(this.eveChar.TotalConsumption)) {
|
|
109
|
+
this.service.addCharacteristic(this.eveChar.TotalConsumption)
|
|
110
|
+
}
|
|
111
|
+
if (!this.service.testCharacteristic(this.eveChar.ResetTotal)) {
|
|
112
|
+
this.service.addCharacteristic(this.eveChar.ResetTotal)
|
|
113
|
+
}
|
|
114
|
+
break
|
|
115
|
+
default:
|
|
116
|
+
// Remove unused Eve characteristics
|
|
117
|
+
if (this.service.testCharacteristic(this.hapChar.OutletInUse)) {
|
|
118
|
+
this.service.removeCharacteristic(
|
|
119
|
+
this.service.getCharacteristic(this.eveChar.OutletInUse),
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
if (this.service.testCharacteristic(this.eveChar.CurrentConsumption)) {
|
|
123
|
+
this.service.removeCharacteristic(
|
|
124
|
+
this.service.getCharacteristic(this.eveChar.CurrentConsumption),
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
if (this.service.testCharacteristic(this.eveChar.ElectricCurrent)) {
|
|
128
|
+
this.service.removeCharacteristic(
|
|
129
|
+
this.service.getCharacteristic(this.eveChar.ElectricCurrent),
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
if (this.service.testCharacteristic(this.eveChar.Voltage)) {
|
|
133
|
+
this.service.removeCharacteristic(this.service.getCharacteristic(this.eveChar.Voltage))
|
|
134
|
+
}
|
|
135
|
+
if (this.service.testCharacteristic(this.eveChar.TotalConsumption)) {
|
|
136
|
+
this.service.removeCharacteristic(
|
|
137
|
+
this.service.getCharacteristic(this.eveChar.TotalConsumption),
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
if (this.service.testCharacteristic(this.eveChar.ResetTotal)) {
|
|
141
|
+
this.service.removeCharacteristic(this.service.getCharacteristic(this.eveChar.ResetTotal))
|
|
142
|
+
}
|
|
143
|
+
break
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Set a flag for devices with hardware that use multi-channel format
|
|
147
|
+
if (
|
|
148
|
+
platformConsts.devices.switchSCM.includes(this.accessory.context.eweUIID)
|
|
149
|
+
|| platformConsts.devices.switchSCMPower.includes(this.accessory.context.eweUIID)
|
|
150
|
+
) {
|
|
151
|
+
this.isSCM = true
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Add the set handler to the outlet on/off characteristic
|
|
155
|
+
this.service
|
|
156
|
+
.getCharacteristic(this.hapChar.On)
|
|
157
|
+
.onSet(async value => this.internalStateUpdate(value))
|
|
158
|
+
this.cacheState = this.service.getCharacteristic(this.hapChar.On).value ? 'on' : 'off'
|
|
159
|
+
|
|
160
|
+
// Add a custom characteristic for inverting the switch
|
|
161
|
+
if (!this.service.testCharacteristic(this.cusChar.InvertSwitch)) {
|
|
162
|
+
this.service.addCharacteristic(this.cusChar.InvertSwitch)
|
|
163
|
+
}
|
|
164
|
+
this.service.updateCharacteristic(this.cusChar.InvertSwitch, this.cacheState === 'on')
|
|
165
|
+
|
|
166
|
+
// Add the set handler to invert the switch
|
|
167
|
+
this.service.getCharacteristic(this.cusChar.InvertSwitch).onSet((value) => {
|
|
168
|
+
this.service.updateCharacteristic(this.hapChar.On, value)
|
|
169
|
+
this.cacheState = value ? 'on' : 'off'
|
|
170
|
+
this.log('[%s] %s [%s].', this.name, this.lang.curState, this.cacheState)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
// Add the get handlers only if the user hasn't disabled the disableNoResponse setting
|
|
174
|
+
if (!platform.config.disableNoResponse) {
|
|
175
|
+
this.service.getCharacteristic(this.hapChar.On).onGet(() => {
|
|
176
|
+
if (!this.isOnline) {
|
|
177
|
+
throw new this.hapErr(-70402)
|
|
178
|
+
}
|
|
179
|
+
return this.service.getCharacteristic(this.hapChar.On).value
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Pass the accessory to Fakegato to set up with Eve
|
|
184
|
+
this.accessory.eveService = new platform.eveService('energy', this.accessory, {
|
|
185
|
+
log: () => {},
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
// Set up extra features for outlets that provide power readings
|
|
189
|
+
if (this.powerReadings) {
|
|
190
|
+
// TotalConsumption is calculated by the plugin with these context readings
|
|
191
|
+
if (!hasProperty(this.accessory.context, 'energyReadings')) {
|
|
192
|
+
this.accessory.context.energyReadings = []
|
|
193
|
+
}
|
|
194
|
+
if (!hasProperty(this.accessory.context, 'energyReadingTotal')) {
|
|
195
|
+
this.accessory.context.energyReadingTotal = 0
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Add the set handler to the outlet eve reset total energy characteristic
|
|
199
|
+
this.service.getCharacteristic(this.eveChar.ResetTotal).onSet(() => {
|
|
200
|
+
this.accessory.context.energyReadings = []
|
|
201
|
+
this.accessory.context.energyReadingTotal = 0
|
|
202
|
+
this.service.updateCharacteristic(this.eveChar.TotalConsumption, 0)
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
// Set up an interval for the plugin to calculate an approx total consumption
|
|
206
|
+
this.intervalPower = setInterval(() => {
|
|
207
|
+
// Every 30 seconds start with a zero reading
|
|
208
|
+
let total = 0
|
|
209
|
+
|
|
210
|
+
// Check we have had readings within the previous 30 seconds
|
|
211
|
+
if (this.accessory.context.energyReadings.length > 0) {
|
|
212
|
+
// Accumulate the total from the energy readings
|
|
213
|
+
this.accessory.context.energyReadings.forEach((x) => {
|
|
214
|
+
total += x
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
// Divide this by the number of entries to get an average W5m
|
|
218
|
+
total /= this.accessory.context.energyReadings.length
|
|
219
|
+
|
|
220
|
+
// Convert this to Wh then kWh
|
|
221
|
+
total /= 12
|
|
222
|
+
total /= 1000
|
|
223
|
+
|
|
224
|
+
// Accumulate the grand total that Eve reads as the total consumption
|
|
225
|
+
this.accessory.context.energyReadingTotal += total
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Reset the array for each 30 second readings
|
|
229
|
+
this.accessory.context.energyReadings = []
|
|
230
|
+
|
|
231
|
+
// Update Eve with the new grand total
|
|
232
|
+
this.service.updateCharacteristic(
|
|
233
|
+
this.eveChar.TotalConsumption,
|
|
234
|
+
this.accessory.context.energyReadingTotal,
|
|
235
|
+
)
|
|
236
|
+
}, 30000)
|
|
237
|
+
|
|
238
|
+
// Set up an interval to get eWeLink to send power updates
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
this.internalUIUpdate()
|
|
241
|
+
this.intervalPoll = setInterval(() => this.internalUIUpdate(), 120000)
|
|
242
|
+
}, 5000)
|
|
243
|
+
|
|
244
|
+
// Stop the intervals on Homebridge shutdown
|
|
245
|
+
platform.api.on('shutdown', () => {
|
|
246
|
+
clearInterval(this.intervalPoll)
|
|
247
|
+
clearInterval(this.intervalPower)
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Output the customised options to the log
|
|
252
|
+
const normalLogging = this.enableLogging ? 'standard' : 'disable'
|
|
253
|
+
const opts = JSON.stringify({
|
|
254
|
+
inUsePowerThreshold: this.inUsePowerThreshold,
|
|
255
|
+
isInched: true,
|
|
256
|
+
logging: this.enableDebugLogging ? 'debug' : normalLogging,
|
|
257
|
+
showAs: 'outlet',
|
|
258
|
+
})
|
|
259
|
+
this.log('[%s] %s %s.', this.name, this.lang.devInitOpts, opts)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async internalStateUpdate(value) {
|
|
263
|
+
try {
|
|
264
|
+
const newValue = this.cacheState === 'on' ? 'off' : 'on'
|
|
265
|
+
const params = {}
|
|
266
|
+
if (this.isSCM) {
|
|
267
|
+
params.switches = [{ switch: 'on', outlet: 0 }]
|
|
268
|
+
} else {
|
|
269
|
+
params.switch = 'on'
|
|
270
|
+
}
|
|
271
|
+
this.ignoreUpdates = true
|
|
272
|
+
setTimeout(() => {
|
|
273
|
+
this.ignoreUpdates = false
|
|
274
|
+
}, 1500)
|
|
275
|
+
await this.platform.sendDeviceUpdate(this.accessory, params)
|
|
276
|
+
this.cacheState = newValue
|
|
277
|
+
this.service.updateCharacteristic(this.cusChar.InvertSwitch, value)
|
|
278
|
+
this.accessory.eveService.addEntry({ status: this.cacheState === 'on' ? 1 : 0 })
|
|
279
|
+
if (this.enableLogging) {
|
|
280
|
+
this.log('[%s] %s [%s].', this.name, this.lang.curState, this.cacheState)
|
|
281
|
+
}
|
|
282
|
+
} catch (err) {
|
|
283
|
+
this.platform.deviceUpdateError(this.accessory, err, true)
|
|
284
|
+
setTimeout(() => {
|
|
285
|
+
this.service.updateCharacteristic(this.hapChar.On, this.cacheState === 'on')
|
|
286
|
+
}, 2000)
|
|
287
|
+
throw new this.hapErr(-70402)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async internalUIUpdate() {
|
|
292
|
+
try {
|
|
293
|
+
// Skip polling if device isn't online
|
|
294
|
+
if (!this.isOnline) {
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Send the params to request the updates
|
|
299
|
+
await this.platform.sendDeviceUpdate(this.accessory, { uiActive: 120 })
|
|
300
|
+
} catch (err) {
|
|
301
|
+
// Suppress errors here
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async externalUpdate(params) {
|
|
306
|
+
try {
|
|
307
|
+
if (!this.isSCM && params.switch === 'on') {
|
|
308
|
+
if (!this.ignoreUpdates) {
|
|
309
|
+
this.ignoreUpdates = true
|
|
310
|
+
setTimeout(() => {
|
|
311
|
+
this.ignoreUpdates = false
|
|
312
|
+
}, 1500)
|
|
313
|
+
this.cacheState = this.cacheState === 'on' ? 'off' : 'on'
|
|
314
|
+
this.service.updateCharacteristic(this.hapChar.On, this.cacheState === 'on')
|
|
315
|
+
this.accessory.eveService.addEntry({ status: this.cacheState === 'on' ? 1 : 0 })
|
|
316
|
+
if (params.updateSource && this.enableLogging) {
|
|
317
|
+
this.log('[%s] %s [%s].', this.name, this.lang.curState, this.cacheState)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (this.isSCM && params.switches && params.switches[0].switch === 'on') {
|
|
322
|
+
if (!this.ignoreUpdates) {
|
|
323
|
+
this.ignoreUpdates = true
|
|
324
|
+
setTimeout(() => {
|
|
325
|
+
this.ignoreUpdates = false
|
|
326
|
+
}, 1500)
|
|
327
|
+
this.cacheState = this.cacheState === 'on' ? 'off' : 'on'
|
|
328
|
+
this.service.updateCharacteristic(this.hapChar.On, this.cacheState === 'on')
|
|
329
|
+
this.accessory.eveService.addEntry({ status: this.cacheState === 'on' ? 1 : 0 })
|
|
330
|
+
if (params.updateSource && this.enableLogging) {
|
|
331
|
+
this.log('[%s] %s [%s].', this.name, this.lang.curState, this.cacheState)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (!this.powerReadings) {
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
let logger = false
|
|
339
|
+
if (hasProperty(params, 'power')) {
|
|
340
|
+
const power = Number.parseFloat(params.power)
|
|
341
|
+
this.service.updateCharacteristic(
|
|
342
|
+
this.hapChar.OutletInUse,
|
|
343
|
+
this.cacheState === 'on' && power > this.inUsePowerThreshold,
|
|
344
|
+
)
|
|
345
|
+
this.service.updateCharacteristic(this.eveChar.CurrentConsumption, power)
|
|
346
|
+
this.accessory.eveService.addEntry({ power })
|
|
347
|
+
this.accessory.context.energyReadings.push(power)
|
|
348
|
+
logger = true
|
|
349
|
+
}
|
|
350
|
+
if (hasProperty(params, 'voltage')) {
|
|
351
|
+
this.service.updateCharacteristic(this.eveChar.Voltage, Number.parseFloat(params.voltage))
|
|
352
|
+
logger = true
|
|
353
|
+
}
|
|
354
|
+
if (hasProperty(params, 'current')) {
|
|
355
|
+
this.service.updateCharacteristic(this.eveChar.ElectricCurrent, Number.parseFloat(params.current))
|
|
356
|
+
logger = true
|
|
357
|
+
}
|
|
358
|
+
if (params.updateSource && logger && this.enableLogging) {
|
|
359
|
+
this.log(
|
|
360
|
+
'[%s] %s%s%s.',
|
|
361
|
+
this.name,
|
|
362
|
+
hasProperty(params, 'power')
|
|
363
|
+
? `${this.lang.curPower} [${params.power}W]`
|
|
364
|
+
: '',
|
|
365
|
+
hasProperty(params, 'voltage')
|
|
366
|
+
? ` ${this.lang.curVolt} [${params.voltage}V]`
|
|
367
|
+
: '',
|
|
368
|
+
hasProperty(params, 'current')
|
|
369
|
+
? ` ${this.lang.curCurr} [${params.current}A]`
|
|
370
|
+
: '',
|
|
371
|
+
)
|
|
372
|
+
}
|
|
373
|
+
} catch (err) {
|
|
374
|
+
this.platform.deviceUpdateError(this.accessory, err, false)
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
markStatus(isOnline) {
|
|
379
|
+
this.isOnline = isOnline
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async currentState() {
|
|
383
|
+
const toReturn = {}
|
|
384
|
+
toReturn.services = ['outlet']
|
|
385
|
+
toReturn.outlet = {
|
|
386
|
+
state: this.service.getCharacteristic(this.hapChar.On).value ? 'on' : 'off',
|
|
387
|
+
}
|
|
388
|
+
if (this.powerReadings) {
|
|
389
|
+
try {
|
|
390
|
+
toReturn.services.push('power')
|
|
391
|
+
toReturn.power = {
|
|
392
|
+
state: await this.platform.sendDeviceUpdate(this.accessory, { hundredDaysKwh: 'get' }),
|
|
393
|
+
voltage: this.service.testCharacteristic(this.eveChar.Voltage)
|
|
394
|
+
? this.service.getCharacteristic(this.eveChar.Voltage).value
|
|
395
|
+
: undefined,
|
|
396
|
+
power: this.service.testCharacteristic(this.eveChar.CurrentConsumption)
|
|
397
|
+
? this.service.getCharacteristic(this.eveChar.CurrentConsumption).value
|
|
398
|
+
: undefined,
|
|
399
|
+
current: this.service.testCharacteristic(this.eveChar.ElectricCurrent)
|
|
400
|
+
? this.service.getCharacteristic(this.eveChar.ElectricCurrent).value
|
|
401
|
+
: undefined,
|
|
402
|
+
}
|
|
403
|
+
} catch (err) {
|
|
404
|
+
// Suppress errors here
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return toReturn
|
|
408
|
+
}
|
|
409
|
+
}
|