@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,323 @@
1
+ import platformConsts from '../../utils/constants.js'
2
+ import { hasProperty, parseError } from '../../utils/functions.js'
3
+
4
+ export default class {
5
+ constructor(platform, accessory) {
6
+ // Set up variables from the platform
7
+ this.hapChar = platform.api.hap.Characteristic
8
+ this.hapServ = platform.api.hap.Service
9
+ this.hapErr = platform.api.hap.HapStatusError
10
+ this.lang = platform.lang
11
+ this.log = platform.log
12
+ this.platform = platform
13
+
14
+ // Set up variables from the accessory
15
+ this.name = accessory.displayName
16
+ this.accessory = accessory
17
+
18
+ // Initially set the online flag as true (to be then updated as false if necessary)
19
+ this.isOnline = true
20
+
21
+ // Set up custom variables for this device type
22
+ const deviceConf = platform.deviceConf[accessory.context.eweDeviceId] || {}
23
+ this.tempOffset = deviceConf.offset || platformConsts.defaultValues.offset
24
+ this.tempOffsetFactor = deviceConf.offsetFactor
25
+
26
+ // Set the correct logging variables for this accessory
27
+ switch (deviceConf.overrideLogging) {
28
+ case 'standard':
29
+ this.enableLogging = true
30
+ this.enableDebugLogging = false
31
+ break
32
+ case 'debug':
33
+ this.enableLogging = true
34
+ this.enableDebugLogging = true
35
+ break
36
+ case 'disable':
37
+ this.enableLogging = false
38
+ this.enableDebugLogging = false
39
+ break
40
+ default:
41
+ this.enableLogging = !platform.config.disableDeviceLogging
42
+ this.enableDebugLogging = platform.config.debug
43
+ break
44
+ }
45
+
46
+ /*
47
+ **************
48
+ *** PARAMS ***
49
+ **************
50
+ "subDevId": "",
51
+ "parentid": "",
52
+ "fwVersion": "1.1.1",
53
+ "battery": 100,
54
+ "supportPowConfig": 1,
55
+ "ecoTargetTemp": 70,
56
+ "step": "008d",
57
+ "limitVoltage": "0507",
58
+ "runVoltage": "0593",
59
+ "temperature": 230,
60
+ "trigTime": "1698510595000",
61
+ "mon": "000000a001a400be025800a0025800a003fc00be056400a0",
62
+ "tues": "000000a001a400be025800a0025800a003fc00be056400a0",
63
+ "workMode": "0",
64
+ "curTargetTemp": 230,
65
+ "switch": "on",
66
+ "manTargetTemp": 230,
67
+ "wed": "000000a001a400be025800a0025800a003fc00be056400a0",
68
+ "thur": "000000a001a400be025800a0025800a003fc00be056400a0",
69
+ "fri": "000000a001a400be025800a0025800a003fc00be056400a0",
70
+ "sat": "000000a001a400be025800be025800be025800be056400a0",
71
+ "sun": "000000a001a400be025800be025800be025800be056400a0",
72
+ "autoTargetTemp": 190,
73
+ "workState": "0"
74
+ */
75
+
76
+ // Add the thermostat service if it doesn't already exist
77
+ this.service = this.accessory.getService(this.hapServ.Thermostat)
78
+ || this.accessory.addService(this.hapServ.Thermostat)
79
+
80
+ // Set custom properties of the current temperature characteristic
81
+ this.service.getCharacteristic(this.hapChar.CurrentTemperature).setProps({
82
+ minStep: 0.1,
83
+ })
84
+ this.cacheTemp = this.service.getCharacteristic(this.hapChar.CurrentTemperature).value
85
+ this.updateCache()
86
+
87
+ // Add the set handler to the target state characteristic
88
+ this.service
89
+ .getCharacteristic(this.hapChar.TargetHeatingCoolingState)
90
+ .setProps({
91
+ minValue: 0,
92
+ maxValue: 3,
93
+ validValues: [0, 1, 3],
94
+ })
95
+ .onSet(async value => this.internalStateUpdate(value))
96
+
97
+ // Add the set handler to the target temperature characteristic
98
+ this.service
99
+ .getCharacteristic(this.hapChar.TargetTemperature)
100
+ .setProps({
101
+ minValue: 5,
102
+ maxValue: 45,
103
+ minStep: 0.5,
104
+ })
105
+ .onSet(async value => this.internalTargetUpdate(value))
106
+
107
+ // Add the get handlers only if the user hasn't disabled the disableNoResponse setting
108
+ if (!platform.config.disableNoResponse) {
109
+ this.service.getCharacteristic(this.hapChar.CurrentTemperature).onGet(() => {
110
+ if (!this.isOnline) {
111
+ throw new this.hapErr(-70402)
112
+ }
113
+ return this.service.getCharacteristic(this.hapChar.CurrentTemperature).value
114
+ })
115
+ this.service.getCharacteristic(this.hapChar.CurrentHeatingCoolingState).onGet(() => {
116
+ if (!this.isOnline) {
117
+ throw new this.hapErr(-70402)
118
+ }
119
+ return this.service.getCharacteristic(this.hapChar.CurrentHeatingCoolingState).value
120
+ })
121
+ this.service.getCharacteristic(this.hapChar.TargetHeatingCoolingState).onGet(() => {
122
+ if (!this.isOnline) {
123
+ throw new this.hapErr(-70402)
124
+ }
125
+ return this.service.getCharacteristic(this.hapChar.TargetHeatingCoolingState).value
126
+ })
127
+ this.service.getCharacteristic(this.hapChar.TargetTemperature).onGet(() => {
128
+ if (!this.isOnline) {
129
+ throw new this.hapErr(-70402)
130
+ }
131
+ return this.service.getCharacteristic(this.hapChar.TargetTemperature).value
132
+ })
133
+ }
134
+
135
+ // Pass the accessory to Fakegato to set up with Eve
136
+ this.accessory.eveService = new platform.eveService('custom', this.accessory, {
137
+ log: () => {},
138
+ })
139
+
140
+ // Output the customised options to the log
141
+ const normalLogging = this.enableLogging ? 'standard' : 'disable'
142
+ const opts = JSON.stringify({
143
+ logging: this.enableDebugLogging ? 'debug' : normalLogging,
144
+ offset: this.tempOffset,
145
+ offsetFactor: this.tempOffsetFactor,
146
+ })
147
+ this.log('[%s] %s %s.', this.name, this.lang.devInitOpts, opts)
148
+ }
149
+
150
+ async internalStateUpdate(value) {
151
+ // value is 0 (off), 1 (heat), 3 (auto)
152
+ // workMode for heat is 0, auto is 2
153
+ try {
154
+ const params = {}
155
+
156
+ switch (value) {
157
+ case 0:
158
+ if (this.cacheMode === 'off') {
159
+ return
160
+ }
161
+
162
+ // still not sure which params to send for "off"
163
+ this.cacheMode = 'off'
164
+ params.workMode = '1'
165
+ break
166
+ case 1:
167
+ case 2:
168
+ if (this.cacheMode === 'heat') {
169
+ return
170
+ }
171
+ this.cacheMode = 'heat'
172
+ params.workMode = '0'
173
+ break
174
+ case 3:
175
+ if (this.cacheMode === 'auto') {
176
+ return
177
+ }
178
+ this.cacheMode = 'auto'
179
+ params.workMode = '2'
180
+ break
181
+ default:
182
+ return
183
+ }
184
+
185
+ await this.platform.sendDeviceUpdate(this.accessory, params)
186
+ if (this.enableLogging) {
187
+ this.log('[%s] %s [%s].', this.name, this.lang.curMode, this.cacheMode)
188
+ }
189
+ } catch (err) {
190
+ this.platform.deviceUpdateError(this.accessory, err, true)
191
+ setTimeout(() => {
192
+ this.service.updateCharacteristic(
193
+ this.hapChar.TargetHeatingCoolingState,
194
+
195
+ this.cacheMode === 'auto' ? 3 : (this.cacheMode === 'heat' ? 1 : 0),
196
+ )
197
+ }, 2000)
198
+ throw new this.hapErr(-70402)
199
+ }
200
+ }
201
+
202
+ async internalTargetUpdate(value) {
203
+ try {
204
+ const params = {
205
+ workMode: '0',
206
+ curTargetTemp: value * 10,
207
+ }
208
+ await this.platform.sendDeviceUpdate(this.accessory, params)
209
+ this.cacheTarg = value
210
+ if (this.enableLogging) {
211
+ this.log('[%s] %s [%s°C].', this.name, this.lang.curTarg, this.cacheTarg)
212
+ }
213
+ } catch (err) {
214
+ this.platform.deviceUpdateError(this.accessory, err, true)
215
+ setTimeout(() => {
216
+ this.service.updateCharacteristic(this.hapChar.TargetTemperature, this.cacheTarg)
217
+ }, 2000)
218
+ throw new this.hapErr(-70402)
219
+ }
220
+ }
221
+
222
+ async externalUpdate(params) {
223
+ try {
224
+ if (params.workMode) {
225
+ let workMode
226
+ let hkWorkMode
227
+ switch (params.workMode) {
228
+ case '0':
229
+ workMode = 'heat'
230
+ hkWorkMode = 1
231
+ break
232
+ case '1':
233
+ workMode = 'off'
234
+ hkWorkMode = 0
235
+ break
236
+ // case '2':
237
+ default:
238
+ workMode = 'auto'
239
+ hkWorkMode = 3
240
+ break
241
+ }
242
+ if (this.cacheMode !== workMode) {
243
+ this.cacheMode = workMode
244
+ this.service.updateCharacteristic(this.hapChar.TargetHeatingCoolingState, hkWorkMode)
245
+ if (params.updateSource && this.enableLogging) {
246
+ this.log('[%s] %s [%s].', this.name, this.lang.curMode, this.cacheMode)
247
+ }
248
+ }
249
+ }
250
+
251
+ if (params.workState) {
252
+ const workState = params.workState === '1' ? 'on' : 'off'
253
+ if (this.cacheHeat !== workState) {
254
+ this.cacheHeat = workState
255
+ this.service.updateCharacteristic(
256
+ this.hapChar.CurrentHeatingCoolingState,
257
+ this.cacheHeat === 'on' ? 1 : 0,
258
+ )
259
+ if (params.updateSource && this.enableLogging) {
260
+ this.log('[%s] %s [%s].', this.name, this.lang.curHeat, this.cacheHeat)
261
+ }
262
+ }
263
+ }
264
+
265
+ if (hasProperty(params, 'curTargetTemp')) {
266
+ const curTargetTemp = Number(params.curTargetTemp) / 10
267
+ if (this.cacheTarg !== curTargetTemp) {
268
+ this.cacheTarg = curTargetTemp
269
+ this.service.updateCharacteristic(this.hapChar.TargetTemperature, this.cacheTarg)
270
+ if (params.updateSource && this.enableLogging) {
271
+ this.log('[%s] %s [%s°C].', this.name, this.lang.curTarg, this.cacheTarg)
272
+ }
273
+ }
274
+ }
275
+
276
+ if (hasProperty(params, 'temperature')) {
277
+ let currentTemp = Number(params.temperature) / 10
278
+ if (this.tempOffsetFactor) {
279
+ currentTemp *= this.tempOffset
280
+ } else {
281
+ currentTemp += this.tempOffset
282
+ }
283
+
284
+ if (this.cacheTemp !== currentTemp) {
285
+ this.cacheTemp = currentTemp
286
+ this.service.updateCharacteristic(this.hapChar.CurrentTemperature, this.cacheTemp)
287
+ this.accessory.eveService.addEntry({ temp: this.cacheTemp })
288
+ if (params.updateSource && this.enableLogging) {
289
+ this.log('[%s] %s [%s°C].', this.name, this.lang.curTemp, this.cacheTemp)
290
+ }
291
+
292
+ // Update the cache file with the new temperature
293
+ this.updateCache()
294
+ }
295
+ }
296
+ } catch (err) {
297
+ this.platform.deviceUpdateError(this.accessory, err, false)
298
+ }
299
+ }
300
+
301
+ async updateCache() {
302
+ // Don't continue if the storage client hasn't initialised properly
303
+ if (!this.platform.storageClientData) {
304
+ return
305
+ }
306
+
307
+ // Attempt to save the new temperature to the cache
308
+ try {
309
+ await this.platform.storageData.setItem(
310
+ `${this.accessory.context.eweDeviceId}_temp`,
311
+ this.cacheTemp,
312
+ )
313
+ } catch (err) {
314
+ if (this.enableLogging) {
315
+ this.log.warn('[%s] %s %s.', this.name, this.lang.storageWriteErr, parseError(err))
316
+ }
317
+ }
318
+ }
319
+
320
+ markStatus(isOnline) {
321
+ this.isOnline = isOnline
322
+ }
323
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 simont77
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.