@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,119 @@
|
|
|
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.hapServ = platform.api.hap.Service
|
|
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
|
+
// Set up custom variables for this device type
|
|
19
|
+
const deviceConf = platform.deviceConf[accessory.context.eweDeviceId] || {}
|
|
20
|
+
this.lowBattThreshold = deviceConf.lowBattThreshold
|
|
21
|
+
? Math.min(deviceConf.lowBattThreshold, 100)
|
|
22
|
+
: platformConsts.defaultValues.lowBattThreshold
|
|
23
|
+
this.sensorTimeDifference = deviceConf.sensorTimeDifference || platformConsts.defaultValues.sensorTimeDifference
|
|
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
|
+
// Add the leak sensor service if it doesn't already exist
|
|
46
|
+
this.service = this.accessory.getService(this.hapServ.LeakSensor)
|
|
47
|
+
if (!this.service) {
|
|
48
|
+
this.service = this.accessory.addService(this.hapServ.LeakSensor)
|
|
49
|
+
this.service.addCharacteristic(this.eveChar.LastActivation)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Add the battery service if it doesn't already exist
|
|
53
|
+
this.battService = this.accessory.getService(this.hapServ.Battery)
|
|
54
|
+
|| this.accessory.addService(this.hapServ.Battery)
|
|
55
|
+
|
|
56
|
+
// Pass the accessory to Fakegato to set up with Eve
|
|
57
|
+
this.accessory.eveService = new platform.eveService('motion', this.accessory, {
|
|
58
|
+
log: () => {},
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// Output the customised options to the log
|
|
62
|
+
const normalLogging = this.enableLogging ? 'standard' : 'disable'
|
|
63
|
+
const opts = JSON.stringify({
|
|
64
|
+
logging: this.enableDebugLogging ? 'debug' : normalLogging,
|
|
65
|
+
lowBattThreshold: this.lowBattThreshold,
|
|
66
|
+
sensorTimeDifference: this.sensorTimeDifference,
|
|
67
|
+
})
|
|
68
|
+
this.log('[%s] %s %s.', this.name, this.lang.devInitOpts, opts)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async externalUpdate(params) {
|
|
72
|
+
try {
|
|
73
|
+
if (hasProperty(params, 'battery') && params.battery !== this.cacheBatt) {
|
|
74
|
+
this.cacheBatt = params.battery
|
|
75
|
+
this.cacheBattScaled = Math.max(Math.min(this.cacheBatt, 100), 0)
|
|
76
|
+
this.battService.updateCharacteristic(this.hapChar.BatteryLevel, this.cacheBattScaled)
|
|
77
|
+
this.battService.updateCharacteristic(
|
|
78
|
+
this.hapChar.StatusLowBattery,
|
|
79
|
+
this.cacheBattScaled < this.lowBattThreshold ? 1 : 0,
|
|
80
|
+
)
|
|
81
|
+
if (params.updateSource && this.enableLogging) {
|
|
82
|
+
this.log('[%s] %s [%s%].', this.name, this.lang.curBatt, this.cacheBattScaled)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (
|
|
86
|
+
hasProperty(params, 'water')
|
|
87
|
+
&& hasProperty(params, 'trigTime')
|
|
88
|
+
&& this.cacheState !== params.water
|
|
89
|
+
) {
|
|
90
|
+
this.cacheState = params.water
|
|
91
|
+
const timeDiff = (new Date().getTime() - params.trigTime) / 1000
|
|
92
|
+
const leakDetected = !!(
|
|
93
|
+
params.updateSource
|
|
94
|
+
&& params.water === 1
|
|
95
|
+
&& timeDiff < this.sensorTimeDifference
|
|
96
|
+
)
|
|
97
|
+
this.service.updateCharacteristic(this.hapChar.LeakDetected, leakDetected ? 1 : 0)
|
|
98
|
+
if (leakDetected) {
|
|
99
|
+
const initialTime = this.accessory.eveService.getInitialTime()
|
|
100
|
+
this.service.updateCharacteristic(
|
|
101
|
+
this.eveChar.LastActivation,
|
|
102
|
+
Math.round(new Date().valueOf() / 1000) - initialTime,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
this.accessory.eveService.addEntry({ status: leakDetected ? 1 : 0 })
|
|
106
|
+
if (params.updateSource && this.enableLogging) {
|
|
107
|
+
this.log(
|
|
108
|
+
'[%s] %s [%s].',
|
|
109
|
+
this.name,
|
|
110
|
+
this.lang.curState,
|
|
111
|
+
leakDetected ? this.lang.leakYes : this.lang.leakNo,
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
this.platform.deviceUpdateError(this.accessory, err, false)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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.hapServ = platform.api.hap.Service
|
|
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
|
+
// Set up custom variables for this device type
|
|
19
|
+
const deviceConf = platform.deviceConf[accessory.context.eweDeviceId] || {}
|
|
20
|
+
this.lowBattThreshold = deviceConf.lowBattThreshold
|
|
21
|
+
? Math.min(deviceConf.lowBattThreshold, 100)
|
|
22
|
+
: platformConsts.defaultValues.lowBattThreshold
|
|
23
|
+
this.sensorTimeDifference = deviceConf.sensorTimeDifference || platformConsts.defaultValues.sensorTimeDifference
|
|
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
|
+
// Add the motion sensor service if it doesn't already exist
|
|
46
|
+
this.service = this.accessory.getService(this.hapServ.MotionSensor)
|
|
47
|
+
if (!this.service) {
|
|
48
|
+
this.service = this.accessory.addService(this.hapServ.MotionSensor)
|
|
49
|
+
this.service.addCharacteristic(this.eveChar.LastActivation)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Add the battery service if it doesn't already exist
|
|
53
|
+
this.battService = this.accessory.getService(this.hapServ.Battery)
|
|
54
|
+
|| this.accessory.addService(this.hapServ.Battery)
|
|
55
|
+
|
|
56
|
+
// Pass the accessory to Fakegato to set up with Eve
|
|
57
|
+
this.accessory.eveService = new platform.eveService('motion', this.accessory, {
|
|
58
|
+
log: () => {},
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// Output the customised options to the log
|
|
62
|
+
const normalLogging = this.enableLogging ? 'standard' : 'disable'
|
|
63
|
+
const opts = JSON.stringify({
|
|
64
|
+
logging: this.enableDebugLogging ? 'debug' : normalLogging,
|
|
65
|
+
lowBattThreshold: this.lowBattThreshold,
|
|
66
|
+
sensorTimeDifference: this.sensorTimeDifference,
|
|
67
|
+
})
|
|
68
|
+
this.log('[%s] %s %s.', this.name, this.lang.devInitOpts, opts)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async externalUpdate(params) {
|
|
72
|
+
try {
|
|
73
|
+
if (hasProperty(params, 'battery') && params.battery !== this.cacheBatt) {
|
|
74
|
+
this.cacheBatt = params.battery
|
|
75
|
+
this.cacheBattScaled = Math.max(Math.min(this.cacheBatt, 100), 0)
|
|
76
|
+
this.battService.updateCharacteristic(this.hapChar.BatteryLevel, this.cacheBattScaled)
|
|
77
|
+
this.battService.updateCharacteristic(
|
|
78
|
+
this.hapChar.StatusLowBattery,
|
|
79
|
+
this.cacheBattScaled < this.lowBattThreshold ? 1 : 0,
|
|
80
|
+
)
|
|
81
|
+
if (params.updateSource && this.enableLogging) {
|
|
82
|
+
this.log('[%s] %s [%s%].', this.name, this.lang.curBatt, this.cacheBattScaled)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (
|
|
86
|
+
hasProperty(params, 'motion')
|
|
87
|
+
&& hasProperty(params, 'trigTime')
|
|
88
|
+
&& params.motion !== this.cacheState
|
|
89
|
+
) {
|
|
90
|
+
this.cacheState = params.motion
|
|
91
|
+
const timeDiff = (new Date().getTime() - params.trigTime) / 1000
|
|
92
|
+
const motionDetected = !!(
|
|
93
|
+
params.updateSource
|
|
94
|
+
&& params.motion === 1
|
|
95
|
+
&& timeDiff < this.sensorTimeDifference
|
|
96
|
+
)
|
|
97
|
+
this.service.updateCharacteristic(this.hapChar.MotionDetected, motionDetected)
|
|
98
|
+
if (motionDetected) {
|
|
99
|
+
const initialTime = this.accessory.eveService.getInitialTime()
|
|
100
|
+
this.service.updateCharacteristic(
|
|
101
|
+
this.eveChar.LastActivation,
|
|
102
|
+
Math.round(new Date().valueOf() / 1000) - initialTime,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
this.accessory.eveService.addEntry({ status: motionDetected ? 1 : 0 })
|
|
106
|
+
if (params.updateSource && this.enableLogging) {
|
|
107
|
+
this.log(
|
|
108
|
+
'[%s] %s [%s].',
|
|
109
|
+
this.name,
|
|
110
|
+
this.lang.curState,
|
|
111
|
+
motionDetected ? this.lang.motionYes : this.lang.motionNo,
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
this.platform.deviceUpdateError(this.accessory, err, false)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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.hapServ = platform.api.hap.Service
|
|
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
|
+
// Set up custom variables for this device type
|
|
19
|
+
const deviceConf = platform.deviceConf[accessory.context.eweDeviceId] || {}
|
|
20
|
+
this.lowBattThreshold = deviceConf.lowBattThreshold
|
|
21
|
+
? Math.min(deviceConf.lowBattThreshold, 100)
|
|
22
|
+
: platformConsts.defaultValues.lowBattThreshold
|
|
23
|
+
this.sensorTimeDifference = deviceConf.sensorTimeDifference || platformConsts.defaultValues.sensorTimeDifference
|
|
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
|
+
// Add the occupancy sensor service if it doesn't already exist
|
|
46
|
+
this.service = this.accessory.getService(this.hapServ.OccupancySensor)
|
|
47
|
+
if (!this.service) {
|
|
48
|
+
this.service = this.accessory.addService(this.hapServ.OccupancySensor)
|
|
49
|
+
this.service.addCharacteristic(this.eveChar.LastActivation)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Add the battery service if it doesn't already exist
|
|
53
|
+
this.battService = this.accessory.getService(this.hapServ.Battery)
|
|
54
|
+
|| this.accessory.addService(this.hapServ.Battery)
|
|
55
|
+
|
|
56
|
+
// Pass the accessory to Fakegato to set up with Eve
|
|
57
|
+
this.accessory.eveService = new platform.eveService('motion', this.accessory, {
|
|
58
|
+
log: () => {},
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// Output the customised options to the log
|
|
62
|
+
const normalLogging = this.enableLogging ? 'standard' : 'disable'
|
|
63
|
+
const opts = JSON.stringify({
|
|
64
|
+
logging: this.enableDebugLogging ? 'debug' : normalLogging,
|
|
65
|
+
lowBattThreshold: this.lowBattThreshold,
|
|
66
|
+
sensorTimeDifference: this.sensorTimeDifference,
|
|
67
|
+
})
|
|
68
|
+
this.log('[%s] %s %s.', this.name, this.lang.devInitOpts, opts)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async externalUpdate(params) {
|
|
72
|
+
try {
|
|
73
|
+
if (hasProperty(params, 'battery') && params.battery !== this.cacheBatt) {
|
|
74
|
+
this.cacheBatt = params.battery
|
|
75
|
+
this.cacheBattScaled = Math.max(Math.min(this.cacheBatt, 100), 0)
|
|
76
|
+
this.battService.updateCharacteristic(this.hapChar.BatteryLevel, this.cacheBattScaled)
|
|
77
|
+
this.battService.updateCharacteristic(
|
|
78
|
+
this.hapChar.StatusLowBattery,
|
|
79
|
+
this.cacheBattScaled < this.lowBattThreshold ? 1 : 0,
|
|
80
|
+
)
|
|
81
|
+
if (params.updateSource && this.enableLogging) {
|
|
82
|
+
this.log('[%s] %s [%s%].', this.name, this.lang.curBatt, this.cacheBattScaled)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (
|
|
86
|
+
hasProperty(params, 'human')
|
|
87
|
+
&& hasProperty(params, 'trigTime')
|
|
88
|
+
&& params.occupancy !== this.cacheState
|
|
89
|
+
) {
|
|
90
|
+
this.cacheState = params.occupancy
|
|
91
|
+
const timeDiff = (new Date().getTime() - params.trigTime) / 1000
|
|
92
|
+
const occupancyDetected = !!(
|
|
93
|
+
params.updateSource
|
|
94
|
+
&& params.occupancy === 1
|
|
95
|
+
&& timeDiff < this.sensorTimeDifference
|
|
96
|
+
)
|
|
97
|
+
this.service.updateCharacteristic(this.hapChar.OccupancyDetected, occupancyDetected)
|
|
98
|
+
if (occupancyDetected) {
|
|
99
|
+
const initialTime = this.accessory.eveService.getInitialTime()
|
|
100
|
+
this.service.updateCharacteristic(
|
|
101
|
+
this.eveChar.LastActivation,
|
|
102
|
+
Math.round(new Date().valueOf() / 1000) - initialTime,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
this.accessory.eveService.addEntry({ status: occupancyDetected ? 1 : 0 })
|
|
106
|
+
if (params.updateSource && this.enableLogging) {
|
|
107
|
+
this.log(
|
|
108
|
+
'[%s] %s [%s].',
|
|
109
|
+
this.name,
|
|
110
|
+
this.lang.curState,
|
|
111
|
+
occupancyDetected ? this.lang.occupancyYes : this.lang.occupancyNo,
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
this.platform.deviceUpdateError(this.accessory, err, false)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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.hapServ = platform.api.hap.Service
|
|
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
|
+
// Set up custom variables for this device type
|
|
19
|
+
const deviceConf = platform.deviceConf[accessory.context.eweDeviceId] || {}
|
|
20
|
+
this.lowBattThreshold = deviceConf.lowBattThreshold
|
|
21
|
+
? Math.min(deviceConf.lowBattThreshold, 100)
|
|
22
|
+
: platformConsts.defaultValues.lowBattThreshold
|
|
23
|
+
|
|
24
|
+
// Set the correct logging variables for this accessory
|
|
25
|
+
switch (deviceConf.overrideLogging) {
|
|
26
|
+
case 'standard':
|
|
27
|
+
this.enableLogging = true
|
|
28
|
+
this.enableDebugLogging = false
|
|
29
|
+
break
|
|
30
|
+
case 'debug':
|
|
31
|
+
this.enableLogging = true
|
|
32
|
+
this.enableDebugLogging = true
|
|
33
|
+
break
|
|
34
|
+
case 'disable':
|
|
35
|
+
this.enableLogging = false
|
|
36
|
+
this.enableDebugLogging = false
|
|
37
|
+
break
|
|
38
|
+
default:
|
|
39
|
+
this.enableLogging = !platform.config.disableDeviceLogging
|
|
40
|
+
this.enableDebugLogging = platform.config.debug
|
|
41
|
+
break
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Add the smoke sensor service if it doesn't already exist
|
|
45
|
+
this.service = this.accessory.getService(this.hapServ.SmokeSensor)
|
|
46
|
+
|| this.accessory.addService(this.hapServ.SmokeSensor)
|
|
47
|
+
|
|
48
|
+
// Add the battery service if it doesn't already exist
|
|
49
|
+
this.battService = this.accessory.getService(this.hapServ.Battery)
|
|
50
|
+
|| this.accessory.addService(this.hapServ.Battery)
|
|
51
|
+
|
|
52
|
+
// Output the customised options to the log
|
|
53
|
+
const normalLogging = this.enableLogging ? 'standard' : 'disable'
|
|
54
|
+
const opts = JSON.stringify({
|
|
55
|
+
logging: this.enableDebugLogging ? 'debug' : normalLogging,
|
|
56
|
+
lowBattThreshold: this.lowBattThreshold,
|
|
57
|
+
})
|
|
58
|
+
this.log('[%s] %s %s.', this.name, this.lang.devInitOpts, opts)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async externalUpdate(params) {
|
|
62
|
+
try {
|
|
63
|
+
if (hasProperty(params, 'battery') && params.battery !== this.cacheBatt) {
|
|
64
|
+
this.cacheBatt = params.battery
|
|
65
|
+
this.cacheBattScaled = this.scaleBattery ? this.cacheBatt * 10 : this.cacheBatt
|
|
66
|
+
this.cacheBattScaled = Math.max(Math.min(this.cacheBattScaled, 100), 0)
|
|
67
|
+
this.battService.updateCharacteristic(this.hapChar.BatteryLevel, this.cacheBattScaled)
|
|
68
|
+
this.battService.updateCharacteristic(
|
|
69
|
+
this.hapChar.StatusLowBattery,
|
|
70
|
+
this.cacheBattScaled < this.lowBattThreshold ? 1 : 0,
|
|
71
|
+
)
|
|
72
|
+
if (params.updateSource && this.enableLogging) {
|
|
73
|
+
this.log('[%s] %s [%s%].', this.name, this.lang.curBatt, this.cacheBattScaled)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (
|
|
77
|
+
hasProperty(params, 'smoke')
|
|
78
|
+
&& [0, 1].includes(params.smoke)
|
|
79
|
+
&& params.smoke !== this.cacheState
|
|
80
|
+
) {
|
|
81
|
+
this.cacheState = params.smoke
|
|
82
|
+
this.service.updateCharacteristic(this.hapChar.SmokeDetected, this.cacheState)
|
|
83
|
+
if (params.updateSource && this.enableLogging) {
|
|
84
|
+
this.log(
|
|
85
|
+
'[%s] %s [%s].',
|
|
86
|
+
this.name,
|
|
87
|
+
this.lang.curState,
|
|
88
|
+
params.smoke === 0 ? this.lang.smokeYes : this.lang.smokeNo,
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} catch (err) {
|
|
93
|
+
this.platform.deviceUpdateError(this.accessory, err, false)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
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.hapChar = platform.api.hap.Characteristic
|
|
8
|
+
this.hapServ = platform.api.hap.Service
|
|
9
|
+
this.lang = platform.lang
|
|
10
|
+
this.log = platform.log
|
|
11
|
+
this.platform = platform
|
|
12
|
+
|
|
13
|
+
// Set up variables from the accessory
|
|
14
|
+
this.name = accessory.displayName
|
|
15
|
+
this.accessory = accessory
|
|
16
|
+
|
|
17
|
+
// Set up custom variables for this device type
|
|
18
|
+
const deviceConf = platform.deviceConf[accessory.context.eweDeviceId] || {}
|
|
19
|
+
this.hideLongDouble = deviceConf.hideLongDouble
|
|
20
|
+
this.lowBattThreshold = deviceConf.lowBattThreshold
|
|
21
|
+
? Math.min(deviceConf.lowBattThreshold, 100)
|
|
22
|
+
: platformConsts.defaultValues.lowBattThreshold
|
|
23
|
+
this.sensorTimeDifference = deviceConf.sensorTimeDifference || platformConsts.defaultValues.sensorTimeDifference
|
|
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
|
+
// Add the stateless switch service if it doesn't already exist
|
|
46
|
+
this.service = this.accessory.getService(this.hapServ.StatelessProgrammableSwitch)
|
|
47
|
+
|| this.accessory.addService(this.hapServ.StatelessProgrammableSwitch)
|
|
48
|
+
|
|
49
|
+
// Hide the double and long press options if the user wants
|
|
50
|
+
if (this.hideLongDouble) {
|
|
51
|
+
this.service.getCharacteristic(this.hapChar.ProgrammableSwitchEvent).setProps({
|
|
52
|
+
validValues: [0],
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Add the battery service if it doesn't already exist
|
|
57
|
+
this.battService = this.accessory.getService(this.hapServ.Battery)
|
|
58
|
+
|| this.accessory.addService(this.hapServ.Battery)
|
|
59
|
+
|
|
60
|
+
// Output the customised options to the log
|
|
61
|
+
const normalLogging = this.enableLogging ? 'standard' : 'disable'
|
|
62
|
+
const opts = JSON.stringify({
|
|
63
|
+
hideLongDouble: this.hideLongDouble,
|
|
64
|
+
logging: this.enableDebugLogging ? 'debug' : normalLogging,
|
|
65
|
+
lowBattThreshold: this.lowBattThreshold,
|
|
66
|
+
sensorTimeDifference: this.sensorTimeDifference,
|
|
67
|
+
})
|
|
68
|
+
this.log('[%s] %s %s.', this.name, this.lang.devInitOpts, opts)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async externalUpdate(params) {
|
|
72
|
+
try {
|
|
73
|
+
if (hasProperty(params, 'battery') && params.battery !== this.cacheBatt) {
|
|
74
|
+
this.cacheBatt = params.battery
|
|
75
|
+
this.cacheBattScaled = Math.max(Math.min(this.cacheBatt, 100), 0)
|
|
76
|
+
this.battService.updateCharacteristic(this.hapChar.BatteryLevel, this.cacheBattScaled)
|
|
77
|
+
this.battService.updateCharacteristic(
|
|
78
|
+
this.hapChar.StatusLowBattery,
|
|
79
|
+
this.cacheBattScaled < this.lowBattThreshold ? 1 : 0,
|
|
80
|
+
)
|
|
81
|
+
if (params.updateSource && this.enableLogging) {
|
|
82
|
+
this.log('[%s] %s [%s%].', this.name, this.lang.curBatt, this.cacheBattScaled)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (
|
|
86
|
+
hasProperty(params, 'key')
|
|
87
|
+
&& [0, 1, 2].includes(params.key)
|
|
88
|
+
&& params.trigTime
|
|
89
|
+
) {
|
|
90
|
+
const timeDiff = (new Date().getTime() - params.trigTime) / 1000
|
|
91
|
+
if (timeDiff < this.sensorTimeDifference) {
|
|
92
|
+
this.service.updateCharacteristic(this.hapChar.ProgrammableSwitchEvent, params.key)
|
|
93
|
+
if (params.updateSource && this.enableLogging) {
|
|
94
|
+
const doubleLong = params.key === 1 ? this.lang.buttonDouble : this.lang.buttonLong
|
|
95
|
+
const textLabel = params.key === 0 ? this.lang.buttonSingle : doubleLong
|
|
96
|
+
this.log('[%s] %s [%s].', this.name, this.lang.curState, textLabel)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
this.platform.deviceUpdateError(this.accessory, err, false)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|