@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.
Files changed (113) hide show
  1. package/CHANGELOG.md +1363 -0
  2. package/LICENSE +21 -0
  3. package/README.md +68 -0
  4. package/config.schema.json +1757 -0
  5. package/eslint.config.js +15 -0
  6. package/lib/connection/api.js +508 -0
  7. package/lib/connection/http.js +304 -0
  8. package/lib/connection/lan.js +318 -0
  9. package/lib/connection/ws.js +414 -0
  10. package/lib/device/curtain.js +324 -0
  11. package/lib/device/diffuser.js +473 -0
  12. package/lib/device/fan.js +349 -0
  13. package/lib/device/group.js +106 -0
  14. package/lib/device/humidifier.js +199 -0
  15. package/lib/device/index.js +61 -0
  16. package/lib/device/light-cct.js +333 -0
  17. package/lib/device/light-dimmer.js +257 -0
  18. package/lib/device/light-rgb-cct.js +809 -0
  19. package/lib/device/light-rgb.js +272 -0
  20. package/lib/device/motor.js +363 -0
  21. package/lib/device/outlet-multi.js +417 -0
  22. package/lib/device/outlet-single-inched.js +409 -0
  23. package/lib/device/outlet-single.js +384 -0
  24. package/lib/device/panel.js +382 -0
  25. package/lib/device/rf-bridge.js +321 -0
  26. package/lib/device/rf-button.js +125 -0
  27. package/lib/device/rf-sensor.js +173 -0
  28. package/lib/device/sensor-ambient.js +311 -0
  29. package/lib/device/sensor-contact.js +140 -0
  30. package/lib/device/sensor-temp-humi.js +182 -0
  31. package/lib/device/simulation/blind.js +253 -0
  32. package/lib/device/simulation/cooler.js +312 -0
  33. package/lib/device/simulation/door.js +253 -0
  34. package/lib/device/simulation/doorbell.js +190 -0
  35. package/lib/device/simulation/garage-eachen.js +235 -0
  36. package/lib/device/simulation/garage-four.js +176 -0
  37. package/lib/device/simulation/garage-od-switch.js +36 -0
  38. package/lib/device/simulation/garage-one.js +395 -0
  39. package/lib/device/simulation/garage-two.js +394 -0
  40. package/lib/device/simulation/gate-one.js +327 -0
  41. package/lib/device/simulation/heater.js +389 -0
  42. package/lib/device/simulation/index.js +75 -0
  43. package/lib/device/simulation/light-fan.js +258 -0
  44. package/lib/device/simulation/lock-eachen.js +163 -0
  45. package/lib/device/simulation/lock-one.js +366 -0
  46. package/lib/device/simulation/p-button.js +223 -0
  47. package/lib/device/simulation/purifier.js +289 -0
  48. package/lib/device/simulation/rf-blind.js +192 -0
  49. package/lib/device/simulation/rf-door.js +180 -0
  50. package/lib/device/simulation/rf-window.js +180 -0
  51. package/lib/device/simulation/sensor-hidden.js +105 -0
  52. package/lib/device/simulation/sensor-leak.js +123 -0
  53. package/lib/device/simulation/sensor-visible.js +231 -0
  54. package/lib/device/simulation/sensor.js +300 -0
  55. package/lib/device/simulation/switch-valve.js +351 -0
  56. package/lib/device/simulation/tap-one.js +283 -0
  57. package/lib/device/simulation/tap-two.js +266 -0
  58. package/lib/device/simulation/th-cooler.js +443 -0
  59. package/lib/device/simulation/th-dehumidifier.js +424 -0
  60. package/lib/device/simulation/th-heater.js +449 -0
  61. package/lib/device/simulation/th-humidifier.js +424 -0
  62. package/lib/device/simulation/th-thermostat.js +611 -0
  63. package/lib/device/simulation/tv.js +252 -0
  64. package/lib/device/simulation/valve-four.js +232 -0
  65. package/lib/device/simulation/valve-one.js +345 -0
  66. package/lib/device/simulation/valve-two.js +340 -0
  67. package/lib/device/simulation/window.js +253 -0
  68. package/lib/device/switch-man.js +106 -0
  69. package/lib/device/switch-mate.js +82 -0
  70. package/lib/device/switch-multi.js +411 -0
  71. package/lib/device/switch-single-inched.js +332 -0
  72. package/lib/device/switch-single.js +307 -0
  73. package/lib/device/template.js +43 -0
  74. package/lib/device/thermostat.js +286 -0
  75. package/lib/device/zigbee/index.js +27 -0
  76. package/lib/device/zigbee/light-cct.js +263 -0
  77. package/lib/device/zigbee/light-dimmer.js +148 -0
  78. package/lib/device/zigbee/light-rgb-cct.js +400 -0
  79. package/lib/device/zigbee/motor.js +301 -0
  80. package/lib/device/zigbee/sensor-ambient.js +177 -0
  81. package/lib/device/zigbee/sensor-contact.js +137 -0
  82. package/lib/device/zigbee/sensor-leak.js +119 -0
  83. package/lib/device/zigbee/sensor-motion.js +119 -0
  84. package/lib/device/zigbee/sensor-occupancy.js +119 -0
  85. package/lib/device/zigbee/sensor-smoke.js +96 -0
  86. package/lib/device/zigbee/switch-stateless.js +104 -0
  87. package/lib/device/zigbee/thermostat.js +323 -0
  88. package/lib/fakegato/LICENSE +21 -0
  89. package/lib/fakegato/fakegato-history.js +813 -0
  90. package/lib/fakegato/fakegato-storage.js +108 -0
  91. package/lib/fakegato/fakegato-timer.js +125 -0
  92. package/lib/fakegato/uuid.js +27 -0
  93. package/lib/homebridge-ui/public/index.html +365 -0
  94. package/lib/homebridge-ui/server.js +46 -0
  95. package/lib/index.js +7 -0
  96. package/lib/node-dns-sd/LICENSE +21 -0
  97. package/lib/node-dns-sd/README.md +613 -0
  98. package/lib/node-dns-sd/lib/dns-sd-classes.json +6 -0
  99. package/lib/node-dns-sd/lib/dns-sd-composer.js +83 -0
  100. package/lib/node-dns-sd/lib/dns-sd-parser.js +344 -0
  101. package/lib/node-dns-sd/lib/dns-sd-types.json +52 -0
  102. package/lib/node-dns-sd/lib/dns-sd.js +580 -0
  103. package/lib/platform.js +2156 -0
  104. package/lib/utils/colour.js +552 -0
  105. package/lib/utils/constants.js +589 -0
  106. package/lib/utils/custom-chars.js +33 -0
  107. package/lib/utils/eve-chars.js +130 -0
  108. package/lib/utils/functions.js +42 -0
  109. package/lib/utils/lang-en.js +160 -0
  110. package/lib/utils/lang-fr.js +163 -0
  111. package/lib/utils/lang-th.js +160 -0
  112. package/lib/utils/lang.js +5 -0
  113. package/package.json +75 -0
@@ -0,0 +1,283 @@
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.eveChar = platform.eveChar
8
+ this.hapChar = platform.api.hap.Characteristic
9
+ this.hapErr = platform.api.hap.HapStatusError
10
+ this.hapServ = platform.api.hap.Service
11
+ this.lang = platform.lang
12
+ this.log = platform.log
13
+ this.platform = platform
14
+
15
+ // Set up variables from the accessory
16
+ this.name = accessory.displayName
17
+ this.accessory = accessory
18
+
19
+ // Initially set the online flag as true (to be then updated as false if necessary)
20
+ this.isOnline = true
21
+
22
+ // Set up custom variables for this device type
23
+ const deviceConf = platform.deviceConf[accessory.context.eweDeviceId] || {}
24
+
25
+ // Set the correct logging variables for this accessory
26
+ switch (deviceConf.overrideLogging) {
27
+ case 'standard':
28
+ this.enableLogging = true
29
+ this.enableDebugLogging = false
30
+ break
31
+ case 'debug':
32
+ this.enableLogging = true
33
+ this.enableDebugLogging = true
34
+ break
35
+ case 'disable':
36
+ this.enableLogging = false
37
+ this.enableDebugLogging = false
38
+ break
39
+ default:
40
+ this.enableLogging = !platform.config.disableDeviceLogging
41
+ this.enableDebugLogging = platform.config.debug
42
+ break
43
+ }
44
+
45
+ // If the accessory has a switch service then remove it
46
+ if (this.accessory.getService(this.hapServ.Switch)) {
47
+ this.accessory.removeService(this.accessory.getService(this.hapServ.Switch))
48
+ }
49
+
50
+ // Add the tap service if it doesn't already exist
51
+ this.service = this.accessory.getService(this.hapServ.Valve)
52
+ if (!this.service) {
53
+ this.service = this.accessory.addService(this.hapServ.Valve)
54
+ this.service.updateCharacteristic(this.hapChar.Active, 0)
55
+ this.service.updateCharacteristic(this.hapChar.InUse, 0)
56
+ this.service.updateCharacteristic(this.hapChar.ValveType, 3)
57
+ }
58
+
59
+ // Set up the device type and power readings if necessary
60
+ if (platformConsts.devices.switchSingle.includes(this.accessory.context.eweUIID)) {
61
+ this.setup = 'switchSingle'
62
+ } else if (platformConsts.devices.switchSinglePower.includes(this.accessory.context.eweUIID)) {
63
+ this.setup = 'switchSingle'
64
+
65
+ // Add Eve power characteristics
66
+ this.powerReadings = true
67
+ if (!this.service.testCharacteristic(this.eveChar.CurrentConsumption)) {
68
+ this.service.addCharacteristic(this.eveChar.CurrentConsumption)
69
+ }
70
+ if (this.accessory.context.eweUIID === 32) {
71
+ if (!this.service.testCharacteristic(this.eveChar.ElectricCurrent)) {
72
+ this.service.addCharacteristic(this.eveChar.ElectricCurrent)
73
+ }
74
+ if (!this.service.testCharacteristic(this.eveChar.Voltage)) {
75
+ this.service.addCharacteristic(this.eveChar.Voltage)
76
+ }
77
+ }
78
+ } else if (platformConsts.devices.switchMulti.includes(this.accessory.context.eweUIID)) {
79
+ this.setup = 'switchMulti'
80
+ if (platformConsts.devices.switchMultiPower.includes(this.accessory.context.eweUIID)) {
81
+ // Add Eve power characteristics
82
+ this.powerReadings = true
83
+ if (!this.service.testCharacteristic(this.eveChar.CurrentConsumption)) {
84
+ this.service.addCharacteristic(this.eveChar.CurrentConsumption)
85
+ }
86
+ if (!this.service.testCharacteristic(this.eveChar.ElectricCurrent)) {
87
+ this.service.addCharacteristic(this.eveChar.ElectricCurrent)
88
+ }
89
+ if (!this.service.testCharacteristic(this.eveChar.Voltage)) {
90
+ this.service.addCharacteristic(this.eveChar.Voltage)
91
+ }
92
+ this.isDualR3 = true
93
+ }
94
+ } else if (platformConsts.devices.switchSCM.includes(this.accessory.context.eweUIID)) {
95
+ this.setup = 'switchMulti'
96
+ } else if (platformConsts.devices.switchSCMPower.includes(this.accessory.context.eweUIID)) {
97
+ // Could do power here
98
+ this.setup = 'switchMulti'
99
+ }
100
+
101
+ // Add the set handler to the tap active characteristic
102
+ this.service.getCharacteristic(this.hapChar.Active).onSet(async (value) => {
103
+ await this.internalUpdate(value)
104
+ })
105
+
106
+ // Add the get handlers only if the user hasn't disabled the disableNoResponse setting
107
+ if (!platform.config.disableNoResponse) {
108
+ this.service.getCharacteristic(this.hapChar.Active).onGet(() => {
109
+ if (!this.isOnline) {
110
+ throw new this.hapErr(-70402)
111
+ }
112
+ return this.service.getCharacteristic(this.hapChar.Active).value
113
+ })
114
+ }
115
+
116
+ // Set up an interval to get eWeLink to send power updates
117
+ if (
118
+ this.powerReadings
119
+ && (!this.isDualR3 || (this.isDualR3 && platform.config.mode !== 'lan'))
120
+ ) {
121
+ setTimeout(() => {
122
+ this.internalUIUpdate()
123
+ this.intervalPoll = setInterval(() => this.internalUIUpdate(), 120000)
124
+ }, 5000)
125
+
126
+ // Stop the intervals on Homebridge shutdown
127
+ platform.api.on('shutdown', () => clearInterval(this.intervalPoll))
128
+ }
129
+
130
+ // Output the customised options to the log
131
+ const normalLogging = this.enableLogging ? 'standard' : 'disable'
132
+ const opts = JSON.stringify({
133
+ logging: this.enableDebugLogging ? 'debug' : normalLogging,
134
+ showAs: 'tap',
135
+ })
136
+ this.log('[%s] %s %s.', this.name, this.lang.devInitOpts, opts)
137
+ }
138
+
139
+ async internalUpdate(value) {
140
+ try {
141
+ const params = {}
142
+ switch (this.setup) {
143
+ case 'switchSingle':
144
+ params.switch = value ? 'on' : 'off'
145
+ break
146
+ case 'switchMulti':
147
+ params.switches = [
148
+ {
149
+ switch: value ? 'on' : 'off',
150
+ outlet: 0,
151
+ },
152
+ ]
153
+ break
154
+ default:
155
+ return
156
+ }
157
+ await this.platform.sendDeviceUpdate(this.accessory, params)
158
+ this.cacheState = value ? 'on' : 'off'
159
+ this.service.updateCharacteristic(this.hapChar.InUse, value)
160
+ if (this.enableLogging) {
161
+ this.log(
162
+ '[%s] %s [%s].',
163
+ this.name,
164
+ this.lang.curState,
165
+ value === 1 ? this.lang.valveYes : this.lang.valveNo,
166
+ )
167
+ }
168
+ } catch (err) {
169
+ this.platform.deviceUpdateError(this.accessory, err, true)
170
+ setTimeout(() => {
171
+ this.service.updateCharacteristic(this.hapChar.Active, this.cacheState === 'on')
172
+ }, 2000)
173
+ throw new this.hapErr(-70402)
174
+ }
175
+ }
176
+
177
+ async internalUIUpdate() {
178
+ try {
179
+ // Skip polling if device isn't online
180
+ if (!this.isOnline) {
181
+ return
182
+ }
183
+
184
+ // Send the params to request the updates
185
+ if (this.isDualR3) {
186
+ await this.platform.sendDeviceUpdate(this.accessory, { uiActive: { outlet: 0, time: 120 } })
187
+ } else {
188
+ await this.platform.sendDeviceUpdate(this.accessory, { uiActive: 120 })
189
+ }
190
+ } catch (err) {
191
+ // Suppress errors here
192
+ }
193
+ }
194
+
195
+ async externalUpdate(params) {
196
+ try {
197
+ if (
198
+ (this.setup === 'switchMulti' && params.switches)
199
+ || (this.setup === 'switchSingle' && params.switch)
200
+ ) {
201
+ let newState
202
+ if (this.setup === 'switchMulti' && params.switches) {
203
+ newState = params.switches[0].switch
204
+ } else if (this.setup === 'switchSingle' && params.switch) {
205
+ newState = params.switch
206
+ }
207
+ if (newState && newState !== this.cacheState) {
208
+ this.cacheState = newState
209
+ this.service.updateCharacteristic(this.hapChar.Active, this.cacheState === 'on' ? 1 : 0)
210
+ this.service.updateCharacteristic(this.hapChar.InUse, this.cacheState === 'on' ? 1 : 0)
211
+ if (params.updateSource && this.enableLogging) {
212
+ this.log(
213
+ '[%s] %s [%s].',
214
+ this.name,
215
+ this.lang.curState,
216
+ this.cacheState === 'on' ? this.lang.valveYes : this.lang.valveNo,
217
+ )
218
+ }
219
+ }
220
+ }
221
+
222
+ // Get the power readings given by certain devices
223
+ if (!this.powerReadings) {
224
+ return
225
+ }
226
+ let logger = false
227
+ let power
228
+ let voltage
229
+ let current
230
+ if (hasProperty(params, 'actPow_00')) {
231
+ power = Number.parseInt(params.actPow_00, 10) / 100
232
+ this.service.updateCharacteristic(this.eveChar.CurrentConsumption, power)
233
+ logger = true
234
+ } else if (hasProperty(params, 'power')) {
235
+ power = Number.parseFloat(params.power)
236
+ this.service.updateCharacteristic(this.eveChar.CurrentConsumption, power)
237
+ logger = true
238
+ }
239
+ if (hasProperty(params, 'voltage_00')) {
240
+ voltage = Number.parseInt(params.voltage_00, 10) / 100
241
+ this.service.updateCharacteristic(this.eveChar.Voltage, voltage)
242
+ logger = true
243
+ } else if (hasProperty(params, 'voltage')) {
244
+ voltage = Number.parseFloat(params.voltage)
245
+ this.service.updateCharacteristic(this.eveChar.Voltage, voltage)
246
+ logger = true
247
+ }
248
+ if (hasProperty(params, 'current_00')) {
249
+ current = Number.parseInt(params.current_00, 10) / 100
250
+ this.service.updateCharacteristic(this.eveChar.ElectricCurrent, current)
251
+ logger = true
252
+ } else if (hasProperty(params, 'current')) {
253
+ current = Number.parseFloat(params.current)
254
+ this.service.updateCharacteristic(this.eveChar.ElectricCurrent, current)
255
+ logger = true
256
+ }
257
+ if (params.updateSource && logger && this.enableLogging) {
258
+ this.log(
259
+ '[%s] %s%s%s.',
260
+ this.name,
261
+ power !== undefined ? `${this.lang.curPower} [${power}W]` : '',
262
+ voltage !== undefined ? ` ${this.lang.curVolt} [${voltage}V]` : '',
263
+ current !== undefined ? ` ${this.lang.curCurr} [${current}A]` : '',
264
+ )
265
+ }
266
+ } catch (err) {
267
+ this.platform.deviceUpdateError(this.accessory, err, false)
268
+ }
269
+ }
270
+
271
+ currentState() {
272
+ return {
273
+ services: ['valve'],
274
+ valve: {
275
+ state: this.service.getCharacteristic(this.hapChar.Active).value === 1 ? 'on' : 'off',
276
+ },
277
+ }
278
+ }
279
+
280
+ markStatus(isOnline) {
281
+ this.isOnline = isOnline
282
+ }
283
+ }
@@ -0,0 +1,266 @@
1
+ import platformConsts from '../../utils/constants.js'
2
+ import { hasProperty, sleep } from '../../utils/functions.js'
3
+
4
+ export default class {
5
+ constructor(platform, accessory) {
6
+ // Set up variables from the platform
7
+ this.eveChar = platform.eveChar
8
+ this.hapChar = platform.api.hap.Characteristic
9
+ this.hapErr = platform.api.hap.HapStatusError
10
+ this.hapServ = platform.api.hap.Service
11
+ this.lang = platform.lang
12
+ this.log = platform.log
13
+ this.platform = platform
14
+
15
+ // Set up variables from the accessory
16
+ this.name = accessory.displayName
17
+ this.accessory = accessory
18
+
19
+ // Initially set the online flag as true (to be then updated as false if necessary)
20
+ this.isOnline = true
21
+
22
+ // Set up custom variables for this device type
23
+ const deviceConf = platform.deviceConf[accessory.context.eweDeviceId] || {}
24
+
25
+ // Set the correct logging variables for this accessory
26
+ switch (deviceConf.overrideLogging) {
27
+ case 'standard':
28
+ this.enableLogging = true
29
+ this.enableDebugLogging = false
30
+ break
31
+ case 'debug':
32
+ this.enableLogging = true
33
+ this.enableDebugLogging = true
34
+ break
35
+ case 'disable':
36
+ this.enableLogging = false
37
+ this.enableDebugLogging = false
38
+ break
39
+ default:
40
+ this.enableLogging = !platform.config.disableDeviceLogging
41
+ this.enableDebugLogging = platform.config.debug
42
+ break
43
+ }
44
+
45
+ // Certain devices give power readings
46
+ if (platformConsts.devices.switchMultiPower.includes(this.accessory.context.eweUIID)) {
47
+ this.powerReadings = true
48
+ }
49
+
50
+ // We want two tap services for this accessory
51
+ ['1', '2'].forEach((v) => {
52
+ // Add the tap service if it doesn't already exist
53
+ let tapService = this.accessory.getService(`Tap ${v}`)
54
+ if (!tapService) {
55
+ tapService = this.accessory.addService(this.hapServ.Valve, `Tap ${v}`, `tap${v}`)
56
+ tapService.updateCharacteristic(this.hapChar.Active, 0)
57
+ tapService.updateCharacteristic(this.hapChar.InUse, 0)
58
+ tapService.updateCharacteristic(this.hapChar.ValveType, 3)
59
+ }
60
+
61
+ // Add Eve power characteristics
62
+ if (this.powerReadings) {
63
+ if (!tapService.testCharacteristic(this.eveChar.CurrentConsumption)) {
64
+ tapService.addCharacteristic(this.eveChar.CurrentConsumption)
65
+ }
66
+ if (!tapService.testCharacteristic(this.eveChar.ElectricCurrent)) {
67
+ tapService.addCharacteristic(this.eveChar.ElectricCurrent)
68
+ }
69
+ if (!tapService.testCharacteristic(this.eveChar.Voltage)) {
70
+ tapService.addCharacteristic(this.eveChar.Voltage)
71
+ }
72
+ }
73
+
74
+ // Add the set handler to the tap active characteristic
75
+ tapService
76
+ .getCharacteristic(this.hapChar.Active)
77
+ .onSet(async value => this.internalUpdate(`Tap ${v}`, value))
78
+
79
+ // Add the get handlers only if the user hasn't disabled the disableNoResponse setting
80
+ if (!platform.config.disableNoResponse) {
81
+ tapService.getCharacteristic(this.hapChar.Active).onGet(() => {
82
+ if (!this.isOnline) {
83
+ throw new this.hapErr(-70402)
84
+ }
85
+ return tapService.getCharacteristic(this.hapChar.Active).value
86
+ })
87
+ }
88
+ })
89
+
90
+ // Set up an interval to get eWeLink to send power updates
91
+ if (this.powerReadings && platform.config.mode !== 'lan') {
92
+ setTimeout(() => {
93
+ this.internalUIUpdate()
94
+ this.intervalPoll = setInterval(() => this.internalUIUpdate(), 120000)
95
+ }, 5000)
96
+
97
+ // Stop the intervals on Homebridge shutdown
98
+ platform.api.on('shutdown', () => clearInterval(this.intervalPoll))
99
+ }
100
+
101
+ // Output the customised options to the log
102
+ const normalLogging = this.enableLogging ? 'standard' : 'disable'
103
+ const opts = JSON.stringify({
104
+ logging: this.enableDebugLogging ? 'debug' : normalLogging,
105
+ showAs: 'tap_two',
106
+ })
107
+ this.log('[%s] %s %s.', this.name, this.lang.devInitOpts, opts)
108
+ }
109
+
110
+ async internalUpdate(tap, value) {
111
+ try {
112
+ const params = {
113
+ switches: [],
114
+ }
115
+ const tapService = this.accessory.getService(tap)
116
+ switch (tap) {
117
+ case 'Tap 1':
118
+ params.switches.push({ switch: value ? 'on' : 'off', outlet: 0 })
119
+ break
120
+ case 'Tap 2':
121
+ params.switches.push({ switch: value ? 'on' : 'off', outlet: 1 })
122
+ break
123
+ default:
124
+ return
125
+ }
126
+ tapService.updateCharacteristic(this.hapChar.InUse, value)
127
+ if (this.enableLogging) {
128
+ this.log(
129
+ '[%s] [%s] %s [%s].',
130
+ this.name,
131
+ tap,
132
+ this.lang.curState,
133
+ value === 1 ? this.lang.valveYes : this.lang.valveNo,
134
+ )
135
+ }
136
+ await this.platform.sendDeviceUpdate(this.accessory, params)
137
+ } catch (err) {
138
+ this.platform.deviceUpdateError(this.accessory, err, true)
139
+ const tapService = this.accessory.getService(tap)
140
+ setTimeout(() => {
141
+ tapService.updateCharacteristic(this.hapChar.Active, value === 1 ? 0 : 1)
142
+ }, 2000)
143
+ throw new this.hapErr(-70402)
144
+ }
145
+ }
146
+
147
+ async internalUIUpdate() {
148
+ try {
149
+ // Skip polling if device isn't online
150
+ if (!this.isOnline) {
151
+ return
152
+ }
153
+
154
+ // Send the params to request the updates
155
+ await this.platform.sendDeviceUpdate(this.accessory, { uiActive: { outlet: 0, time: 120 } })
156
+ await sleep(2000)
157
+ await this.platform.sendDeviceUpdate(this.accessory, { uiActive: { outlet: 1, time: 120 } })
158
+ } catch (err) {
159
+ // Suppress errors here
160
+ }
161
+ }
162
+
163
+ async externalUpdate(params) {
164
+ try {
165
+ if (params.switches) {
166
+ ['1', '2'].forEach((v, k) => {
167
+ const tapService = this.accessory.getService(`Tap ${v}`)
168
+ tapService.updateCharacteristic(
169
+ this.hapChar.Active,
170
+ params.switches[k].switch === 'on' ? 1 : 0,
171
+ )
172
+ tapService.updateCharacteristic(
173
+ this.hapChar.InUse,
174
+ params.switches[k].switch === 'on' ? 1 : 0,
175
+ )
176
+ if (params.updateSource && this.enableLogging) {
177
+ this.log(
178
+ '[%s] [Tap %s] %s [%s].',
179
+ this.name,
180
+ v,
181
+ this.lang.curState,
182
+ params.switches[k].switch === 'on' ? this.lang.valveYes : this.lang.valveNo,
183
+ )
184
+ }
185
+ })
186
+ }
187
+
188
+ // Get the power readings given by certain devices
189
+ if (!this.powerReadings) {
190
+ return
191
+ }
192
+ let logger0 = false
193
+ let logger1 = false
194
+ let power0
195
+ let power1
196
+ let voltage0
197
+ let voltage1
198
+ let current0
199
+ let current1
200
+ if (hasProperty(params, 'actPow_00')) {
201
+ power0 = Number.parseInt(params.actPow_00, 10) / 100
202
+ this.accessory
203
+ .getService('Tap 1')
204
+ .updateCharacteristic(this.eveChar.CurrentConsumption, power0)
205
+ logger0 = true
206
+ }
207
+ if (hasProperty(params, 'actPow_01')) {
208
+ power1 = Number.parseInt(params.actPow_01, 10) / 100
209
+ this.accessory
210
+ .getService('Tap 2')
211
+ .updateCharacteristic(this.eveChar.CurrentConsumption, power1)
212
+ logger1 = true
213
+ }
214
+ if (hasProperty(params, 'voltage_00')) {
215
+ voltage0 = Number.parseInt(params.voltage_00, 10) / 100
216
+ this.accessory.getService('Tap 1').updateCharacteristic(this.eveChar.Voltage, voltage0)
217
+ logger0 = true
218
+ }
219
+ if (hasProperty(params, 'voltage_01')) {
220
+ voltage1 = Number.parseInt(params.voltage_01, 10) / 100
221
+ this.accessory.getService('Tap 2').updateCharacteristic(this.eveChar.Voltage, voltage1)
222
+ logger1 = true
223
+ }
224
+ if (hasProperty(params, 'current_00')) {
225
+ current0 = Number.parseInt(params.current_00, 10) / 100
226
+ this.accessory
227
+ .getService('Tap 1')
228
+ .updateCharacteristic(this.eveChar.ElectricCurrent, current0)
229
+ logger0 = true
230
+ }
231
+ if (hasProperty(params, 'current_01')) {
232
+ current1 = Number.parseInt(params.current_01, 10) / 100
233
+ this.accessory
234
+ .getService('Tap 2')
235
+ .updateCharacteristic(this.eveChar.ElectricCurrent, current1)
236
+ logger1 = true
237
+ }
238
+ if (params.updateSource && this.enableLogging) {
239
+ if (logger0) {
240
+ this.log(
241
+ '[%s] [Tap 1] %s%s%s.',
242
+ this.name,
243
+ power0 !== undefined ? `${this.lang.curPower} [${power0}W]` : '',
244
+ voltage0 !== undefined ? ` ${this.lang.curVolt} [${voltage0}V]` : '',
245
+ current0 !== undefined ? ` ${this.lang.curCurr} [${current0}A]` : '',
246
+ )
247
+ }
248
+ if (logger1) {
249
+ this.log(
250
+ '[%s] [Tap 2] %s%s%s.',
251
+ this.name,
252
+ power1 !== undefined ? `${this.lang.curPower} [${power1}W]` : '',
253
+ voltage1 !== undefined ? ` ${this.lang.curVolt} [${voltage1}V]` : '',
254
+ current1 !== undefined ? ` ${this.lang.curCurr} [${current1}A]` : '',
255
+ )
256
+ }
257
+ }
258
+ } catch (err) {
259
+ this.platform.deviceUpdateError(this.accessory, err, false)
260
+ }
261
+ }
262
+
263
+ markStatus(isOnline) {
264
+ this.isOnline = isOnline
265
+ }
266
+ }