From 1eab7e8c98a6ca11dbbd5763f57437d9e759517b Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 10 Apr 2022 13:28:55 +0200 Subject: [PATCH 1/2] Dependencies update, linting and fix for deprecations - Updated dependencies: hap-nodejs from `0.4.52` to `0.10.0` - Updated devDependencies: xo from `0.24.0` to `0.48.0` - Disabled xo linter rules: `unicorn/prefer-module`, `unicorn/numeric-separators-style`, `import/extensions` - Fixed linter issues, but still 4 Todos left - Fixed deprecated: manuall initialization of HAP and moved to directly set HAPStorage.setCustomStoragePath - Fixed deprecated: `BatteryService` replaced by `Battery` - Fixed deprecated: `Slat` replaced by `Slats` - Fixed deprecated: `Accessory.Categories` by `Categories` Enum --- create-todo.js | 10 +- homematic-devices/hb-lc-bl1pbu-fm.js | 2 +- homematic-devices/hb-lc-sw1pbu-fm.js | 2 +- homematic-devices/hb-lc-sw2-fm.js | 2 +- homematic-devices/hb-lc-sw2pbu-fm.js | 2 +- homematic-devices/hb-uni-dmx-master.js | 6 +- homematic-devices/hb-uni-rgb-led-ctrl.js | 2 +- homematic-devices/hb-uni-sen-press-sc.js | 10 +- homematic-devices/hb-uni-sen-temp-ds18b20.js | 7 +- homematic-devices/hb-uni-sen-temp-ir.js | 7 +- homematic-devices/hb-uni-sen-wea.js | 2 +- homematic-devices/hb-uni-senact-4-4-rc-bat.js | 12 +- homematic-devices/hb-uni-senact-4-4-rc.js | 2 +- homematic-devices/hb-uni-senact-4-4-sc-bat.js | 16 +-- homematic-devices/hb-uni-senact-4-4-sc.js | 6 +- homematic-devices/hb-uni-senact-8-8-rc-bat.js | 12 +- homematic-devices/hb-uni-senact-8-8-rc.js | 2 +- homematic-devices/hb-uni-senact-8-8-sc-bat.js | 16 +-- homematic-devices/hb-uni-senact-8-8-sc.js | 6 +- homematic-devices/hm-cc-rt-dn-bom.js | 2 +- homematic-devices/hm-cc-rt-dn.js | 12 +- homematic-devices/hm-cc-scd.js | 6 +- homematic-devices/hm-cc-tc.js | 16 +-- homematic-devices/hm-cc-vg-1.js | 52 ++++----- homematic-devices/hm-dw-wm.js | 2 +- homematic-devices/hm-es-pmsw1-dr.js | 2 +- homematic-devices/hm-es-pmsw1-pl-dn-r1.js | 2 +- homematic-devices/hm-es-pmsw1-pl.js | 12 +- homematic-devices/hm-es-pmsw1-sm.js | 2 +- homematic-devices/hm-lc-ao-sm.js | 2 +- homematic-devices/hm-lc-bl1-fm-2.js | 2 +- homematic-devices/hm-lc-bl1-fm.js | 8 +- homematic-devices/hm-lc-bl1-pb-fm.js | 2 +- homematic-devices/hm-lc-bl1-sm-2.js | 2 +- homematic-devices/hm-lc-bl1-sm.js | 2 +- homematic-devices/hm-lc-bl1pbu-fm.js | 2 +- homematic-devices/hm-lc-dim1l-cv-2.js | 2 +- homematic-devices/hm-lc-dim1l-cv.js | 8 +- homematic-devices/hm-lc-dim1l-pl-2.js | 2 +- homematic-devices/hm-lc-dim1l-pl-3.js | 2 +- homematic-devices/hm-lc-dim1l-pl.js | 2 +- homematic-devices/hm-lc-dim1pwm-cv-2.js | 2 +- homematic-devices/hm-lc-dim1pwm-cv.js | 2 +- homematic-devices/hm-lc-dim1t-cv-2.js | 2 +- homematic-devices/hm-lc-dim1t-cv.js | 2 +- homematic-devices/hm-lc-dim1t-dr.js | 2 +- homematic-devices/hm-lc-dim1t-fm-2.js | 2 +- homematic-devices/hm-lc-dim1t-fm-lf.js | 2 +- homematic-devices/hm-lc-dim1t-fm.js | 2 +- homematic-devices/hm-lc-dim1t-pl-2.js | 2 +- homematic-devices/hm-lc-dim1t-pl-3.js | 2 +- homematic-devices/hm-lc-dim1t-pl.js | 2 +- homematic-devices/hm-lc-dim1tpbu-fm-2.js | 2 +- homematic-devices/hm-lc-dim1tpbu-fm.js | 2 +- homematic-devices/hm-lc-dim2l-sm-2.js | 2 +- homematic-devices/hm-lc-dim2l-sm.js | 8 +- homematic-devices/hm-lc-dim2t-sm-2.js | 2 +- homematic-devices/hm-lc-dim2t-sm.js | 2 +- homematic-devices/hm-lc-ja1pbu-fm.js | 23 +--- homematic-devices/hm-lc-rgbw-wm.js | 2 +- homematic-devices/hm-lc-sw1-ba-pcb.js | 12 +- homematic-devices/hm-lc-sw1-dr.js | 2 +- homematic-devices/hm-lc-sw1-fm-2.js | 2 +- homematic-devices/hm-lc-sw1-fm.js | 2 +- homematic-devices/hm-lc-sw1-pb-fm.js | 2 +- homematic-devices/hm-lc-sw1-pcb.js | 2 +- homematic-devices/hm-lc-sw1-pl-2.js | 2 +- homematic-devices/hm-lc-sw1-pl-3.js | 2 +- homematic-devices/hm-lc-sw1-pl-ct-r1.js | 2 +- homematic-devices/hm-lc-sw1-pl-ct-r2.js | 2 +- homematic-devices/hm-lc-sw1-pl-ct-r3.js | 2 +- homematic-devices/hm-lc-sw1-pl-ct-r4.js | 2 +- homematic-devices/hm-lc-sw1-pl-ct-r5.js | 2 +- homematic-devices/hm-lc-sw1-pl-dn-r1.js | 2 +- homematic-devices/hm-lc-sw1-pl-dn-r2.js | 2 +- homematic-devices/hm-lc-sw1-pl-dn-r3.js | 2 +- homematic-devices/hm-lc-sw1-pl-dn-r4.js | 2 +- homematic-devices/hm-lc-sw1-pl-dn-r5.js | 2 +- homematic-devices/hm-lc-sw1-pl-om54.js | 2 +- homematic-devices/hm-lc-sw1-pl.js | 2 +- homematic-devices/hm-lc-sw1-sm-2.js | 2 +- homematic-devices/hm-lc-sw1-sm.js | 2 +- homematic-devices/hm-lc-sw1pbu-fm.js | 2 +- homematic-devices/hm-lc-sw2-dr-2.js | 2 +- homematic-devices/hm-lc-sw2-dr.js | 2 +- homematic-devices/hm-lc-sw2-fm-2.js | 2 +- homematic-devices/hm-lc-sw2-fm.js | 2 +- homematic-devices/hm-lc-sw2-pb-fm.js | 2 +- homematic-devices/hm-lc-sw2pbu-fm.js | 2 +- homematic-devices/hm-lc-sw4-ba-pcb.js | 2 +- homematic-devices/hm-lc-sw4-dr-2.js | 2 +- homematic-devices/hm-lc-sw4-dr.js | 2 +- homematic-devices/hm-lc-sw4-pcb-2.js | 2 +- homematic-devices/hm-lc-sw4-pcb.js | 2 +- homematic-devices/hm-lc-sw4-sm-2.js | 2 +- homematic-devices/hm-lc-sw4-sm.js | 2 +- homematic-devices/hm-lc-sw4-wm-2.js | 2 +- homematic-devices/hm-lc-sw4-wm.js | 2 +- homematic-devices/hm-mod-re-8.js | 2 +- homematic-devices/hm-sci-3-fm.js | 20 +--- homematic-devices/hm-sec-key-o.js | 2 +- homematic-devices/hm-sec-key-s.js | 2 +- homematic-devices/hm-sec-key.js | 12 +- homematic-devices/hm-sec-mdir-2.js | 2 +- homematic-devices/hm-sec-mdir-3.js | 2 +- homematic-devices/hm-sec-mdir.js | 18 +-- homematic-devices/hm-sec-rhs-2.js | 2 +- homematic-devices/hm-sec-rhs.js | 34 ++---- homematic-devices/hm-sec-sc-2.js | 2 +- homematic-devices/hm-sec-sc.js | 34 ++---- homematic-devices/hm-sec-sco.js | 2 +- homematic-devices/hm-sec-sd-2.js | 2 +- homematic-devices/hm-sec-sd.js | 13 +-- homematic-devices/hm-sec-sir-wm.js | 58 +++++----- homematic-devices/hm-sec-tis.js | 21 +--- homematic-devices/hm-sec-wds-2.js | 2 +- homematic-devices/hm-sec-wds.js | 10 +- homematic-devices/hm-sec-win.js | 24 ++-- homematic-devices/hm-sen-db-pcb.js | 2 +- homematic-devices/hm-sen-li-o.js | 6 +- homematic-devices/hm-sen-mdir-o-2.js | 2 +- homematic-devices/hm-sen-mdir-o-3.js | 2 +- homematic-devices/hm-sen-mdir-o.js | 2 +- homematic-devices/hm-sen-mdir-sm.js | 2 +- homematic-devices/hm-sen-mdir-wm55.js | 10 +- homematic-devices/hm-tc-it-wm-w-eu.js | 44 ++++--- homematic-devices/hm-wds10-th-o.js | 12 +- homematic-devices/hm-wds100-c6-o-2.js | 2 +- homematic-devices/hm-wds100-c6-o.js | 14 +-- homematic-devices/hm-wds20-th-o.js | 2 +- homematic-devices/hm-wds30-ot2-sm-2.js | 2 +- homematic-devices/hm-wds30-ot2-sm.js | 6 +- homematic-devices/hm-wds30-t-o.js | 7 +- homematic-devices/hm-wds40-th-i-2.js | 2 +- homematic-devices/hm-wds40-th-i.js | 2 +- homematic-devices/hm-ws550st-io.js | 2 +- homematic-devices/hm-ws550sth-i.js | 12 +- homematic-devices/hm-ws550sth-o.js | 2 +- homematic-devices/hmip-bbl.js | 2 +- homematic-devices/hmip-bdt.js | 8 +- homematic-devices/hmip-broll.js | 2 +- homematic-devices/hmip-bsl.js | 2 +- homematic-devices/hmip-bsm.js | 2 +- homematic-devices/hmip-bwth.js | 18 +-- homematic-devices/hmip-bwth24.js | 2 +- homematic-devices/hmip-dbb.js | 8 +- homematic-devices/hmip-drbli4.js | 2 +- homematic-devices/hmip-drsi1.js | 24 ++-- homematic-devices/hmip-drsi4.js | 24 ++-- homematic-devices/hmip-etrv-2.js | 2 +- homematic-devices/hmip-etrv-b.js | 2 +- homematic-devices/hmip-etrv-b1.js | 2 +- homematic-devices/hmip-etrv-c.js | 2 +- homematic-devices/hmip-etrv.js | 16 ++- homematic-devices/hmip-fbl.js | 2 +- homematic-devices/hmip-fci1.js | 12 +- homematic-devices/hmip-fdt.js | 8 +- homematic-devices/hmip-froll.js | 2 +- homematic-devices/hmip-fsi16.js | 2 +- homematic-devices/hmip-fsm.js | 12 +- homematic-devices/hmip-fsm16.js | 2 +- homematic-devices/hmip-heating.js | 46 ++++---- homematic-devices/hmip-mod-ho.js | 2 +- homematic-devices/hmip-mod-oc8.js | 26 ++--- homematic-devices/hmip-mod-tm.js | 2 +- homematic-devices/hmip-pcbs-bat.js | 8 +- homematic-devices/hmip-pcbs.js | 2 +- homematic-devices/hmip-pcbs2.js | 2 +- homematic-devices/hmip-pdt.js | 8 +- homematic-devices/hmip-ps.js | 12 +- homematic-devices/hmip-psm-ch.js | 2 +- homematic-devices/hmip-psm-it.js | 2 +- homematic-devices/hmip-psm-pe.js | 2 +- homematic-devices/hmip-psm-uk.js | 2 +- homematic-devices/hmip-psm.js | 12 +- homematic-devices/hmip-sam.js | 27 ++--- homematic-devices/hmip-sci.js | 27 ++--- homematic-devices/hmip-slo.js | 8 +- homematic-devices/hmip-smi.js | 8 +- homematic-devices/hmip-smi55.js | 8 +- homematic-devices/hmip-smo-a.js | 2 +- homematic-devices/hmip-smo.js | 2 +- homematic-devices/hmip-spdr.js | 8 +- homematic-devices/hmip-spi.js | 8 +- homematic-devices/hmip-srh.js | 27 ++--- homematic-devices/hmip-ste2-pcb.js | 6 +- homematic-devices/hmip-sth.js | 43 ++++--- homematic-devices/hmip-sthd.js | 2 +- homematic-devices/hmip-stho-a.js | 2 +- homematic-devices/hmip-stho.js | 8 +- homematic-devices/hmip-swd.js | 12 +- homematic-devices/hmip-swdm-b.js | 2 +- homematic-devices/hmip-swdm-b1.js | 2 +- homematic-devices/hmip-swdm-b2.js | 2 +- homematic-devices/hmip-swdm.js | 2 +- homematic-devices/hmip-swdo-i.js | 2 +- homematic-devices/hmip-swdo-pl.js | 27 ++--- homematic-devices/hmip-swdo.js | 27 ++--- homematic-devices/hmip-swo-b.js | 12 +- homematic-devices/hmip-swo-pl.js | 2 +- homematic-devices/hmip-swo-pr.js | 2 +- homematic-devices/hmip-swsd.js | 16 +-- homematic-devices/hmip-whs2.js | 2 +- homematic-devices/hmip-wth-2.js | 2 +- homematic-devices/hmip-wth-b.js | 2 +- homematic-devices/hmip-wth.js | 45 ++++---- homematic-devices/hmipw-drbl4.js | 2 +- homematic-devices/hmipw-drd3.js | 8 +- homematic-devices/hmipw-dri16.js | 18 +-- homematic-devices/hmipw-dri32.js | 2 +- homematic-devices/hmipw-drs4.js | 24 ++-- homematic-devices/hmipw-drs8.js | 2 +- homematic-devices/hmipw-fio6.js | 28 ++--- homematic-devices/hmipw-smi55.js | 2 +- homematic-devices/hmipw-wth.js | 2 +- homematic-devices/hmw-io-12-sw7-dr.js | 2 +- homematic-devices/hmw-lc-bl1-dr-2.js | 2 +- homematic-devices/hmw-lc-bl1-dr.js | 16 +-- homematic-devices/hmw-lc-dim1l-dr.js | 2 +- homematic-devices/hmw-lc-sw2-dr.js | 2 +- homematic-devices/hmw-sen-sc-12-dr.js | 6 +- homematic-devices/hmw-sen-sc-12-fm.js | 2 +- homematic-devices/lib/accessory.js | 60 +++++----- homematic-devices/lib/generic-hmip-blind.js | 47 ++++---- homematic-devices/lib/generic-switch.js | 12 +- homematic-devices/zel_stg_rm_fep_230v.js | 2 +- homematic-devices/zel_stg_rm_ffk.js | 2 +- nodes/redmatic-homekit-bridge.js | 28 ++--- nodes/redmatic-homekit-camera.js | 43 ++++--- nodes/redmatic-homekit-homematic-devices.js | 56 ++++----- nodes/redmatic-homekit-homematic-garage.js | 29 ++--- .../redmatic-homekit-homematic-irrigation.js | 108 +++++++++--------- nodes/redmatic-homekit-pseudobutton.js | 26 ++--- ...tic-homekit-statelessprogrammableswitch.js | 21 ++-- nodes/redmatic-homekit-switch.js | 4 +- nodes/redmatic-homekit-tv.js | 102 ++++++++--------- nodes/redmatic-homekit-universal.html | 4 +- nodes/redmatic-homekit-universal.js | 49 ++++---- nodes/redmatic-homekit-zigbee-devices.js | 30 +++-- package.json | 8 +- zigbee-devices/lib/accessory.js | 43 +++---- zigbee-devices/lumi.sensor_magnet.js | 8 +- zigbee-devices/lumi.sensor_motion.js | 12 +- zigbee-devices/lumi.sensor_wleak.js | 8 +- zigbee-devices/lumi.weather.js | 8 +- zigbee-devices/tradfri.controlOutlet.js | 6 +- zigbee-devices/windowcovering.js | 8 +- zigbee-devices/zll.color.js | 12 +- zigbee-devices/zll.dim.js | 12 +- zigbee-devices/zll.extendedcolor.js | 10 +- zigbee-devices/zll.onoff.js | 6 +- zigbee-devices/zll.tw.js | 16 +-- 252 files changed, 984 insertions(+), 1365 deletions(-) diff --git a/create-todo.js b/create-todo.js index 25bea6e..1e46bcb 100644 --- a/create-todo.js +++ b/create-todo.js @@ -2,11 +2,11 @@ const fs = require('fs'); const dir = fs.readdirSync('./homematic-devices'); -dir.forEach(file => { - if (file.match(/h.*-.*\.js/)) { - const len = fs.readFileSync('./homematic-devices/' + file).toString().split('\n').length; - if (len > 4) { +for (const file of dir) { + if (/h.*-.*\.js/.test(file)) { + const {length} = fs.readFileSync('./homematic-devices/' + file).toString().split('\n'); + if (length > 4) { console.log('- [ ] ' + file.replace('.js', '')); } } -}); +} diff --git a/homematic-devices/hb-lc-bl1pbu-fm.js b/homematic-devices/hb-lc-bl1pbu-fm.js index 3596056..cceca1e 100644 --- a/homematic-devices/hb-lc-bl1pbu-fm.js +++ b/homematic-devices/hb-lc-bl1pbu-fm.js @@ -1 +1 @@ -module.exports = require('./hm-lc-bl1pbu-fm'); +module.exports = require('./hm-lc-bl1pbu-fm.js'); diff --git a/homematic-devices/hb-lc-sw1pbu-fm.js b/homematic-devices/hb-lc-sw1pbu-fm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hb-lc-sw1pbu-fm.js +++ b/homematic-devices/hb-lc-sw1pbu-fm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hb-lc-sw2-fm.js b/homematic-devices/hb-lc-sw2-fm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hb-lc-sw2-fm.js +++ b/homematic-devices/hb-lc-sw2-fm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hb-lc-sw2pbu-fm.js b/homematic-devices/hb-lc-sw2pbu-fm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hb-lc-sw2pbu-fm.js +++ b/homematic-devices/hb-lc-sw2pbu-fm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hb-uni-dmx-master.js b/homematic-devices/hb-uni-dmx-master.js index a7facfd..5df9981 100644 --- a/homematic-devices/hb-uni-dmx-master.js +++ b/homematic-devices/hb-uni-dmx-master.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmUniDmx extends Accessory { init(config, node) { @@ -13,9 +13,7 @@ module.exports = class HmUniDmx extends Accessory { const ch = config.description.ADDRESS + ':' + i; const service = this.addService('Switch', ccu.channelNames[ch]); - service.get('On', () => { - return false; - }); + service.get('On', () => false); service.set('On', (value, callback) => { if (value) { ccu.setValue(config.iface, ch, 'PRESS_SHORT', true) diff --git a/homematic-devices/hb-uni-rgb-led-ctrl.js b/homematic-devices/hb-uni-rgb-led-ctrl.js index 26a1146..391c122 100644 --- a/homematic-devices/hb-uni-rgb-led-ctrl.js +++ b/homematic-devices/hb-uni-rgb-led-ctrl.js @@ -1 +1 @@ -module.exports = require('./hm-lc-rgbw-wm'); +module.exports = require('./hm-lc-rgbw-wm.js'); diff --git a/homematic-devices/hb-uni-sen-press-sc.js b/homematic-devices/hb-uni-sen-press-sc.js index 7218dc3..ec8067c 100644 --- a/homematic-devices/hb-uni-sen-press-sc.js +++ b/homematic-devices/hb-uni-sen-press-sc.js @@ -1,14 +1,10 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenPress extends Accessory { init(config) { this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':2.STATE', (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) + .get('ContactSensorState', config.deviceAddress + ':2.STATE', (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } }; diff --git a/homematic-devices/hb-uni-sen-temp-ds18b20.js b/homematic-devices/hb-uni-sen-temp-ds18b20.js index 069a57d..e3e323b 100644 --- a/homematic-devices/hb-uni-sen-temp-ds18b20.js +++ b/homematic-devices/hb-uni-sen-temp-ds18b20.js @@ -1,5 +1,6 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); +// eslint-disable-next-line unicorn/prevent-abbreviations module.exports = class HbUniSenTemp extends Accessory { init(config, node) { const {ccu} = node; @@ -17,9 +18,7 @@ module.exports = class HbUniSenTemp extends Accessory { this.addService('TemperatureSensor', name) .setProps('CurrentTemperature', {minValue: -150, maxValue: 150}) .get('CurrentTemperature', dp) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hb-uni-sen-temp-ir.js b/homematic-devices/hb-uni-sen-temp-ir.js index a5bfe9b..7caaa5e 100644 --- a/homematic-devices/hb-uni-sen-temp-ir.js +++ b/homematic-devices/hb-uni-sen-temp-ir.js @@ -1,5 +1,6 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); +// eslint-disable-next-line unicorn/prevent-abbreviations module.exports = class HbUniSenTemp extends Accessory { init(config, node) { const {ccu} = node; @@ -18,9 +19,7 @@ module.exports = class HbUniSenTemp extends Accessory { this.addService('TemperatureSensor', name) .setProps('CurrentTemperature', {minValue: -450, maxValue: 450}) .get('CurrentTemperature', dp) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hb-uni-sen-wea.js b/homematic-devices/hb-uni-sen-wea.js index 6751301..5b31a66 100644 --- a/homematic-devices/hb-uni-sen-wea.js +++ b/homematic-devices/hb-uni-sen-wea.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenWea extends Accessory { init(config) { diff --git a/homematic-devices/hb-uni-senact-4-4-rc-bat.js b/homematic-devices/hb-uni-senact-4-4-rc-bat.js index 5462dc1..6c839c6 100644 --- a/homematic-devices/hb-uni-senact-4-4-rc-bat.js +++ b/homematic-devices/hb-uni-senact-4-4-rc-bat.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenAct extends Accessory { init(config, node) { @@ -19,13 +19,9 @@ module.exports = class HbUniSenAct extends Accessory { .set('On', dp); } - this.addService('BatteryService') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery') + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); } }; diff --git a/homematic-devices/hb-uni-senact-4-4-rc.js b/homematic-devices/hb-uni-senact-4-4-rc.js index 26cbc14..aebc482 100644 --- a/homematic-devices/hb-uni-senact-4-4-rc.js +++ b/homematic-devices/hb-uni-senact-4-4-rc.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenAct extends Accessory { init(config, node) { diff --git a/homematic-devices/hb-uni-senact-4-4-sc-bat.js b/homematic-devices/hb-uni-senact-4-4-sc-bat.js index 54dff49..7c451f7 100644 --- a/homematic-devices/hb-uni-senact-4-4-sc-bat.js +++ b/homematic-devices/hb-uni-senact-4-4-sc-bat.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenAct extends Accessory { init(config, node) { @@ -28,18 +28,12 @@ module.exports = class HbUniSenAct extends Accessory { const dp = config.iface + '.' + channels[i] + '.STATE'; this.addService('ContactSensor', name) - .get('ContactSensorState', dp, (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }); + .get('ContactSensorState', dp, (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED); } - this.addService('BatteryService') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery') + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); } }; diff --git a/homematic-devices/hb-uni-senact-4-4-sc.js b/homematic-devices/hb-uni-senact-4-4-sc.js index 02486b4..6fc8073 100644 --- a/homematic-devices/hb-uni-senact-4-4-sc.js +++ b/homematic-devices/hb-uni-senact-4-4-sc.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenAct extends Accessory { init(config, node) { @@ -28,9 +28,7 @@ module.exports = class HbUniSenAct extends Accessory { const dp = config.iface + '.' + channels[i] + '.STATE'; this.addService('ContactSensor', name) - .get('ContactSensorState', dp, (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }); + .get('ContactSensorState', dp, (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED); } } }; diff --git a/homematic-devices/hb-uni-senact-8-8-rc-bat.js b/homematic-devices/hb-uni-senact-8-8-rc-bat.js index 6f8c451..6eaddd5 100644 --- a/homematic-devices/hb-uni-senact-8-8-rc-bat.js +++ b/homematic-devices/hb-uni-senact-8-8-rc-bat.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenAct extends Accessory { init(config, node) { @@ -19,13 +19,9 @@ module.exports = class HbUniSenAct extends Accessory { .set('On', dp); } - this.addService('BatteryService') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery') + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); } }; diff --git a/homematic-devices/hb-uni-senact-8-8-rc.js b/homematic-devices/hb-uni-senact-8-8-rc.js index 87429d5..140cbfe 100644 --- a/homematic-devices/hb-uni-senact-8-8-rc.js +++ b/homematic-devices/hb-uni-senact-8-8-rc.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenAct extends Accessory { init(config, node) { diff --git a/homematic-devices/hb-uni-senact-8-8-sc-bat.js b/homematic-devices/hb-uni-senact-8-8-sc-bat.js index 25f80bc..d6dd11d 100644 --- a/homematic-devices/hb-uni-senact-8-8-sc-bat.js +++ b/homematic-devices/hb-uni-senact-8-8-sc-bat.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenAct extends Accessory { init(config, node) { @@ -28,18 +28,12 @@ module.exports = class HbUniSenAct extends Accessory { const dp = config.iface + '.' + channels[i] + '.STATE'; this.addService('ContactSensor', name) - .get('ContactSensorState', dp, (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }); + .get('ContactSensorState', dp, (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED); } - this.addService('BatteryService') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery') + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); } }; diff --git a/homematic-devices/hb-uni-senact-8-8-sc.js b/homematic-devices/hb-uni-senact-8-8-sc.js index 000d869..591cf1f 100644 --- a/homematic-devices/hb-uni-senact-8-8-sc.js +++ b/homematic-devices/hb-uni-senact-8-8-sc.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HbUniSenAct extends Accessory { init(config, node) { @@ -28,9 +28,7 @@ module.exports = class HbUniSenAct extends Accessory { const dp = config.iface + '.' + channels[i] + '.STATE'; this.addService('ContactSensor', name) - .get('ContactSensorState', dp, (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }); + .get('ContactSensorState', dp, (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED); } } }; diff --git a/homematic-devices/hm-cc-rt-dn-bom.js b/homematic-devices/hm-cc-rt-dn-bom.js index 827faa7..d3e555d 100644 --- a/homematic-devices/hm-cc-rt-dn-bom.js +++ b/homematic-devices/hm-cc-rt-dn-bom.js @@ -1 +1 @@ -module.exports = require('./hm-cc-rt-dn'); +module.exports = require('./hm-cc-rt-dn.js'); diff --git a/homematic-devices/hm-cc-rt-dn.js b/homematic-devices/hm-cc-rt-dn.js index 7110ffb..b507f96 100644 --- a/homematic-devices/hm-cc-rt-dn.js +++ b/homematic-devices/hm-cc-rt-dn.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmCcRtDn extends Accessory { init(config, node) { @@ -121,10 +121,8 @@ module.exports = class HmCcRtDn extends Accessory { updateHeatingCoolingState(); }); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':4.BATTERY_STATE', this.percent) .update('ChargingState', 2); @@ -165,9 +163,7 @@ module.exports = class HmCcRtDn extends Accessory { }); } }) - .get('On', config.deviceAddress + ':4.CONTROL_MODE', value => { - return value === 3; - }); + .get('On', config.deviceAddress + ':4.CONTROL_MODE', value => value === 3); } } }; diff --git a/homematic-devices/hm-cc-scd.js b/homematic-devices/hm-cc-scd.js index a6c4d0b..5a9a6bc 100644 --- a/homematic-devices/hm-cc-scd.js +++ b/homematic-devices/hm-cc-scd.js @@ -1,10 +1,8 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmCcScd extends Accessory { init(config) { this.addService('CarbonDioxideSensor', config.name) - .get('CarbonDioxideDetected', config.deviceAddress + ':1.STATE', (value, c) => { - return value > 0 ? c.CO2_LEVELS_ABNORMAL : c.CO2_LEVELS_NORMAL; - }); + .get('CarbonDioxideDetected', config.deviceAddress + ':1.STATE', (value, c) => value > 0 ? c.CO2_LEVELS_ABNORMAL : c.CO2_LEVELS_NORMAL); } }; diff --git a/homematic-devices/hm-cc-tc.js b/homematic-devices/hm-cc-tc.js index 850a7f5..7c13e67 100644 --- a/homematic-devices/hm-cc-tc.js +++ b/homematic-devices/hm-cc-tc.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmCcTc extends Accessory { init(config, node) { @@ -71,22 +71,16 @@ module.exports = class HmCcTc extends Accessory { }); } - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); if (this.option('HumiditySensor')) { this.addService('HumiditySensor', config.name) .get('CurrentRelativeHumidity', config.deviceAddress + ':1.HUMIDITY') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hm-cc-vg-1.js b/homematic-devices/hm-cc-vg-1.js index c145a18..9484b4a 100644 --- a/homematic-devices/hm-cc-vg-1.js +++ b/homematic-devices/hm-cc-vg-1.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmCcVg1 extends Accessory { init(config, node) { @@ -14,8 +14,6 @@ module.exports = class HmCcVg1 extends Accessory { const levels = {}; let level = 0; - const that = this; - const valveDevices = []; const lowbatDps = {}; @@ -31,7 +29,7 @@ module.exports = class HmCcVg1 extends Accessory { } node.debug(config.deviceAddress + ' ' + group.groupProperties.NAME + ' ' + group.groupType.id + ' has ' + group.groupMembers.length + ' members'); - group.groupMembers.forEach(member => { + for (const member of group.groupMembers) { if (member.memberType.id.startsWith('HM-CC')) { valveDevices.push('BidCos-RF.' + member.id); valueChannel = valueChannel || ('BidCos-RF.' + member.id + ':4'); @@ -42,7 +40,7 @@ module.exports = class HmCcVg1 extends Accessory { lowbatDps['BidCos-RF.' + member.id + ':0.LOWBAT'] = false; node.debug(config.deviceAddress + ' member ' + member.memberType.id + ' ' + member.id); - }); + } if (valueChannel) { node.debug(config.deviceAddress + ' valueChannel ' + valueChannel); @@ -151,52 +149,54 @@ module.exports = class HmCcVg1 extends Accessory { function updateHeatingCoolingState() { const current = currentState(); node.debug('update ' + config.name + ' (' + subtypeThermostat + ') CurrentHeatingCoolingState ' + current); - that.acc.getService(subtypeThermostat).updateCharacteristic(hap.Characteristic.CurrentHeatingCoolingState, current); + this.acc.getService(subtypeThermostat).updateCharacteristic(hap.Characteristic.CurrentHeatingCoolingState, current); const target = targetState(); node.debug('update ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + target); - that.acc.getService(subtypeThermostat).updateCharacteristic(hap.Characteristic.TargetHeatingCoolingState, target); + this.acc.getService(subtypeThermostat).updateCharacteristic(hap.Characteristic.TargetHeatingCoolingState, target); } - valveDevices.forEach(valveStateDevice => { + for (const valveStateDevice of valveDevices) { const datapointLevel = valveStateDevice + ':4.VALVE_STATE'; this.subscribe(datapointLevel, value => { levels[datapointLevel] = value; let max = 0; - Object.keys(levels).forEach(dp => { + for (const dp of Object.keys(levels)) { if (levels[dp] > max) { max = levels[dp]; } - }); + } + if (level !== max) { level = max; node.debug('update ' + config.name + ' level ' + level); updateHeatingCoolingState(); } }); - }); + } this.subscriptions.push(ccu.subscribe({ cache: true, change: true, - datapointName: valueChannel + '.CONTROL_MODE' - }, msg => { - controlMode = msg.value; - node.debug('update ' + config.name + ' controlMode ' + msg.value); + datapointName: valueChannel + '.CONTROL_MODE', + }, message => { + controlMode = message.value; + node.debug('update ' + config.name + ' controlMode ' + message.value); updateHeatingCoolingState(); })); - const batteryService = this.addService('BatteryService', config.name, 'Battery'); - Object.keys(lowbatDps).forEach(dp => { + const battery = this.addService('Battery', config.name, 'Battery'); + for (const dp of Object.keys(lowbatDps)) { this.subscribe(dp, value => { lowbatDps[dp] = value; let lowbat = false; - Object.keys(lowbatDps).forEach(ldp => { + for (const ldp of Object.keys(lowbatDps)) { lowbat = lowbat || lowbatDps[ldp]; - }); - batteryService.update('StatusLowBattery', lowbat ? hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); - batteryService.update('BatteryLevel', lowbat ? 0 : 100); + } + + battery.update('StatusLowBattery', lowbat ? hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + battery.update('BatteryLevel', lowbat ? 0 : 100); }); - }); + } if (this.option('HumiditySensor') && humidityDp) { this.addService('HumiditySensor', config.name, 'HumiditySensor') @@ -217,13 +217,11 @@ module.exports = class HmCcVg1 extends Accessory { value = true; } - this.ccuSetValue(config.iface + '.' + config.description.ADDRESS + ':1.' + dp, value, res => { - callback(res); + this.ccuSetValue(config.iface + '.' + config.description.ADDRESS + ':1.' + dp, value, response => { + callback(response); }); }) - .get('On', valueChannel + '.CONTROL_MODE', value => { - return value === 3; - }); + .get('On', valueChannel + '.CONTROL_MODE', value => value === 3); } } }; diff --git a/homematic-devices/hm-dw-wm.js b/homematic-devices/hm-dw-wm.js index acb45ef..b5ccd45 100644 --- a/homematic-devices/hm-dw-wm.js +++ b/homematic-devices/hm-dw-wm.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim2l-sm'); +module.exports = require('./hm-lc-dim2l-sm.js'); diff --git a/homematic-devices/hm-es-pmsw1-dr.js b/homematic-devices/hm-es-pmsw1-dr.js index 13d1344..9c00e67 100644 --- a/homematic-devices/hm-es-pmsw1-dr.js +++ b/homematic-devices/hm-es-pmsw1-dr.js @@ -1 +1 @@ -module.exports = require('./hm-es-pmsw1-pl'); +module.exports = require('./hm-es-pmsw1-pl.js'); diff --git a/homematic-devices/hm-es-pmsw1-pl-dn-r1.js b/homematic-devices/hm-es-pmsw1-pl-dn-r1.js index 13d1344..9c00e67 100644 --- a/homematic-devices/hm-es-pmsw1-pl-dn-r1.js +++ b/homematic-devices/hm-es-pmsw1-pl-dn-r1.js @@ -1 +1 @@ -module.exports = require('./hm-es-pmsw1-pl'); +module.exports = require('./hm-es-pmsw1-pl.js'); diff --git a/homematic-devices/hm-es-pmsw1-pl.js b/homematic-devices/hm-es-pmsw1-pl.js index b7e4f51..e582b3d 100644 --- a/homematic-devices/hm-es-pmsw1-pl.js +++ b/homematic-devices/hm-es-pmsw1-pl.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmEsPmsw1 extends Accessory { init(config, node) { @@ -16,11 +16,11 @@ module.exports = class HmEsPmsw1 extends Accessory { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } diff --git a/homematic-devices/hm-es-pmsw1-sm.js b/homematic-devices/hm-es-pmsw1-sm.js index 13d1344..9c00e67 100644 --- a/homematic-devices/hm-es-pmsw1-sm.js +++ b/homematic-devices/hm-es-pmsw1-sm.js @@ -1 +1 @@ -module.exports = require('./hm-es-pmsw1-pl'); +module.exports = require('./hm-es-pmsw1-pl.js'); diff --git a/homematic-devices/hm-lc-ao-sm.js b/homematic-devices/hm-lc-ao-sm.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-ao-sm.js +++ b/homematic-devices/hm-lc-ao-sm.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-bl1-fm-2.js b/homematic-devices/hm-lc-bl1-fm-2.js index 36ab5d7..4d02675 100644 --- a/homematic-devices/hm-lc-bl1-fm-2.js +++ b/homematic-devices/hm-lc-bl1-fm-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-bl1-fm'); +module.exports = require('./hm-lc-bl1-fm.js'); diff --git a/homematic-devices/hm-lc-bl1-fm.js b/homematic-devices/hm-lc-bl1-fm.js index f32dc45..4a50f4b 100644 --- a/homematic-devices/hm-lc-bl1-fm.js +++ b/homematic-devices/hm-lc-bl1-fm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmLcBl1 extends Accessory { init(config, node) { @@ -10,9 +10,9 @@ module.exports = class HmLcBl1 extends Accessory { ccu.subscribe({ datapointName: config.deviceAddress + ':1.LEVEL', cache: true, - stable: false - }, msg => { - intermediatePosition = msg.value * 100; + stable: false, + }, message => { + intermediatePosition = message.value * 100; }); const service = this.addService('WindowCovering', config.name); diff --git a/homematic-devices/hm-lc-bl1-pb-fm.js b/homematic-devices/hm-lc-bl1-pb-fm.js index 36ab5d7..4d02675 100644 --- a/homematic-devices/hm-lc-bl1-pb-fm.js +++ b/homematic-devices/hm-lc-bl1-pb-fm.js @@ -1 +1 @@ -module.exports = require('./hm-lc-bl1-fm'); +module.exports = require('./hm-lc-bl1-fm.js'); diff --git a/homematic-devices/hm-lc-bl1-sm-2.js b/homematic-devices/hm-lc-bl1-sm-2.js index 36ab5d7..4d02675 100644 --- a/homematic-devices/hm-lc-bl1-sm-2.js +++ b/homematic-devices/hm-lc-bl1-sm-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-bl1-fm'); +module.exports = require('./hm-lc-bl1-fm.js'); diff --git a/homematic-devices/hm-lc-bl1-sm.js b/homematic-devices/hm-lc-bl1-sm.js index 36ab5d7..4d02675 100644 --- a/homematic-devices/hm-lc-bl1-sm.js +++ b/homematic-devices/hm-lc-bl1-sm.js @@ -1 +1 @@ -module.exports = require('./hm-lc-bl1-fm'); +module.exports = require('./hm-lc-bl1-fm.js'); diff --git a/homematic-devices/hm-lc-bl1pbu-fm.js b/homematic-devices/hm-lc-bl1pbu-fm.js index 36ab5d7..4d02675 100644 --- a/homematic-devices/hm-lc-bl1pbu-fm.js +++ b/homematic-devices/hm-lc-bl1pbu-fm.js @@ -1 +1 @@ -module.exports = require('./hm-lc-bl1-fm'); +module.exports = require('./hm-lc-bl1-fm.js'); diff --git a/homematic-devices/hm-lc-dim1l-cv-2.js b/homematic-devices/hm-lc-dim1l-cv-2.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1l-cv-2.js +++ b/homematic-devices/hm-lc-dim1l-cv-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1l-cv.js b/homematic-devices/hm-lc-dim1l-cv.js index 1fd32e7..edc901f 100644 --- a/homematic-devices/hm-lc-dim1l-cv.js +++ b/homematic-devices/hm-lc-dim1l-cv.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmLcDim extends Accessory { init(config) { @@ -14,11 +14,7 @@ module.exports = class HmLcDim extends Accessory { .set('On', (value, callback) => { if (value) { setTimeout(() => { - if (valueBrightness === 0) { - value = 1; - } else { - value = valueBrightness / 100; - } + value = valueBrightness === 0 ? 1 : valueBrightness / 100; this.ccuSetValue(config.deviceAddress + ':1.LEVEL', value, callback); }, 100); diff --git a/homematic-devices/hm-lc-dim1l-pl-2.js b/homematic-devices/hm-lc-dim1l-pl-2.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1l-pl-2.js +++ b/homematic-devices/hm-lc-dim1l-pl-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1l-pl-3.js b/homematic-devices/hm-lc-dim1l-pl-3.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1l-pl-3.js +++ b/homematic-devices/hm-lc-dim1l-pl-3.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1l-pl.js b/homematic-devices/hm-lc-dim1l-pl.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1l-pl.js +++ b/homematic-devices/hm-lc-dim1l-pl.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1pwm-cv-2.js b/homematic-devices/hm-lc-dim1pwm-cv-2.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1pwm-cv-2.js +++ b/homematic-devices/hm-lc-dim1pwm-cv-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1pwm-cv.js b/homematic-devices/hm-lc-dim1pwm-cv.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1pwm-cv.js +++ b/homematic-devices/hm-lc-dim1pwm-cv.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1t-cv-2.js b/homematic-devices/hm-lc-dim1t-cv-2.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1t-cv-2.js +++ b/homematic-devices/hm-lc-dim1t-cv-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1t-cv.js b/homematic-devices/hm-lc-dim1t-cv.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1t-cv.js +++ b/homematic-devices/hm-lc-dim1t-cv.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1t-dr.js b/homematic-devices/hm-lc-dim1t-dr.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1t-dr.js +++ b/homematic-devices/hm-lc-dim1t-dr.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1t-fm-2.js b/homematic-devices/hm-lc-dim1t-fm-2.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1t-fm-2.js +++ b/homematic-devices/hm-lc-dim1t-fm-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1t-fm-lf.js b/homematic-devices/hm-lc-dim1t-fm-lf.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1t-fm-lf.js +++ b/homematic-devices/hm-lc-dim1t-fm-lf.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1t-fm.js b/homematic-devices/hm-lc-dim1t-fm.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1t-fm.js +++ b/homematic-devices/hm-lc-dim1t-fm.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1t-pl-2.js b/homematic-devices/hm-lc-dim1t-pl-2.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1t-pl-2.js +++ b/homematic-devices/hm-lc-dim1t-pl-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1t-pl-3.js b/homematic-devices/hm-lc-dim1t-pl-3.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1t-pl-3.js +++ b/homematic-devices/hm-lc-dim1t-pl-3.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1t-pl.js b/homematic-devices/hm-lc-dim1t-pl.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1t-pl.js +++ b/homematic-devices/hm-lc-dim1t-pl.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1tpbu-fm-2.js b/homematic-devices/hm-lc-dim1tpbu-fm-2.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1tpbu-fm-2.js +++ b/homematic-devices/hm-lc-dim1tpbu-fm-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim1tpbu-fm.js b/homematic-devices/hm-lc-dim1tpbu-fm.js index b42c2e9..d34bc8c 100644 --- a/homematic-devices/hm-lc-dim1tpbu-fm.js +++ b/homematic-devices/hm-lc-dim1tpbu-fm.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim1l-cv'); +module.exports = require('./hm-lc-dim1l-cv.js'); diff --git a/homematic-devices/hm-lc-dim2l-sm-2.js b/homematic-devices/hm-lc-dim2l-sm-2.js index acb45ef..b5ccd45 100644 --- a/homematic-devices/hm-lc-dim2l-sm-2.js +++ b/homematic-devices/hm-lc-dim2l-sm-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim2l-sm'); +module.exports = require('./hm-lc-dim2l-sm.js'); diff --git a/homematic-devices/hm-lc-dim2l-sm.js b/homematic-devices/hm-lc-dim2l-sm.js index 871ed31..a202b8d 100644 --- a/homematic-devices/hm-lc-dim2l-sm.js +++ b/homematic-devices/hm-lc-dim2l-sm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmLcDim2 extends Accessory { init(config, node) { @@ -27,11 +27,7 @@ module.exports = class HmLcDim2 extends Accessory { .set('On', (value, callback) => { if (value) { setTimeout(() => { - if (valueBrightness === 0) { - value = 1; - } else { - value = valueBrightness / 100; - } + value = valueBrightness === 0 ? 1 : valueBrightness / 100; this.ccuSetValue(dp, value, callback); }, 100); diff --git a/homematic-devices/hm-lc-dim2t-sm-2.js b/homematic-devices/hm-lc-dim2t-sm-2.js index acb45ef..b5ccd45 100644 --- a/homematic-devices/hm-lc-dim2t-sm-2.js +++ b/homematic-devices/hm-lc-dim2t-sm-2.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim2l-sm'); +module.exports = require('./hm-lc-dim2l-sm.js'); diff --git a/homematic-devices/hm-lc-dim2t-sm.js b/homematic-devices/hm-lc-dim2t-sm.js index acb45ef..b5ccd45 100644 --- a/homematic-devices/hm-lc-dim2t-sm.js +++ b/homematic-devices/hm-lc-dim2t-sm.js @@ -1 +1 @@ -module.exports = require('./hm-lc-dim2l-sm'); +module.exports = require('./hm-lc-dim2l-sm.js'); diff --git a/homematic-devices/hm-lc-ja1pbu-fm.js b/homematic-devices/hm-lc-ja1pbu-fm.js index f148741..84da230 100644 --- a/homematic-devices/hm-lc-ja1pbu-fm.js +++ b/homematic-devices/hm-lc-ja1pbu-fm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmLcJa1 extends Accessory { init(config) { @@ -6,18 +6,12 @@ module.exports = class HmLcJa1 extends Accessory { let level = null; let levelSlats = null; - const that = this; - const service = this.addService('WindowCovering', config.name); service - .get('CurrentPosition', config.deviceAddress + ':1.LEVEL', value => { - return value * 100; - }) + .get('CurrentPosition', config.deviceAddress + ':1.LEVEL', value => value * 100) - .get('TargetPosition', config.deviceAddress + ':1.LEVEL', value => { - return value * 100; - }) + .get('TargetPosition', config.deviceAddress + ':1.LEVEL', value => value * 100) .set('TargetPosition', (value, callback) => { level = value / 100; clearTimeout(timeout); @@ -38,13 +32,8 @@ module.exports = class HmLcJa1 extends Accessory { } }) - .get('CurrentVerticalTiltAngle', config.deviceAddress + ':1.LEVEL_SLATS', value => { - return (value * 180) - 90; - }) - - .get('TargetVerticalTiltAngle', config.deviceAddress + ':1.LEVEL_SLATS', value => { - return (value * 180) - 90; - }) + .get('CurrentVerticalTiltAngle', config.deviceAddress + ':1.LEVEL_SLATS', value => (value * 180) - 90) + .get('TargetVerticalTiltAngle', config.deviceAddress + ':1.LEVEL_SLATS', value => (value * 180) - 90) .set('TargetVerticalTiltAngle', (value, callback) => { levelSlats = (value + 90) / 180; clearTimeout(timeout); @@ -70,7 +59,7 @@ module.exports = class HmLcJa1 extends Accessory { dp = config.deviceAddress + ':1.LEVEL_SLATS'; } - that.ccuSetValue(dp, value, error => { + this.ccuSetValue(dp, value, error => { if (error) { service.updateCharacteristic('TargetPosition', error); } diff --git a/homematic-devices/hm-lc-rgbw-wm.js b/homematic-devices/hm-lc-rgbw-wm.js index 1b17ee1..799ee76 100644 --- a/homematic-devices/hm-lc-rgbw-wm.js +++ b/homematic-devices/hm-lc-rgbw-wm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmLcRgbw extends Accessory { init(config, node) { diff --git a/homematic-devices/hm-lc-sw1-ba-pcb.js b/homematic-devices/hm-lc-sw1-ba-pcb.js index e74fec3..89da818 100644 --- a/homematic-devices/hm-lc-sw1-ba-pcb.js +++ b/homematic-devices/hm-lc-sw1-ba-pcb.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmLcSw1BaPcb extends Accessory { init(config) { @@ -6,13 +6,9 @@ module.exports = class HmLcSw1BaPcb extends Accessory { .get('On', config.deviceAddress + ':1.STATE') .set('On', config.deviceAddress + ':1.STATE'); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); } }; diff --git a/homematic-devices/hm-lc-sw1-dr.js b/homematic-devices/hm-lc-sw1-dr.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-dr.js +++ b/homematic-devices/hm-lc-sw1-dr.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-fm-2.js b/homematic-devices/hm-lc-sw1-fm-2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-fm-2.js +++ b/homematic-devices/hm-lc-sw1-fm-2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-fm.js b/homematic-devices/hm-lc-sw1-fm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-fm.js +++ b/homematic-devices/hm-lc-sw1-fm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pb-fm.js b/homematic-devices/hm-lc-sw1-pb-fm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pb-fm.js +++ b/homematic-devices/hm-lc-sw1-pb-fm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pcb.js b/homematic-devices/hm-lc-sw1-pcb.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pcb.js +++ b/homematic-devices/hm-lc-sw1-pcb.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-2.js b/homematic-devices/hm-lc-sw1-pl-2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-2.js +++ b/homematic-devices/hm-lc-sw1-pl-2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-3.js b/homematic-devices/hm-lc-sw1-pl-3.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-3.js +++ b/homematic-devices/hm-lc-sw1-pl-3.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-ct-r1.js b/homematic-devices/hm-lc-sw1-pl-ct-r1.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-ct-r1.js +++ b/homematic-devices/hm-lc-sw1-pl-ct-r1.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-ct-r2.js b/homematic-devices/hm-lc-sw1-pl-ct-r2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-ct-r2.js +++ b/homematic-devices/hm-lc-sw1-pl-ct-r2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-ct-r3.js b/homematic-devices/hm-lc-sw1-pl-ct-r3.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-ct-r3.js +++ b/homematic-devices/hm-lc-sw1-pl-ct-r3.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-ct-r4.js b/homematic-devices/hm-lc-sw1-pl-ct-r4.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-ct-r4.js +++ b/homematic-devices/hm-lc-sw1-pl-ct-r4.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-ct-r5.js b/homematic-devices/hm-lc-sw1-pl-ct-r5.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-ct-r5.js +++ b/homematic-devices/hm-lc-sw1-pl-ct-r5.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-dn-r1.js b/homematic-devices/hm-lc-sw1-pl-dn-r1.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-dn-r1.js +++ b/homematic-devices/hm-lc-sw1-pl-dn-r1.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-dn-r2.js b/homematic-devices/hm-lc-sw1-pl-dn-r2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-dn-r2.js +++ b/homematic-devices/hm-lc-sw1-pl-dn-r2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-dn-r3.js b/homematic-devices/hm-lc-sw1-pl-dn-r3.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-dn-r3.js +++ b/homematic-devices/hm-lc-sw1-pl-dn-r3.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-dn-r4.js b/homematic-devices/hm-lc-sw1-pl-dn-r4.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-dn-r4.js +++ b/homematic-devices/hm-lc-sw1-pl-dn-r4.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-dn-r5.js b/homematic-devices/hm-lc-sw1-pl-dn-r5.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-dn-r5.js +++ b/homematic-devices/hm-lc-sw1-pl-dn-r5.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl-om54.js b/homematic-devices/hm-lc-sw1-pl-om54.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl-om54.js +++ b/homematic-devices/hm-lc-sw1-pl-om54.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-pl.js b/homematic-devices/hm-lc-sw1-pl.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-pl.js +++ b/homematic-devices/hm-lc-sw1-pl.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-sm-2.js b/homematic-devices/hm-lc-sw1-sm-2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-sm-2.js +++ b/homematic-devices/hm-lc-sw1-sm-2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1-sm.js b/homematic-devices/hm-lc-sw1-sm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1-sm.js +++ b/homematic-devices/hm-lc-sw1-sm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw1pbu-fm.js b/homematic-devices/hm-lc-sw1pbu-fm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw1pbu-fm.js +++ b/homematic-devices/hm-lc-sw1pbu-fm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw2-dr-2.js b/homematic-devices/hm-lc-sw2-dr-2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw2-dr-2.js +++ b/homematic-devices/hm-lc-sw2-dr-2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw2-dr.js b/homematic-devices/hm-lc-sw2-dr.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw2-dr.js +++ b/homematic-devices/hm-lc-sw2-dr.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw2-fm-2.js b/homematic-devices/hm-lc-sw2-fm-2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw2-fm-2.js +++ b/homematic-devices/hm-lc-sw2-fm-2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw2-fm.js b/homematic-devices/hm-lc-sw2-fm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw2-fm.js +++ b/homematic-devices/hm-lc-sw2-fm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw2-pb-fm.js b/homematic-devices/hm-lc-sw2-pb-fm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw2-pb-fm.js +++ b/homematic-devices/hm-lc-sw2-pb-fm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw2pbu-fm.js b/homematic-devices/hm-lc-sw2pbu-fm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw2pbu-fm.js +++ b/homematic-devices/hm-lc-sw2pbu-fm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw4-ba-pcb.js b/homematic-devices/hm-lc-sw4-ba-pcb.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw4-ba-pcb.js +++ b/homematic-devices/hm-lc-sw4-ba-pcb.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw4-dr-2.js b/homematic-devices/hm-lc-sw4-dr-2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw4-dr-2.js +++ b/homematic-devices/hm-lc-sw4-dr-2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw4-dr.js b/homematic-devices/hm-lc-sw4-dr.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw4-dr.js +++ b/homematic-devices/hm-lc-sw4-dr.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw4-pcb-2.js b/homematic-devices/hm-lc-sw4-pcb-2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw4-pcb-2.js +++ b/homematic-devices/hm-lc-sw4-pcb-2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw4-pcb.js b/homematic-devices/hm-lc-sw4-pcb.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw4-pcb.js +++ b/homematic-devices/hm-lc-sw4-pcb.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw4-sm-2.js b/homematic-devices/hm-lc-sw4-sm-2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw4-sm-2.js +++ b/homematic-devices/hm-lc-sw4-sm-2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw4-sm.js b/homematic-devices/hm-lc-sw4-sm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw4-sm.js +++ b/homematic-devices/hm-lc-sw4-sm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw4-wm-2.js b/homematic-devices/hm-lc-sw4-wm-2.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw4-wm-2.js +++ b/homematic-devices/hm-lc-sw4-wm-2.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-lc-sw4-wm.js b/homematic-devices/hm-lc-sw4-wm.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-lc-sw4-wm.js +++ b/homematic-devices/hm-lc-sw4-wm.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-mod-re-8.js b/homematic-devices/hm-mod-re-8.js index c5cf82d..253424f 100644 --- a/homematic-devices/hm-mod-re-8.js +++ b/homematic-devices/hm-mod-re-8.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hm-sci-3-fm.js b/homematic-devices/hm-sci-3-fm.js index 7335a2c..d685bcf 100644 --- a/homematic-devices/hm-sci-3-fm.js +++ b/homematic-devices/hm-sci-3-fm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSci3Fm extends Accessory { init(config, node) { @@ -43,24 +43,16 @@ module.exports = class HmSci3Fm extends Accessory { }, 20); }); - this.addService('BatteryService', name, 'Bat') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }); + this.addService('Battery', name, 'Bat') + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100); break; default: this.addService('ContactSensor', name) - .get('ContactSensorState', dp, (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('ContactSensorState', dp, (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } } diff --git a/homematic-devices/hm-sec-key-o.js b/homematic-devices/hm-sec-key-o.js index 34d426e..972490c 100644 --- a/homematic-devices/hm-sec-key-o.js +++ b/homematic-devices/hm-sec-key-o.js @@ -1 +1 @@ -module.exports = require('./hm-sec-key'); +module.exports = require('./hm-sec-key.js'); diff --git a/homematic-devices/hm-sec-key-s.js b/homematic-devices/hm-sec-key-s.js index 34d426e..972490c 100644 --- a/homematic-devices/hm-sec-key-s.js +++ b/homematic-devices/hm-sec-key-s.js @@ -1 +1 @@ -module.exports = require('./hm-sec-key'); +module.exports = require('./hm-sec-key.js'); diff --git a/homematic-devices/hm-sec-key.js b/homematic-devices/hm-sec-key.js index 0d7246f..041028a 100644 --- a/homematic-devices/hm-sec-key.js +++ b/homematic-devices/hm-sec-key.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSecKey extends Accessory { init(config, node) { @@ -53,13 +53,9 @@ module.exports = class HmSecKey extends Accessory { service.update('LockCurrentState', getState()); }); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); } }; diff --git a/homematic-devices/hm-sec-mdir-2.js b/homematic-devices/hm-sec-mdir-2.js index e92b87a..5116807 100644 --- a/homematic-devices/hm-sec-mdir-2.js +++ b/homematic-devices/hm-sec-mdir-2.js @@ -1 +1 @@ -module.exports = require('./hm-sec-mdir'); +module.exports = require('./hm-sec-mdir.js'); diff --git a/homematic-devices/hm-sec-mdir-3.js b/homematic-devices/hm-sec-mdir-3.js index e92b87a..5116807 100644 --- a/homematic-devices/hm-sec-mdir-3.js +++ b/homematic-devices/hm-sec-mdir-3.js @@ -1 +1 @@ -module.exports = require('./hm-sec-mdir'); +module.exports = require('./hm-sec-mdir.js'); diff --git a/homematic-devices/hm-sec-mdir.js b/homematic-devices/hm-sec-mdir.js index 8e73f6f..b079347 100644 --- a/homematic-devices/hm-sec-mdir.js +++ b/homematic-devices/hm-sec-mdir.js @@ -1,25 +1,17 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSecMdir extends Accessory { init(config) { this.addService('MotionSensor', config.name) .get('MotionDetected', config.deviceAddress + ':1.MOTION') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('StatusTampered', config.deviceAddress + ':1.ERROR', value => { - return Boolean(value); - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('StatusTampered', config.deviceAddress + ':1.ERROR', value => Boolean(value)); if (this.option('LightSensor')) { this.addService('LightSensor', config.name) .get('CurrentAmbientLightLevel', config.deviceAddress + ':1.BRIGHTNESS', this.lux) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('StatusTampered', config.deviceAddress + ':1.ERROR', value => { - return Boolean(value); - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('StatusTampered', config.deviceAddress + ':1.ERROR', value => Boolean(value)); } } }; diff --git a/homematic-devices/hm-sec-rhs-2.js b/homematic-devices/hm-sec-rhs-2.js index dcf52a7..93e2cb9 100644 --- a/homematic-devices/hm-sec-rhs-2.js +++ b/homematic-devices/hm-sec-rhs-2.js @@ -1 +1 @@ -module.exports = require('./hm-sec-rhs'); +module.exports = require('./hm-sec-rhs.js'); diff --git a/homematic-devices/hm-sec-rhs.js b/homematic-devices/hm-sec-rhs.js index b33cafc..0f64120 100644 --- a/homematic-devices/hm-sec-rhs.js +++ b/homematic-devices/hm-sec-rhs.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSecRhs extends Accessory { init(config) { @@ -7,8 +7,8 @@ module.exports = class HmSecRhs extends Accessory { let service; let actualValue; - function convert(val) { - switch (val) { + function convert(value) { + switch (value) { case 1: return 25; case 2: @@ -46,33 +46,19 @@ module.exports = class HmSecRhs extends Accessory { }, 20); }); - service.get('ObstructionDetected', config.deviceAddress + ':1.ERROR', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':1.ERROR', value => Boolean(value)); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }); + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100); break; default: this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) - - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - - .get('StatusTampered', config.deviceAddress + ':1.ERROR', value => { - return Boolean(value); - }); + .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('StatusTampered', config.deviceAddress + ':1.ERROR', value => Boolean(value)); } } }; diff --git a/homematic-devices/hm-sec-sc-2.js b/homematic-devices/hm-sec-sc-2.js index 573cbde..1ad21a2 100644 --- a/homematic-devices/hm-sec-sc-2.js +++ b/homematic-devices/hm-sec-sc-2.js @@ -1 +1 @@ -module.exports = require('./hm-sec-sc'); +module.exports = require('./hm-sec-sc.js'); diff --git a/homematic-devices/hm-sec-sc.js b/homematic-devices/hm-sec-sc.js index 09998bf..02603c9 100644 --- a/homematic-devices/hm-sec-sc.js +++ b/homematic-devices/hm-sec-sc.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSecSc extends Accessory { init(config) { @@ -34,9 +34,7 @@ module.exports = class HmSecSc extends Accessory { }, 100); }); - service.get('ObstructionDetected', config.deviceAddress + ':1.ERROR', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':1.ERROR', value => Boolean(value)); break; @@ -67,34 +65,20 @@ module.exports = class HmSecSc extends Accessory { }, 20); }); - service.get('ObstructionDetected', config.deviceAddress + ':1.ERROR', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':1.ERROR', value => Boolean(value)); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); break; default: this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) - - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - - .get('StatusTampered', config.deviceAddress + ':1.ERROR', value => { - return Boolean(value); - }); + .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('StatusTampered', config.deviceAddress + ':1.ERROR', value => Boolean(value)); } } }; diff --git a/homematic-devices/hm-sec-sco.js b/homematic-devices/hm-sec-sco.js index 573cbde..1ad21a2 100644 --- a/homematic-devices/hm-sec-sco.js +++ b/homematic-devices/hm-sec-sco.js @@ -1 +1 @@ -module.exports = require('./hm-sec-sc'); +module.exports = require('./hm-sec-sc.js'); diff --git a/homematic-devices/hm-sec-sd-2.js b/homematic-devices/hm-sec-sd-2.js index 5aec565..2662ccc 100644 --- a/homematic-devices/hm-sec-sd-2.js +++ b/homematic-devices/hm-sec-sd-2.js @@ -1 +1 @@ -module.exports = require('./hm-sec-sd'); +module.exports = require('./hm-sec-sd.js'); diff --git a/homematic-devices/hm-sec-sd.js b/homematic-devices/hm-sec-sd.js index 474a295..fed3657 100644 --- a/homematic-devices/hm-sec-sd.js +++ b/homematic-devices/hm-sec-sd.js @@ -1,20 +1,15 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSecSd extends Accessory { init(config) { this.addService('SmokeSensor', config.name) - .get('SmokeDetected', config.deviceAddress + ':1.STATE', (value, c) => { - return value ? c.SMOKE_DETECTED : c.SMOKE_NOT_DETECTED; - }) - - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + .get('SmokeDetected', config.deviceAddress + ':1.STATE', (value, c) => value ? c.SMOKE_DETECTED : c.SMOKE_NOT_DETECTED) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .fault([ config.deviceAddress + ':0.UNREACH', config.deviceAddress + ':1.ERROR_ALARM_TEST', - config.deviceAddress + ':1.ERROR_SMOKE_CHAMBER' + config.deviceAddress + ':1.ERROR_SMOKE_CHAMBER', ]); } }; diff --git a/homematic-devices/hm-sec-sir-wm.js b/homematic-devices/hm-sec-sir-wm.js index 4951d7f..82e2c40 100644 --- a/homematic-devices/hm-sec-sir-wm.js +++ b/homematic-devices/hm-sec-sir-wm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSecSir extends Accessory { /* @@ -30,75 +30,69 @@ module.exports = class HmSecSir extends Accessory { .setProps('SecuritySystemTargetState', {validValues: [0, 1, 3]}) .get('SecuritySystemCurrentState', config.deviceAddress + ':4.ARMSTATE', value => { - let val = 3; + let result = 3; switch (value) { case 1: - val = 0; + result = 0; break; case 2: - val = 1; + result = 1; break; default: } - this.currentState = val; - return val; + this.currentState = result; + return result; }) .get('SecuritySystemTargetState', config.deviceAddress + ':4.ARMSTATE', value => { - let val = 3; + let result = 3; switch (value) { case 1: - val = 0; + result = 0; break; case 2: - val = 1; + result = 1; break; default: } - this.currentState = val; - return val; + this.currentState = result; + return result; }) .set('SecuritySystemTargetState', config.deviceAddress + ':4.ARMSTATE', value => { - let val = 0; + let result = 0; switch (value) { case 0: - val = 1; + result = 1; break; case 1: - val = 2; + result = 2; break; default: } - this.currentState = value; - return val; + this.currentState = value; // Todo result instead of value? + return result; }) - .get('StatusTampered', config.deviceAddress + ':4.ERROR_SABOTAGE', value => { - return Boolean(value); - }); + .get('StatusTampered', config.deviceAddress + ':4.ERROR_SABOTAGE', value => Boolean(value)); - this.subscribe(config.deviceAddress + ':1.STATE', val => { - this.states[0] = val; + this.subscribe(config.deviceAddress + ':1.STATE', value => { + this.states[0] = value; this.checkAlarm(); }); - this.subscribe(config.deviceAddress + ':2.STATE', val => { - this.states[1] = val; + this.subscribe(config.deviceAddress + ':2.STATE', value => { + this.states[1] = value; this.checkAlarm(); }); - this.subscribe(config.deviceAddress + ':3.STATE', val => { - this.states[2] = val; + this.subscribe(config.deviceAddress + ':3.STATE', value => { + this.states[2] = value; this.checkAlarm(); }); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); } }; diff --git a/homematic-devices/hm-sec-tis.js b/homematic-devices/hm-sec-tis.js index d067d7d..3697f8c 100644 --- a/homematic-devices/hm-sec-tis.js +++ b/homematic-devices/hm-sec-tis.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSecTis extends Accessory { init(config) { @@ -63,26 +63,17 @@ module.exports = class HmSecTis extends Accessory { }, 20); }); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOWBAT', value => value ? 0 : 100) .update('ChargingState', 2); break; default: this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) - - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hm-sec-wds-2.js b/homematic-devices/hm-sec-wds-2.js index cc5b4ea..e20df03 100644 --- a/homematic-devices/hm-sec-wds-2.js +++ b/homematic-devices/hm-sec-wds-2.js @@ -1 +1 @@ -module.exports = require('./hm-sec-wds'); +module.exports = require('./hm-sec-wds.js'); diff --git a/homematic-devices/hm-sec-wds.js b/homematic-devices/hm-sec-wds.js index 98ee283..4683025 100644 --- a/homematic-devices/hm-sec-wds.js +++ b/homematic-devices/hm-sec-wds.js @@ -1,13 +1,9 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSwd extends Accessory { init(config) { this.addService('LeakSensor', config.name) - .get('LeakDetected', config.deviceAddress + ':1.STATE', (value, c) => { - return value ? c.LEAK_DETECTED : c.LEAK_NOT_DETECTED; - }) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('LeakDetected', config.deviceAddress + ':1.STATE', (value, c) => value ? c.LEAK_DETECTED : c.LEAK_NOT_DETECTED) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } }; diff --git a/homematic-devices/hm-sec-win.js b/homematic-devices/hm-sec-win.js index b54b607..6b82995 100644 --- a/homematic-devices/hm-sec-win.js +++ b/homematic-devices/hm-sec-win.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSecWin extends Accessory { init(config) { @@ -13,9 +13,7 @@ module.exports = class HmSecWin extends Accessory { return value * 100; }) - .set('TargetPosition', config.deviceAddress + ':1.LEVEL', value => { - return value === 0 && this.option('LockOnClose') ? -0.005 : (value / 100); - }) + .set('TargetPosition', config.deviceAddress + ':1.LEVEL', value => value === 0 && this.option('LockOnClose') ? -0.005 : (value / 100)) .get('PositionState', config.deviceAddress + ':1.DIRECTION', (value, c) => { switch (value) { @@ -28,19 +26,11 @@ module.exports = class HmSecWin extends Accessory { } }) - .get('ObstructionDetected', config.deviceAddress + ':1.ERROR', value => { - return Boolean(value); - }); + .get('ObstructionDetected', config.deviceAddress + ':1.ERROR', value => Boolean(value)); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':2.LEVEL', value => { - return value * 100; - }) - .get('ChargingState', config.deviceAddress + ':2.STATUS', value => { - return value === 2 ? 0 : 1; - }); + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':2.LEVEL', value => value * 100) + .get('ChargingState', config.deviceAddress + ':2.STATUS', value => value === 2 ? 0 : 1); } }; diff --git a/homematic-devices/hm-sen-db-pcb.js b/homematic-devices/hm-sen-db-pcb.js index d9b886d..6fbac5b 100644 --- a/homematic-devices/hm-sen-db-pcb.js +++ b/homematic-devices/hm-sen-db-pcb.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSecSc extends Accessory { init(config) { diff --git a/homematic-devices/hm-sen-li-o.js b/homematic-devices/hm-sen-li-o.js index badb0bc..12284a0 100644 --- a/homematic-devices/hm-sen-li-o.js +++ b/homematic-devices/hm-sen-li-o.js @@ -1,11 +1,9 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSenLi extends Accessory { init(config) { this.addService('LightSensor', config.name) .get('CurrentAmbientLightLevel', config.deviceAddress + ':1.LUX') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } }; diff --git a/homematic-devices/hm-sen-mdir-o-2.js b/homematic-devices/hm-sen-mdir-o-2.js index d44ad19..883003d 100644 --- a/homematic-devices/hm-sen-mdir-o-2.js +++ b/homematic-devices/hm-sen-mdir-o-2.js @@ -1 +1 @@ -module.exports = require('./hm-sen-mdir-sm'); +module.exports = require('./hm-sen-mdir-sm.js'); diff --git a/homematic-devices/hm-sen-mdir-o-3.js b/homematic-devices/hm-sen-mdir-o-3.js index d44ad19..883003d 100644 --- a/homematic-devices/hm-sen-mdir-o-3.js +++ b/homematic-devices/hm-sen-mdir-o-3.js @@ -1 +1 @@ -module.exports = require('./hm-sen-mdir-sm'); +module.exports = require('./hm-sen-mdir-sm.js'); diff --git a/homematic-devices/hm-sen-mdir-o.js b/homematic-devices/hm-sen-mdir-o.js index d44ad19..883003d 100644 --- a/homematic-devices/hm-sen-mdir-o.js +++ b/homematic-devices/hm-sen-mdir-o.js @@ -1 +1 @@ -module.exports = require('./hm-sen-mdir-sm'); +module.exports = require('./hm-sen-mdir-sm.js'); diff --git a/homematic-devices/hm-sen-mdir-sm.js b/homematic-devices/hm-sen-mdir-sm.js index e92b87a..5116807 100644 --- a/homematic-devices/hm-sen-mdir-sm.js +++ b/homematic-devices/hm-sen-mdir-sm.js @@ -1 +1 @@ -module.exports = require('./hm-sec-mdir'); +module.exports = require('./hm-sec-mdir.js'); diff --git a/homematic-devices/hm-sen-mdir-wm55.js b/homematic-devices/hm-sen-mdir-wm55.js index e9e6cd4..66750d3 100644 --- a/homematic-devices/hm-sen-mdir-wm55.js +++ b/homematic-devices/hm-sen-mdir-wm55.js @@ -1,19 +1,15 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSenMdir55 extends Accessory { init(config) { this.addService('MotionSensor', config.name) .get('MotionDetected', config.deviceAddress + ':3.MOTION') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); if (this.option('LightSensor')) { this.addService('LightSensor', config.name) .get('CurrentAmbientLightLevel', config.deviceAddress + ':3.BRIGHTNESS', this.lux) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hm-tc-it-wm-w-eu.js b/homematic-devices/hm-tc-it-wm-w-eu.js index 58f003e..c01dee3 100644 --- a/homematic-devices/hm-tc-it-wm-w-eu.js +++ b/homematic-devices/hm-tc-it-wm-w-eu.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmTcItWmWEu extends Accessory { init(config, node) { @@ -14,8 +14,6 @@ module.exports = class HmTcItWmWEu extends Accessory { const levels = {}; let level = 0; - const that = this; - const links = ccu.getLinks(config.iface, config.description.ADDRESS + ':2') || []; node.debug(config.name + ' linked to ' + JSON.stringify(links)); @@ -116,45 +114,44 @@ module.exports = class HmTcItWmWEu extends Accessory { function updateHeatingCoolingState() { const current = currentState(); node.debug('update ' + config.name + ' (' + subtypeThermostat + ') CurrentHeatingCoolingState ' + current); - that.acc.getService(subtypeThermostat).updateCharacteristic(hap.Characteristic.CurrentHeatingCoolingState, current); + this.acc.getService(subtypeThermostat).updateCharacteristic(hap.Characteristic.CurrentHeatingCoolingState, current); const target = targetState(); node.debug('update ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + target); - that.acc.getService(subtypeThermostat).updateCharacteristic(hap.Characteristic.TargetHeatingCoolingState, target); + this.acc.getService(subtypeThermostat).updateCharacteristic(hap.Characteristic.TargetHeatingCoolingState, target); } - links.forEach(link => { + for (const link of links) { const valveStateDevice = link.split(':')[0]; const datapointLevel = config.iface + '.' + valveStateDevice + ':4.VALVE_STATE'; this.subscribe(datapointLevel, value => { levels[datapointLevel] = value; let max = 0; - Object.keys(levels).forEach(dp => { + for (const dp of Object.keys(levels)) { if (levels[dp] > max) { max = levels[dp]; } - }); + } + if (level !== max) { level = max; node.debug('update ' + config.name + ' level ' + level); updateHeatingCoolingState(); } }); - }); + } this.subscriptions.push(ccu.subscribe({ cache: true, change: true, - datapointName: config.deviceAddress + ':2.CONTROL_MODE' - }, msg => { - controlMode = msg.value; - node.debug('update ' + config.name + ' controlMode ' + msg.value); + datapointName: config.deviceAddress + ':2.CONTROL_MODE', + }, message => { + controlMode = message.value; + node.debug('update ' + config.name + ' controlMode ' + message.value); updateHeatingCoolingState(); })); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':2.BATTERY_STATE', this.percent); if (this.option('HumiditySensor')) { @@ -176,19 +173,18 @@ module.exports = class HmTcItWmWEu extends Accessory { value = true; } - this.ccuSetValue(config.iface + '.' + config.description.ADDRESS + ':2.' + dp, value, res => { - links.forEach((link, i) => { + this.ccuSetValue(config.iface + '.' + config.description.ADDRESS + ':2.' + dp, value, response => { + for (const [i, link] of links.entries()) { const linkedDevice = link.split(':')[0]; setTimeout(() => { this.ccuSetValue(config.iface + '.' + linkedDevice + ':4.' + dp, value); }, i * 3000); - }); - callback(res); + } + + callback(response); }); }) - .get('On', config.deviceAddress + ':2.CONTROL_MODE', value => { - return value === 3; - }); + .get('On', config.deviceAddress + ':2.CONTROL_MODE', value => value === 3); } } }; diff --git a/homematic-devices/hm-wds10-th-o.js b/homematic-devices/hm-wds10-th-o.js index b370b0d..6d1de67 100644 --- a/homematic-devices/hm-wds10-th-o.js +++ b/homematic-devices/hm-wds10-th-o.js @@ -1,22 +1,16 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmWds extends Accessory { init(config) { this.addService('TemperatureSensor', config.name) .setProps('CurrentTemperature', {minValue: -40, maxValue: 80}) .get('CurrentTemperature', config.deviceAddress + ':1.TEMPERATURE') - - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); if (this.option('HumiditySensor')) { this.addService('HumiditySensor', config.name) .get('CurrentRelativeHumidity', config.deviceAddress + ':1.HUMIDITY') - - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hm-wds100-c6-o-2.js b/homematic-devices/hm-wds100-c6-o-2.js index a77b399..299d2ab 100644 --- a/homematic-devices/hm-wds100-c6-o-2.js +++ b/homematic-devices/hm-wds100-c6-o-2.js @@ -1 +1 @@ -module.exports = require('./hm-wds100-c6-o'); +module.exports = require('./hm-wds100-c6-o.js'); diff --git a/homematic-devices/hm-wds100-c6-o.js b/homematic-devices/hm-wds100-c6-o.js index cf33ee9..5c06b19 100644 --- a/homematic-devices/hm-wds100-c6-o.js +++ b/homematic-devices/hm-wds100-c6-o.js @@ -1,28 +1,22 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmWds100 extends Accessory { init(config) { this.addService('TemperatureSensor', config.name) .setProps('CurrentTemperature', {minValue: -40, maxValue: 80}) .get('CurrentTemperature', config.deviceAddress + ':1.TEMPERATURE') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); if (this.option('HumiditySensor')) { this.addService('HumiditySensor', config.name) .get('CurrentRelativeHumidity', config.deviceAddress + ':1.HUMIDITY') - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } if (this.option('LightSensor')) { this.addService('LightSensor', config.name) .get('CurrentAmbientLightLevel', config.deviceAddress + ':1.BRIGHTNESS', this.lux) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hm-wds20-th-o.js b/homematic-devices/hm-wds20-th-o.js index 4b58b60..260741f 100644 --- a/homematic-devices/hm-wds20-th-o.js +++ b/homematic-devices/hm-wds20-th-o.js @@ -1 +1 @@ -module.exports = require('./hm-wds10-th-o'); +module.exports = require('./hm-wds10-th-o.js'); diff --git a/homematic-devices/hm-wds30-ot2-sm-2.js b/homematic-devices/hm-wds30-ot2-sm-2.js index 445b15f..62edb78 100644 --- a/homematic-devices/hm-wds30-ot2-sm-2.js +++ b/homematic-devices/hm-wds30-ot2-sm-2.js @@ -1 +1 @@ -module.exports = require('./hm-wds30-ot2-sm'); +module.exports = require('./hm-wds30-ot2-sm.js'); diff --git a/homematic-devices/hm-wds30-ot2-sm.js b/homematic-devices/hm-wds30-ot2-sm.js index a13fc41..7d0d449 100644 --- a/homematic-devices/hm-wds30-ot2-sm.js +++ b/homematic-devices/hm-wds30-ot2-sm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmSw extends Accessory { init(config, node) { @@ -18,9 +18,7 @@ module.exports = class HmSw extends Accessory { this.addService('TemperatureSensor', name) .setProps('CurrentTemperature', {minValue: -150, maxValue: 150}) .get('CurrentTemperature', dp) - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hm-wds30-t-o.js b/homematic-devices/hm-wds30-t-o.js index 82e7656..89a3376 100644 --- a/homematic-devices/hm-wds30-t-o.js +++ b/homematic-devices/hm-wds30-t-o.js @@ -1,13 +1,10 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmWds extends Accessory { init(config) { this.addService('TemperatureSensor', config.name) .setProps('CurrentTemperature', {minValue: -40, maxValue: 80}) .get('CurrentTemperature', config.deviceAddress + ':1.TEMPERATURE') - - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } }; diff --git a/homematic-devices/hm-wds40-th-i-2.js b/homematic-devices/hm-wds40-th-i-2.js index 4b58b60..260741f 100644 --- a/homematic-devices/hm-wds40-th-i-2.js +++ b/homematic-devices/hm-wds40-th-i-2.js @@ -1 +1 @@ -module.exports = require('./hm-wds10-th-o'); +module.exports = require('./hm-wds10-th-o.js'); diff --git a/homematic-devices/hm-wds40-th-i.js b/homematic-devices/hm-wds40-th-i.js index 4b58b60..260741f 100644 --- a/homematic-devices/hm-wds40-th-i.js +++ b/homematic-devices/hm-wds40-th-i.js @@ -1 +1 @@ -module.exports = require('./hm-wds10-th-o'); +module.exports = require('./hm-wds10-th-o.js'); diff --git a/homematic-devices/hm-ws550st-io.js b/homematic-devices/hm-ws550st-io.js index 4cf6993..ce1f765 100644 --- a/homematic-devices/hm-ws550st-io.js +++ b/homematic-devices/hm-ws550st-io.js @@ -1 +1 @@ -module.exports = require('./hm-ws550sth-i'); +module.exports = require('./hm-ws550sth-i.js'); diff --git a/homematic-devices/hm-ws550sth-i.js b/homematic-devices/hm-ws550sth-i.js index 733b8bb..6ba34fa 100644 --- a/homematic-devices/hm-ws550sth-i.js +++ b/homematic-devices/hm-ws550sth-i.js @@ -1,22 +1,16 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmWs550 extends Accessory { init(config) { this.addService('TemperatureSensor', config.name) .setProps('CurrentTemperature', {minValue: -40, maxValue: 80}) .get('CurrentTemperature', config.deviceAddress + ':10.TEMPERATURE') - - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); if (this.option('HumiditySensor')) { this.addService('HumiditySensor', config.name) .get('CurrentRelativeHumidity', config.deviceAddress + ':10.HUMIDITY') - - .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hm-ws550sth-o.js b/homematic-devices/hm-ws550sth-o.js index 4cf6993..ce1f765 100644 --- a/homematic-devices/hm-ws550sth-o.js +++ b/homematic-devices/hm-ws550sth-o.js @@ -1 +1 @@ -module.exports = require('./hm-ws550sth-i'); +module.exports = require('./hm-ws550sth-i.js'); diff --git a/homematic-devices/hmip-bbl.js b/homematic-devices/hmip-bbl.js index d8777c6..21b2187 100644 --- a/homematic-devices/hmip-bbl.js +++ b/homematic-devices/hmip-bbl.js @@ -1 +1 @@ -module.exports = require('./lib/generic-hmip-blind'); +module.exports = require('./lib/generic-hmip-blind.js'); diff --git a/homematic-devices/hmip-bdt.js b/homematic-devices/hmip-bdt.js index e956049..f02115c 100644 --- a/homematic-devices/hmip-bdt.js +++ b/homematic-devices/hmip-bdt.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipBdt extends Accessory { init(config, node) { @@ -21,11 +21,7 @@ module.exports = class HmipBdt extends Accessory { .set('On', (value, callback) => { if (value) { setTimeout(() => { - if (valueBrightness === 0) { - value = 1; - } else { - value = valueBrightness / 100; - } + value = valueBrightness === 0 ? 1 : valueBrightness / 100; this.ccuSetValue(channel + '.LEVEL', value, callback); }, 100); diff --git a/homematic-devices/hmip-broll.js b/homematic-devices/hmip-broll.js index d8777c6..21b2187 100644 --- a/homematic-devices/hmip-broll.js +++ b/homematic-devices/hmip-broll.js @@ -1 +1 @@ -module.exports = require('./lib/generic-hmip-blind'); +module.exports = require('./lib/generic-hmip-blind.js'); diff --git a/homematic-devices/hmip-bsl.js b/homematic-devices/hmip-bsl.js index 4ebd11c..124b040 100644 --- a/homematic-devices/hmip-bsl.js +++ b/homematic-devices/hmip-bsl.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipBsl extends Accessory { init(config) { diff --git a/homematic-devices/hmip-bsm.js b/homematic-devices/hmip-bsm.js index a0bc064..9b52941 100644 --- a/homematic-devices/hmip-bsm.js +++ b/homematic-devices/hmip-bsm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipBsm extends Accessory { init(config) { diff --git a/homematic-devices/hmip-bwth.js b/homematic-devices/hmip-bwth.js index 4965e77..060d3a9 100644 --- a/homematic-devices/hmip-bwth.js +++ b/homematic-devices/hmip-bwth.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipBwth extends Accessory { init(config, node) { @@ -69,25 +69,25 @@ module.exports = class HmipBwth extends Accessory { .set('TargetHeatingCoolingState', (value, callback) => { // 0=off, 1=heat, 3=auto if (value === 0) { - const params = { + const parameters = { CONTROL_MODE: 1, - SET_POINT_TEMPERATURE: 4.5 + SET_POINT_TEMPERATURE: 4.5, }; - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(params)); + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(parameters)); - ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', params]) + ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', parameters]) .then(() => { callback(); }).catch(() => { callback(new Error(hap.HAPServer.Status.SERVICE_COMMUNICATION_FAILURE)); }); } else if (value === 1) { - const params = { + const parameters = { CONTROL_MODE: 1, - SET_POINT_TEMPERATURE: valueSetpoint + SET_POINT_TEMPERATURE: valueSetpoint, }; - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(params)); - ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', params]) + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(parameters)); + ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', parameters]) .then(() => { serviceThermostat.update('TargetTemperature', valueSetpoint); callback(); diff --git a/homematic-devices/hmip-bwth24.js b/homematic-devices/hmip-bwth24.js index dc8142d..c7814e7 100644 --- a/homematic-devices/hmip-bwth24.js +++ b/homematic-devices/hmip-bwth24.js @@ -1 +1 @@ -module.exports = require('./hmip-bwth'); +module.exports = require('./hmip-bwth.js'); diff --git a/homematic-devices/hmip-dbb.js b/homematic-devices/hmip-dbb.js index 026b71a..815db74 100644 --- a/homematic-devices/hmip-dbb.js +++ b/homematic-devices/hmip-dbb.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipDbb extends Accessory { init(config) { @@ -11,10 +11,8 @@ module.exports = class HmipDbb extends Accessory { service.update('ProgrammableSwitchEvent', 0); }); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-drbli4.js b/homematic-devices/hmip-drbli4.js index d8777c6..21b2187 100644 --- a/homematic-devices/hmip-drbli4.js +++ b/homematic-devices/hmip-drbli4.js @@ -1 +1 @@ -module.exports = require('./lib/generic-hmip-blind'); +module.exports = require('./lib/generic-hmip-blind.js'); diff --git a/homematic-devices/hmip-drsi1.js b/homematic-devices/hmip-drsi1.js index 0460eab..9c68f35 100644 --- a/homematic-devices/hmip-drsi1.js +++ b/homematic-devices/hmip-drsi1.js @@ -1,6 +1,6 @@ /* eslint-disable no-new */ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); function addService(type, dp, name) { switch (type) { @@ -12,11 +12,11 @@ function addService(type, dp, name) { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } @@ -80,16 +80,10 @@ module.exports = class HmipDrsi1 { addr = addr + ':' + id; } - let res; + const result = option ? this.config.options[addr] && this.config.options[addr][option] : !(this.config.options[addr] && this.config.options[addr].disabled); - if (option) { - res = this.config.options[addr] && this.config.options[addr][option]; - } else { - res = !(this.config.options[addr] && this.config.options[addr].disabled); - } - - this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); - return res; + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + result); + return result; } constructor(config, node) { diff --git a/homematic-devices/hmip-drsi4.js b/homematic-devices/hmip-drsi4.js index 276881c..70f60a9 100644 --- a/homematic-devices/hmip-drsi4.js +++ b/homematic-devices/hmip-drsi4.js @@ -1,6 +1,6 @@ /* eslint-disable no-new */ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); function addService(type, dp, name) { switch (type) { @@ -12,11 +12,11 @@ function addService(type, dp, name) { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } @@ -81,16 +81,10 @@ module.exports = class HmipDrsi4 { addr = addr + ':' + id; } - let res; + const result = option ? this.config.options[addr] && this.config.options[addr][option] : !(this.config.options[addr] && this.config.options[addr].disabled); - if (option) { - res = this.config.options[addr] && this.config.options[addr][option]; - } else { - res = !(this.config.options[addr] && this.config.options[addr].disabled); - } - - this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); - return res; + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + result); + return result; } constructor(config, node) { diff --git a/homematic-devices/hmip-etrv-2.js b/homematic-devices/hmip-etrv-2.js index 786700f..cedbc83 100644 --- a/homematic-devices/hmip-etrv-2.js +++ b/homematic-devices/hmip-etrv-2.js @@ -1 +1 @@ -module.exports = require('./hmip-etrv'); +module.exports = require('./hmip-etrv.js'); diff --git a/homematic-devices/hmip-etrv-b.js b/homematic-devices/hmip-etrv-b.js index 786700f..cedbc83 100644 --- a/homematic-devices/hmip-etrv-b.js +++ b/homematic-devices/hmip-etrv-b.js @@ -1 +1 @@ -module.exports = require('./hmip-etrv'); +module.exports = require('./hmip-etrv.js'); diff --git a/homematic-devices/hmip-etrv-b1.js b/homematic-devices/hmip-etrv-b1.js index 786700f..cedbc83 100644 --- a/homematic-devices/hmip-etrv-b1.js +++ b/homematic-devices/hmip-etrv-b1.js @@ -1 +1 @@ -module.exports = require('./hmip-etrv'); +module.exports = require('./hmip-etrv.js'); diff --git a/homematic-devices/hmip-etrv-c.js b/homematic-devices/hmip-etrv-c.js index 786700f..cedbc83 100644 --- a/homematic-devices/hmip-etrv-c.js +++ b/homematic-devices/hmip-etrv-c.js @@ -1 +1 @@ -module.exports = require('./hmip-etrv'); +module.exports = require('./hmip-etrv.js'); diff --git a/homematic-devices/hmip-etrv.js b/homematic-devices/hmip-etrv.js index 7fda57e..3cc017f 100644 --- a/homematic-devices/hmip-etrv.js +++ b/homematic-devices/hmip-etrv.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipEtrv extends Accessory { init(config, node) { @@ -68,12 +68,12 @@ module.exports = class HmipEtrv extends Accessory { .set('TargetHeatingCoolingState', (value, callback) => { // 0=off, 1=heat, 3=auto if (value === 0 || value === 1) { - const params = { + const parameters = { CONTROL_MODE: 1, - SET_POINT_TEMPERATURE: value === 0 ? 4.5 : valueSetpoint + SET_POINT_TEMPERATURE: value === 0 ? 4.5 : valueSetpoint, }; - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(params)); - ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', params]).then(() => { + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(parameters)); + ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', parameters]).then(() => { if (valueSetpoint > 4.5) { serviceThermostat.update('TargetTemperature', valueSetpoint); } @@ -111,10 +111,8 @@ module.exports = class HmipEtrv extends Accessory { updateHeatingCoolingState(); }); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); diff --git a/homematic-devices/hmip-fbl.js b/homematic-devices/hmip-fbl.js index d8777c6..21b2187 100644 --- a/homematic-devices/hmip-fbl.js +++ b/homematic-devices/hmip-fbl.js @@ -1 +1 @@ -module.exports = require('./lib/generic-hmip-blind'); +module.exports = require('./lib/generic-hmip-blind.js'); diff --git a/homematic-devices/hmip-fci1.js b/homematic-devices/hmip-fci1.js index b65a65e..8caf9ee 100644 --- a/homematic-devices/hmip-fci1.js +++ b/homematic-devices/hmip-fci1.js @@ -1,16 +1,12 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipFci1 extends Accessory { init(config) { this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }); + .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', value => this.percent(value, null, 1, 1.5)) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-fdt.js b/homematic-devices/hmip-fdt.js index bc59aa0..8c768a8 100644 --- a/homematic-devices/hmip-fdt.js +++ b/homematic-devices/hmip-fdt.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipFdt extends Accessory { init(config, node) { @@ -21,11 +21,7 @@ module.exports = class HmipFdt extends Accessory { .set('On', (value, callback) => { if (value) { setTimeout(() => { - if (valueBrightness === 0) { - value = 1; - } else { - value = valueBrightness / 100; - } + value = valueBrightness === 0 ? 1 : valueBrightness / 100; this.ccuSetValue(channel + '.LEVEL', value, callback); }, 100); diff --git a/homematic-devices/hmip-froll.js b/homematic-devices/hmip-froll.js index d8777c6..21b2187 100644 --- a/homematic-devices/hmip-froll.js +++ b/homematic-devices/hmip-froll.js @@ -1 +1 @@ -module.exports = require('./lib/generic-hmip-blind'); +module.exports = require('./lib/generic-hmip-blind.js'); diff --git a/homematic-devices/hmip-fsi16.js b/homematic-devices/hmip-fsi16.js index f008c51..1d1347c 100644 --- a/homematic-devices/hmip-fsi16.js +++ b/homematic-devices/hmip-fsi16.js @@ -1 +1 @@ -module.exports = require('./hmip-drsi1'); +module.exports = require('./hmip-drsi1.js'); diff --git a/homematic-devices/hmip-fsm.js b/homematic-devices/hmip-fsm.js index f879edf..edff3a4 100644 --- a/homematic-devices/hmip-fsm.js +++ b/homematic-devices/hmip-fsm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipFsm extends Accessory { init(config, node) { @@ -16,11 +16,11 @@ module.exports = class HmipFsm extends Accessory { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } diff --git a/homematic-devices/hmip-fsm16.js b/homematic-devices/hmip-fsm16.js index 5594487..38b1650 100644 --- a/homematic-devices/hmip-fsm16.js +++ b/homematic-devices/hmip-fsm16.js @@ -1 +1 @@ -module.exports = require('./hmip-fsm'); +module.exports = require('./hmip-fsm.js'); diff --git a/homematic-devices/hmip-heating.js b/homematic-devices/hmip-heating.js index f117d4a..fc1b8a5 100644 --- a/homematic-devices/hmip-heating.js +++ b/homematic-devices/hmip-heating.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipHeating extends Accessory { init(config, node) { @@ -46,7 +46,7 @@ module.exports = class HmipHeating extends Accessory { } node.debug(config.deviceAddress + ' ' + group.groupProperties.NAME + ' ' + group.groupType.id + ' has ' + group.groupMembers.length + ' members'); - group.groupMembers.forEach(member => { + for (const member of group.groupMembers) { if (member.memberType.id.startsWith('RADIATOR')) { valveDevices.push('HmIP-RF.' + member.id); valueDevice = valueDevice || ('HmIP-RF.' + member.id); @@ -57,7 +57,7 @@ module.exports = class HmipHeating extends Accessory { lowbatDps['HmIP-RF.' + (member.id.split(':')[0]) + ':0.LOW_BAT'] = false; node.debug(config.deviceAddress + ' member ' + member.memberType.id + ' ' + member.id); - }); + } if (valueDevice) { node.debug(config.deviceAddress + ' valueDevice ' + valueDevice); @@ -104,13 +104,13 @@ module.exports = class HmipHeating extends Accessory { .set('TargetHeatingCoolingState', (value, callback) => { // 0=off, 1=heat, 3=auto if (value === 0) { - const params = { + const parameters = { CONTROL_MODE: 1, - SET_POINT_TEMPERATURE: 4.5 + SET_POINT_TEMPERATURE: 4.5, }; - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(params)); + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(parameters)); - ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', params]) + ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', parameters]) .then(() => { setpointMode = 1; callback(); @@ -118,12 +118,12 @@ module.exports = class HmipHeating extends Accessory { callback(new Error(hap.HAPServer.Status.SERVICE_COMMUNICATION_FAILURE)); }); } else if (value === 1) { - const params = { + const parameters = { CONTROL_MODE: 1, - SET_POINT_TEMPERATURE: valueSetpoint + SET_POINT_TEMPERATURE: valueSetpoint, }; - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(params)); - ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', params]) + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(parameters)); + ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', parameters]) .then(() => { serviceThermostat.update('TargetTemperature', valueSetpoint); setpointMode = 1; @@ -148,23 +148,24 @@ module.exports = class HmipHeating extends Accessory { serviceThermostat.update('TargetHeatingCoolingState', targetState()); } - valveDevices.forEach(valveStateDevice => { + for (const valveStateDevice of valveDevices) { const datapointLevel = valveStateDevice + '.LEVEL'; this.subscribe(datapointLevel, value => { levels[datapointLevel] = value; let max = 0; - Object.keys(levels).forEach(dp => { + for (const dp of Object.keys(levels)) { if (levels[dp] > max) { max = levels[dp]; } - }); + } + if (level !== max) { level = max; node.debug('update ' + config.name + ' level ' + level); updateHeatingCoolingState(); } }); - }); + } this.subscribe(valueDevice + '.SET_POINT_MODE', value => { setpointMode = value; @@ -172,18 +173,19 @@ module.exports = class HmipHeating extends Accessory { updateHeatingCoolingState(); }); - const batteryService = this.addService('BatteryService', config.name, 'Battery'); - Object.keys(lowbatDps).forEach(dp => { + const battery = this.addService('Battery', config.name, 'Battery'); + for (const dp of Object.keys(lowbatDps)) { this.subscribe(dp, value => { lowbatDps[dp] = value; let lowbat = false; - Object.keys(lowbatDps).forEach(ldp => { + for (const ldp of Object.keys(lowbatDps)) { lowbat = lowbat || lowbatDps[ldp]; - }); - batteryService.update('StatusLowBattery', lowbat ? hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); - batteryService.update('BatteryLevel', lowbat ? 0 : 100); + } + + battery.update('StatusLowBattery', lowbat ? hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + battery.update('BatteryLevel', lowbat ? 0 : 100); }); - }); + } if (this.option('HumiditySensor') && humidityDp) { this.addService('HumiditySensor', config.name) diff --git a/homematic-devices/hmip-mod-ho.js b/homematic-devices/hmip-mod-ho.js index 69ebea9..6c44854 100644 --- a/homematic-devices/hmip-mod-ho.js +++ b/homematic-devices/hmip-mod-ho.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipModHo extends Accessory { init(config) { // , node) { diff --git a/homematic-devices/hmip-mod-oc8.js b/homematic-devices/hmip-mod-oc8.js index cb5de45..2d9ce12 100644 --- a/homematic-devices/hmip-mod-oc8.js +++ b/homematic-devices/hmip-mod-oc8.js @@ -1,6 +1,6 @@ -/* eslint-disable no-new */ +/* eslint-disable no-new, */ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); function addService(type, dp, name) { switch (type) { @@ -12,11 +12,11 @@ function addService(type, dp, name) { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } @@ -81,16 +81,10 @@ module.exports = class HmipModOc8 { addr = addr + ':' + id; } - let res; + const result = option ? this.config.options[addr] && this.config.options[addr][option] : !(this.config.options[addr] && this.config.options[addr].disabled); - if (option) { - res = this.config.options[addr] && this.config.options[addr][option]; - } else { - res = !(this.config.options[addr] && this.config.options[addr].disabled); - } - - this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); - return res; + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + result); + return result; } constructor(config, node) { diff --git a/homematic-devices/hmip-mod-tm.js b/homematic-devices/hmip-mod-tm.js index cfe71cb..19f9c07 100644 --- a/homematic-devices/hmip-mod-tm.js +++ b/homematic-devices/hmip-mod-tm.js @@ -1 +1 @@ -module.exports = require('./hmip-mod-ho'); +module.exports = require('./hmip-mod-ho.js'); diff --git a/homematic-devices/hmip-pcbs-bat.js b/homematic-devices/hmip-pcbs-bat.js index 1380858..4f59712 100644 --- a/homematic-devices/hmip-pcbs-bat.js +++ b/homematic-devices/hmip-pcbs-bat.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipPcbsBat extends Accessory { init(config) { @@ -8,10 +8,8 @@ module.exports = class HmipPcbsBat extends Accessory { .get('On', config.deviceAddress + ':3.STATE') .set('On', config.deviceAddress + ':3.STATE'); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-pcbs.js b/homematic-devices/hmip-pcbs.js index f6ac031..551fe81 100644 --- a/homematic-devices/hmip-pcbs.js +++ b/homematic-devices/hmip-pcbs.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipPcbs extends Accessory { init(config) { diff --git a/homematic-devices/hmip-pcbs2.js b/homematic-devices/hmip-pcbs2.js index b03fed7..d2847b8 100644 --- a/homematic-devices/hmip-pcbs2.js +++ b/homematic-devices/hmip-pcbs2.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipPcbs2 extends Accessory { init(config, node) { diff --git a/homematic-devices/hmip-pdt.js b/homematic-devices/hmip-pdt.js index 401b7c1..004aaf8 100644 --- a/homematic-devices/hmip-pdt.js +++ b/homematic-devices/hmip-pdt.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipFdt extends Accessory { init(config, node) { @@ -21,11 +21,7 @@ module.exports = class HmipFdt extends Accessory { .set('On', (value, callback) => { if (value) { setTimeout(() => { - if (valueBrightness === 0) { - value = 1; - } else { - value = valueBrightness / 100; - } + value = valueBrightness === 0 ? 1 : valueBrightness / 100; this.ccuSetValue(channel + '.LEVEL', value, callback); }, 100); diff --git a/homematic-devices/hmip-ps.js b/homematic-devices/hmip-ps.js index 1b9ec59..ab201f5 100644 --- a/homematic-devices/hmip-ps.js +++ b/homematic-devices/hmip-ps.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipPs extends Accessory { init(config, node) { @@ -16,11 +16,11 @@ module.exports = class HmipPs extends Accessory { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } diff --git a/homematic-devices/hmip-psm-ch.js b/homematic-devices/hmip-psm-ch.js index a9534a3..023ff7b 100644 --- a/homematic-devices/hmip-psm-ch.js +++ b/homematic-devices/hmip-psm-ch.js @@ -1 +1 @@ -module.exports = require('./hmip-psm'); +module.exports = require('./hmip-psm.js'); diff --git a/homematic-devices/hmip-psm-it.js b/homematic-devices/hmip-psm-it.js index a9534a3..023ff7b 100644 --- a/homematic-devices/hmip-psm-it.js +++ b/homematic-devices/hmip-psm-it.js @@ -1 +1 @@ -module.exports = require('./hmip-psm'); +module.exports = require('./hmip-psm.js'); diff --git a/homematic-devices/hmip-psm-pe.js b/homematic-devices/hmip-psm-pe.js index a9534a3..023ff7b 100644 --- a/homematic-devices/hmip-psm-pe.js +++ b/homematic-devices/hmip-psm-pe.js @@ -1 +1 @@ -module.exports = require('./hmip-psm'); +module.exports = require('./hmip-psm.js'); diff --git a/homematic-devices/hmip-psm-uk.js b/homematic-devices/hmip-psm-uk.js index a9534a3..023ff7b 100644 --- a/homematic-devices/hmip-psm-uk.js +++ b/homematic-devices/hmip-psm-uk.js @@ -1 +1 @@ -module.exports = require('./hmip-psm'); +module.exports = require('./hmip-psm.js'); diff --git a/homematic-devices/hmip-psm.js b/homematic-devices/hmip-psm.js index 53ae7a5..cadd7f0 100644 --- a/homematic-devices/hmip-psm.js +++ b/homematic-devices/hmip-psm.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipPsm extends Accessory { init(config, node) { @@ -16,11 +16,11 @@ module.exports = class HmipPsm extends Accessory { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } diff --git a/homematic-devices/hmip-sam.js b/homematic-devices/hmip-sam.js index 63a1148..08853a5 100644 --- a/homematic-devices/hmip-sam.js +++ b/homematic-devices/hmip-sam.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSam extends Accessory { init(config) { @@ -34,9 +34,7 @@ module.exports = class HmipSam extends Accessory { }, 100); }); - service.get('ObstructionDetected', config.deviceAddress + ':0.SENSOR_ERROR', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':0.SENSOR_ERROR', value => Boolean(value)); break; @@ -70,31 +68,22 @@ module.exports = class HmipSam extends Accessory { }, 100); }); - service.get('ObstructionDetected', config.deviceAddress + ':0.SENSOR_ERROR', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':0.SENSOR_ERROR', value => Boolean(value)); break; default: this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':1.MOTION', (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) - - .get('StatusTampered', config.deviceAddress + ':0.SENSOR_ERROR', value => { - return Boolean(value); - }) + .get('ContactSensorState', config.deviceAddress + ':1.MOTION', (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) + .get('StatusTampered', config.deviceAddress + ':0.SENSOR_ERROR', value => Boolean(value)) .fault([ - config.deviceAddress + ':0.ERROR_CODE' + config.deviceAddress + ':0.ERROR_CODE', ]); } - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', value => this.percent(value, null, 2, 3)) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-sci.js b/homematic-devices/hmip-sci.js index 2206806..f0f5d68 100644 --- a/homematic-devices/hmip-sci.js +++ b/homematic-devices/hmip-sci.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSci extends Accessory { init(config) { @@ -34,9 +34,7 @@ module.exports = class HmipSci extends Accessory { }, 100); }); - service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)); break; @@ -70,31 +68,22 @@ module.exports = class HmipSci extends Accessory { }, 100); }); - service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)); break; default: this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) - - .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }) + .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) + .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)) .fault([ - config.deviceAddress + ':0.ERROR_CODE' + config.deviceAddress + ':0.ERROR_CODE', ]); } - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', value => this.percent(value, null, 2, 3)) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-slo.js b/homematic-devices/hmip-slo.js index dfc8c6d..33e0173 100644 --- a/homematic-devices/hmip-slo.js +++ b/homematic-devices/hmip-slo.js @@ -1,14 +1,12 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSlo extends Accessory { init(config) { this.addService('LightSensor', config.name) .get('CurrentAmbientLightLevel', config.deviceAddress + ':1.CURRENT_ILLUMINATION'); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-smi.js b/homematic-devices/hmip-smi.js index 131b65c..96724f8 100644 --- a/homematic-devices/hmip-smi.js +++ b/homematic-devices/hmip-smi.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSmi extends Accessory { init(config) { @@ -6,10 +6,8 @@ module.exports = class HmipSmi extends Accessory { .get('MotionDetected', config.deviceAddress + ':1.MOTION') .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE'); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); diff --git a/homematic-devices/hmip-smi55.js b/homematic-devices/hmip-smi55.js index 44882b6..6b76abc 100644 --- a/homematic-devices/hmip-smi55.js +++ b/homematic-devices/hmip-smi55.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSmi55 extends Accessory { init(config) { @@ -6,10 +6,8 @@ module.exports = class HmipSmi55 extends Accessory { .get('MotionDetected', config.deviceAddress + ':3.MOTION') .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE'); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); diff --git a/homematic-devices/hmip-smo-a.js b/homematic-devices/hmip-smo-a.js index 7af6dda..2fea103 100644 --- a/homematic-devices/hmip-smo-a.js +++ b/homematic-devices/hmip-smo-a.js @@ -1 +1 @@ -module.exports = require('./hmip-smi'); +module.exports = require('./hmip-smi.js'); diff --git a/homematic-devices/hmip-smo.js b/homematic-devices/hmip-smo.js index 7af6dda..2fea103 100644 --- a/homematic-devices/hmip-smo.js +++ b/homematic-devices/hmip-smo.js @@ -1 +1 @@ -module.exports = require('./hmip-smi'); +module.exports = require('./hmip-smi.js'); diff --git a/homematic-devices/hmip-spdr.js b/homematic-devices/hmip-spdr.js index 1638c35..9f08ea6 100644 --- a/homematic-devices/hmip-spdr.js +++ b/homematic-devices/hmip-spdr.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSpdr extends Accessory { init(config, node) { @@ -26,10 +26,8 @@ module.exports = class HmipSpdr extends Accessory { update(); }); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-spi.js b/homematic-devices/hmip-spi.js index fc9e55c..5e07e99 100644 --- a/homematic-devices/hmip-spi.js +++ b/homematic-devices/hmip-spi.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSmi extends Accessory { init(config) { @@ -6,10 +6,8 @@ module.exports = class HmipSmi extends Accessory { .get('OccupancyDetected', config.deviceAddress + ':1.PRESENCE_DETECTION_STATE') .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE'); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); diff --git a/homematic-devices/hmip-srh.js b/homematic-devices/hmip-srh.js index e943186..8a5995e 100644 --- a/homematic-devices/hmip-srh.js +++ b/homematic-devices/hmip-srh.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSrh extends Accessory { init(config) { @@ -7,8 +7,8 @@ module.exports = class HmipSrh extends Accessory { let service; let actualValue; - function convert(val) { - switch (val) { + function convert(value) { + switch (value) { case 1: return 25; case 2: @@ -46,31 +46,22 @@ module.exports = class HmipSrh extends Accessory { }, 20); }); - service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)); break; default: this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => { - return value > 0 ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) - - .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }) + .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => value > 0 ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) + .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)) .fault([ - config.deviceAddress + ':0.ERROR_CODE' + config.deviceAddress + ':0.ERROR_CODE', ]); } - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', value => this.percent(value, null, 1, 1.5)) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-ste2-pcb.js b/homematic-devices/hmip-ste2-pcb.js index 60e7f7e..f881c87 100644 --- a/homematic-devices/hmip-ste2-pcb.js +++ b/homematic-devices/hmip-ste2-pcb.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSte2Pcb extends Accessory { init(config, node) { @@ -18,9 +18,7 @@ module.exports = class HmipSte2Pcb extends Accessory { this.addService('TemperatureSensor', name) .setProps('CurrentTemperature', {minValue: -150, maxValue: 150}) .get('CurrentTemperature', dp) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }); + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL); } } }; diff --git a/homematic-devices/hmip-sth.js b/homematic-devices/hmip-sth.js index 60d2967..9220c52 100644 --- a/homematic-devices/hmip-sth.js +++ b/homematic-devices/hmip-sth.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipWth extends Accessory { init(config, node) { @@ -79,13 +79,13 @@ module.exports = class HmipWth extends Accessory { .set('TargetHeatingCoolingState', (value, callback) => { // 0=off, 1=heat, 3=auto if (value === 0) { - const params = { + const parameters = { CONTROL_MODE: 1, - SET_POINT_TEMPERATURE: 4.5 + SET_POINT_TEMPERATURE: 4.5, }; - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(params)); + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(parameters)); - ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', params]) + ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', parameters]) .then(() => { callback(); }).catch(() => { @@ -95,13 +95,13 @@ module.exports = class HmipWth extends Accessory { if (setpointMode === 1) { callback(); } else { - const params = { + const parameters = { CONTROL_MODE: 1, - SET_POINT_TEMPERATURE: valueSetpoint + SET_POINT_TEMPERATURE: valueSetpoint, }; - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(params)); - ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', params]) + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(parameters)); + ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', parameters]) .then(() => { serviceThermostat.update('TargetTemperature', valueSetpoint); callback(); @@ -110,12 +110,12 @@ module.exports = class HmipWth extends Accessory { }); } } else { - const val = value === 3 ? 0 : 1; - if (setpointMode === val) { + const value_ = value === 3 ? 0 : 1; + if (setpointMode === value_) { callback(); } else { node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1.CONTROL_MODE ' + (value === 3 ? 0 : 1)); - ccu.setValue(config.iface, config.description.ADDRESS + ':1', 'CONTROL_MODE', val) + ccu.setValue(config.iface, config.description.ADDRESS + ':1', 'CONTROL_MODE', value_) .then(() => { callback(); }).catch(() => { @@ -125,24 +125,25 @@ module.exports = class HmipWth extends Accessory { } }); - links.forEach(link => { + for (const link of links) { const valveStateDevice = link.split(':')[0]; const datapointLevel = config.iface + '.' + valveStateDevice + ':1.LEVEL'; this.subscribe(datapointLevel, value => { levels[datapointLevel] = value; let max = 0; - Object.keys(levels).forEach(dp => { + for (const dp of Object.keys(levels)) { if (levels[dp] > max) { max = levels[dp]; } - }); + } + if (level !== max) { level = max; node.debug('update ' + config.name + ' level ' + level); updateHeatingCoolingState(); } }); - }); + } this.subscribe(config.deviceAddress + ':1.SET_POINT_MODE', value => { setpointMode = value; @@ -154,10 +155,10 @@ module.exports = class HmipWth extends Accessory { this.addService('Switch', 'Boost ' + config.name, 'Boost') .set('On', (value, callback) => { this.ccuSetValue(config.deviceAddress + ':1.BOOST_MODE', value, callback); - links.forEach(link => { + for (const link of links) { const linkedDevice = link.split(':')[0]; this.ccuSetValue(config.iface + '.' + linkedDevice + ':1.BOOST_MODE', value); - }); + } }) .get('On', config.deviceAddress + ':1.BOOST_MODE'); } @@ -167,10 +168,8 @@ module.exports = class HmipWth extends Accessory { .get('CurrentTemperature', config.deviceAddress + ':1.ACTUAL_TEMPERATURE'); } - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); diff --git a/homematic-devices/hmip-sthd.js b/homematic-devices/hmip-sthd.js index 82c8718..9daaf13 100644 --- a/homematic-devices/hmip-sthd.js +++ b/homematic-devices/hmip-sthd.js @@ -1 +1 @@ -module.exports = require('./hmip-sth'); +module.exports = require('./hmip-sth.js'); diff --git a/homematic-devices/hmip-stho-a.js b/homematic-devices/hmip-stho-a.js index 8808a2f..f3f5dad 100644 --- a/homematic-devices/hmip-stho-a.js +++ b/homematic-devices/hmip-stho-a.js @@ -1 +1 @@ -module.exports = require('./hmip-stho'); +module.exports = require('./hmip-stho.js'); diff --git a/homematic-devices/hmip-stho.js b/homematic-devices/hmip-stho.js index 9a15fea..bcfff27 100644 --- a/homematic-devices/hmip-stho.js +++ b/homematic-devices/hmip-stho.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipStho extends Accessory { init(config) { @@ -6,10 +6,8 @@ module.exports = class HmipStho extends Accessory { .setProps('CurrentTemperature', {minValue: -40, maxValue: 80}) .get('CurrentTemperature', config.deviceAddress + ':1.ACTUAL_TEMPERATURE'); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); diff --git a/homematic-devices/hmip-swd.js b/homematic-devices/hmip-swd.js index 5a0e0ed..414a517 100644 --- a/homematic-devices/hmip-swd.js +++ b/homematic-devices/hmip-swd.js @@ -1,18 +1,14 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSwd extends Accessory { init(config) { this.addService('LeakSensor', config.name) - .get('LeakDetected', config.deviceAddress + ':1.ALARMSTATE', (value, c) => { - return value ? c.LEAK_DETECTED : c.LEAK_NOT_DETECTED; - }) + .get('LeakDetected', config.deviceAddress + ':1.ALARMSTATE', (value, c) => value ? c.LEAK_DETECTED : c.LEAK_NOT_DETECTED) .get('StatusTampered', config.deviceAddress + ':0.ERROR_NON_FLAT_POSITIONING') .fault([config.deviceAddress + ':0.ERROR_CODE']); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', value => this.percent(value, 1, 1.5)) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-swdm-b.js b/homematic-devices/hmip-swdm-b.js index 1a9bb2a..859b9e3 100644 --- a/homematic-devices/hmip-swdm-b.js +++ b/homematic-devices/hmip-swdm-b.js @@ -1 +1 @@ -module.exports = require('./hmip-swdo'); +module.exports = require('./hmip-swdo.js'); diff --git a/homematic-devices/hmip-swdm-b1.js b/homematic-devices/hmip-swdm-b1.js index 1a9bb2a..859b9e3 100644 --- a/homematic-devices/hmip-swdm-b1.js +++ b/homematic-devices/hmip-swdm-b1.js @@ -1 +1 @@ -module.exports = require('./hmip-swdo'); +module.exports = require('./hmip-swdo.js'); diff --git a/homematic-devices/hmip-swdm-b2.js b/homematic-devices/hmip-swdm-b2.js index 1a9bb2a..859b9e3 100644 --- a/homematic-devices/hmip-swdm-b2.js +++ b/homematic-devices/hmip-swdm-b2.js @@ -1 +1 @@ -module.exports = require('./hmip-swdo'); +module.exports = require('./hmip-swdo.js'); diff --git a/homematic-devices/hmip-swdm.js b/homematic-devices/hmip-swdm.js index 1a9bb2a..859b9e3 100644 --- a/homematic-devices/hmip-swdm.js +++ b/homematic-devices/hmip-swdm.js @@ -1 +1 @@ -module.exports = require('./hmip-swdo'); +module.exports = require('./hmip-swdo.js'); diff --git a/homematic-devices/hmip-swdo-i.js b/homematic-devices/hmip-swdo-i.js index 1a9bb2a..859b9e3 100644 --- a/homematic-devices/hmip-swdo-i.js +++ b/homematic-devices/hmip-swdo-i.js @@ -1 +1 @@ -module.exports = require('./hmip-swdo'); +module.exports = require('./hmip-swdo.js'); diff --git a/homematic-devices/hmip-swdo-pl.js b/homematic-devices/hmip-swdo-pl.js index dcc48e7..5572d19 100644 --- a/homematic-devices/hmip-swdo-pl.js +++ b/homematic-devices/hmip-swdo-pl.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSwdoPl extends Accessory { init(config) { @@ -34,9 +34,7 @@ module.exports = class HmipSwdoPl extends Accessory { }, 100); }); - service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)); break; @@ -70,31 +68,22 @@ module.exports = class HmipSwdoPl extends Accessory { }, 100); }); - service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)); break; default: this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) - - .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }) + .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) + .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)) .fault([ - config.deviceAddress + ':0.ERROR_CODE' + config.deviceAddress + ':0.ERROR_CODE', ]); } - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', value => this.percent(value, null, 2, 3)) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-swdo.js b/homematic-devices/hmip-swdo.js index 08b5754..93b0ce0 100644 --- a/homematic-devices/hmip-swdo.js +++ b/homematic-devices/hmip-swdo.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSwdo extends Accessory { init(config) { @@ -34,9 +34,7 @@ module.exports = class HmipSwdo extends Accessory { }, 100); }); - service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)); break; @@ -70,31 +68,22 @@ module.exports = class HmipSwdo extends Accessory { }, 100); }); - service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }); + service.get('ObstructionDetected', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)); break; default: this.addService('ContactSensor', config.name) - .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }) - - .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE', value => { - return Boolean(value); - }) + .get('ContactSensorState', config.deviceAddress + ':1.STATE', (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED) + .get('StatusTampered', config.deviceAddress + ':0.SABOTAGE', value => Boolean(value)) .fault([ - config.deviceAddress + ':0.ERROR_CODE' + config.deviceAddress + ':0.ERROR_CODE', ]); } - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', value => this.percent(value, null, 1, 1.5)) .update('ChargingState', 2); } diff --git a/homematic-devices/hmip-swo-b.js b/homematic-devices/hmip-swo-b.js index 844ac07..e5d9acf 100644 --- a/homematic-devices/hmip-swo-b.js +++ b/homematic-devices/hmip-swo-b.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSwo extends Accessory { init(config) { @@ -6,13 +6,9 @@ module.exports = class HmipSwo extends Accessory { .setProps('CurrentTemperature', {minValue: -40, maxValue: 80}) .get('CurrentTemperature', config.deviceAddress + ':1.ACTUAL_TEMPERATURE'); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - .get('BatteryLevel', config.deviceAddress + ':0.LOW_BAT', value => { - return value ? 0 : 100; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('BatteryLevel', config.deviceAddress + ':0.LOW_BAT', value => value ? 0 : 100) .update('ChargingState', 2); if (this.option('HumiditySensor')) { diff --git a/homematic-devices/hmip-swo-pl.js b/homematic-devices/hmip-swo-pl.js index 127db62..5f22786 100644 --- a/homematic-devices/hmip-swo-pl.js +++ b/homematic-devices/hmip-swo-pl.js @@ -1 +1 @@ -module.exports = require('./hmip-swo-b'); +module.exports = require('./hmip-swo-b.js'); diff --git a/homematic-devices/hmip-swo-pr.js b/homematic-devices/hmip-swo-pr.js index 127db62..5f22786 100644 --- a/homematic-devices/hmip-swo-pr.js +++ b/homematic-devices/hmip-swo-pr.js @@ -1 +1 @@ -module.exports = require('./hmip-swo-b'); +module.exports = require('./hmip-swo-b.js'); diff --git a/homematic-devices/hmip-swsd.js b/homematic-devices/hmip-swsd.js index 03bdcbe..ca3803c 100644 --- a/homematic-devices/hmip-swsd.js +++ b/homematic-devices/hmip-swsd.js @@ -1,18 +1,10 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipSecSwsd extends Accessory { init(config) { this.addService('SmokeSensor', config.name) - .get('SmokeDetected', config.deviceAddress + ':1.SMOKE_DETECTOR_ALARM_STATUS', (value, c) => { - return value ? c.SMOKE_DETECTED : c.SMOKE_NOT_DETECTED; - }) - - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) - - .get('StatusFault', config.deviceAddress + ':1.SMOKE_DETECTOR_TEST_RESULT', value => { - return value === 2; - }); + .get('SmokeDetected', config.deviceAddress + ':1.SMOKE_DETECTOR_ALARM_STATUS', (value, c) => value ? c.SMOKE_DETECTED : c.SMOKE_NOT_DETECTED) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) + .get('StatusFault', config.deviceAddress + ':1.SMOKE_DETECTOR_TEST_RESULT', value => value === 2); } }; diff --git a/homematic-devices/hmip-whs2.js b/homematic-devices/hmip-whs2.js index 3f538e0..a8b52bd 100644 --- a/homematic-devices/hmip-whs2.js +++ b/homematic-devices/hmip-whs2.js @@ -1 +1 @@ -module.exports = require('./hmipw-drs4'); +module.exports = require('./hmipw-drs4.js'); diff --git a/homematic-devices/hmip-wth-2.js b/homematic-devices/hmip-wth-2.js index 29d3ecd..082c0de 100644 --- a/homematic-devices/hmip-wth-2.js +++ b/homematic-devices/hmip-wth-2.js @@ -1 +1 @@ -module.exports = require('./hmip-wth'); +module.exports = require('./hmip-wth.js'); diff --git a/homematic-devices/hmip-wth-b.js b/homematic-devices/hmip-wth-b.js index 29d3ecd..082c0de 100644 --- a/homematic-devices/hmip-wth-b.js +++ b/homematic-devices/hmip-wth-b.js @@ -1 +1 @@ -module.exports = require('./hmip-wth'); +module.exports = require('./hmip-wth.js'); diff --git a/homematic-devices/hmip-wth.js b/homematic-devices/hmip-wth.js index 0665cea..ae28059 100644 --- a/homematic-devices/hmip-wth.js +++ b/homematic-devices/hmip-wth.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipWth extends Accessory { init(config, node) { @@ -72,13 +72,13 @@ module.exports = class HmipWth extends Accessory { .set('TargetHeatingCoolingState', (value, callback) => { // 0=off, 1=heat, 3=auto if (value === 0) { - const params = { + const parameters = { CONTROL_MODE: 1, - SET_POINT_TEMPERATURE: 4.5 + SET_POINT_TEMPERATURE: 4.5, }; - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(params)); + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(parameters)); - ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', params]) + ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', parameters]) .then(() => { callback(); }).catch(() => { @@ -88,12 +88,12 @@ module.exports = class HmipWth extends Accessory { if (setpointMode === 1) { callback(); } else { - const params = { + const parameters = { CONTROL_MODE: 1, - SET_POINT_TEMPERATURE: valueSetpoint + SET_POINT_TEMPERATURE: valueSetpoint, }; - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(params)); - ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', params]) + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1 ' + JSON.stringify(parameters)); + ccu.methodCall(config.iface, 'putParamset', [config.description.ADDRESS + ':1', 'VALUES', parameters]) .then(() => { serviceThermostat.update('TargetTemperature', valueSetpoint); callback(); @@ -102,12 +102,12 @@ module.exports = class HmipWth extends Accessory { }); } } else { - const val = value === 3 ? 0 : 1; - if (setpointMode === val) { + const value_ = value === 3 ? 0 : 1; + if (setpointMode === value_) { callback(); } else { - node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1.CONTROL_MODE ' + val); - ccu.setValue(config.iface, config.description.ADDRESS + ':1', 'CONTROL_MODE', val) + node.debug('set ' + config.name + ' (' + subtypeThermostat + ') TargetHeatingCoolingState ' + value + ' -> ' + config.description.ADDRESS + ':1.CONTROL_MODE ' + value_); + ccu.setValue(config.iface, config.description.ADDRESS + ':1', 'CONTROL_MODE', value_) .then(() => { callback(); }).catch(() => { @@ -122,24 +122,25 @@ module.exports = class HmipWth extends Accessory { serviceThermostat.update('TargetHeatingCoolingState', targetState()); } - links.forEach(link => { + for (const link of links) { const valveStateDevice = link.split(':')[0]; const datapointLevel = config.iface + '.' + valveStateDevice + ':1.LEVEL'; this.subscribe(datapointLevel, value => { levels[datapointLevel] = value; let max = 0; - Object.keys(levels).forEach(dp => { + for (const dp of Object.keys(levels)) { if (levels[dp] > max) { max = levels[dp]; } - }); + } + if (level !== max) { level = max; node.debug('update ' + config.name + ' level ' + level); updateHeatingCoolingState(); } }); - }); + } this.subscribe(config.deviceAddress + ':1.SET_POINT_MODE', value => { setpointMode = value; @@ -147,10 +148,8 @@ module.exports = class HmipWth extends Accessory { updateHeatingCoolingState(); }); - this.addService('BatteryService', config.name) - .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => { - return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL; - }) + this.addService('Battery', config.name) + .get('StatusLowBattery', config.deviceAddress + ':0.LOW_BAT', (value, c) => value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL) .get('BatteryLevel', config.deviceAddress + ':0.OPERATING_VOLTAGE', this.percent) .update('ChargingState', 2); @@ -163,10 +162,10 @@ module.exports = class HmipWth extends Accessory { this.addService('Switch', 'Boost ' + config.name, 'Boost') .set('On', (value, callback) => { this.ccuSetValue(config.deviceAddress + ':1.BOOST_MODE', value, callback); - links.forEach(link => { + for (const link of links) { const linkedDevice = link.split(':')[0]; this.ccuSetValue(config.iface + '.' + linkedDevice + ':1.BOOST_MODE', value); - }); + } }) .get('On', config.deviceAddress + ':1.BOOST_MODE'); } diff --git a/homematic-devices/hmipw-drbl4.js b/homematic-devices/hmipw-drbl4.js index d8777c6..21b2187 100644 --- a/homematic-devices/hmipw-drbl4.js +++ b/homematic-devices/hmipw-drbl4.js @@ -1 +1 @@ -module.exports = require('./lib/generic-hmip-blind'); +module.exports = require('./lib/generic-hmip-blind.js'); diff --git a/homematic-devices/hmipw-drd3.js b/homematic-devices/hmipw-drd3.js index 18d5b08..495cf2d 100644 --- a/homematic-devices/hmipw-drd3.js +++ b/homematic-devices/hmipw-drd3.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmipwDrd extends Accessory { init(config, node) { @@ -23,11 +23,7 @@ module.exports = class HmipwDrd extends Accessory { .set('On', (value, callback) => { if (value) { setTimeout(() => { - if (valueBrightness === 0) { - value = 1; - } else { - value = valueBrightness / 100; - } + value = valueBrightness === 0 ? 1 : valueBrightness / 100; this.ccuSetValue(channel + '.LEVEL', value, callback); }, 100); diff --git a/homematic-devices/hmipw-dri16.js b/homematic-devices/hmipw-dri16.js index d6fbdf1..a7a1756 100644 --- a/homematic-devices/hmipw-dri16.js +++ b/homematic-devices/hmipw-dri16.js @@ -1,6 +1,6 @@ /* eslint-disable no-new */ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); function addService(type, name, dp) { let service; @@ -38,9 +38,7 @@ function addService(type, name, dp) { default: this.addService('ContactSensor', name) - .get('ContactSensorState', dp, (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }); + .get('ContactSensorState', dp, (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED); } } @@ -78,16 +76,10 @@ module.exports = class GenericContactSensor { addr = addr + ':' + id; } - let res; + const result = option ? this.config.options[addr] && this.config.options[addr][option] : !(this.config.options[addr] && this.config.options[addr].disabled); - if (option) { - res = this.config.options[addr] && this.config.options[addr][option]; - } else { - res = !(this.config.options[addr] && this.config.options[addr].disabled); - } - - this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); - return res; + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + result); + return result; } constructor(config, node) { diff --git a/homematic-devices/hmipw-dri32.js b/homematic-devices/hmipw-dri32.js index db9fab7..f6b0d5d 100644 --- a/homematic-devices/hmipw-dri32.js +++ b/homematic-devices/hmipw-dri32.js @@ -1 +1 @@ -module.exports = require('./hmipw-dri16'); +module.exports = require('./hmipw-dri16.js'); diff --git a/homematic-devices/hmipw-drs4.js b/homematic-devices/hmipw-drs4.js index 66bf0b1..b27c4b2 100644 --- a/homematic-devices/hmipw-drs4.js +++ b/homematic-devices/hmipw-drs4.js @@ -1,6 +1,6 @@ /* eslint-disable no-new */ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); function addService(type, dp, name) { switch (type) { @@ -12,11 +12,11 @@ function addService(type, dp, name) { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } @@ -81,16 +81,10 @@ module.exports = class HmipwDrs { addr = addr + ':' + id; } - let res; + const result = option ? this.config.options[addr] && this.config.options[addr][option] : !(this.config.options[addr] && this.config.options[addr].disabled); - if (option) { - res = this.config.options[addr] && this.config.options[addr][option]; - } else { - res = !(this.config.options[addr] && this.config.options[addr].disabled); - } - - this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); - return res; + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + result); + return result; } constructor(config, node) { diff --git a/homematic-devices/hmipw-drs8.js b/homematic-devices/hmipw-drs8.js index 3f538e0..a8b52bd 100644 --- a/homematic-devices/hmipw-drs8.js +++ b/homematic-devices/hmipw-drs8.js @@ -1 +1 @@ -module.exports = require('./hmipw-drs4'); +module.exports = require('./hmipw-drs4.js'); diff --git a/homematic-devices/hmipw-fio6.js b/homematic-devices/hmipw-fio6.js index 43f517e..9864b27 100644 --- a/homematic-devices/hmipw-fio6.js +++ b/homematic-devices/hmipw-fio6.js @@ -1,6 +1,6 @@ /* eslint-disable no-new */ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); function addInputService(type, name, dp) { let service; @@ -38,9 +38,7 @@ function addInputService(type, name, dp) { default: this.addService('ContactSensor', name) - .get('ContactSensorState', dp, (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }); + .get('ContactSensorState', dp, (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED); } } @@ -54,11 +52,11 @@ function addOutputService(type, dp, name) { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } @@ -145,16 +143,10 @@ module.exports = class HmipwFio { addr = addr + ':' + id; } - let res; - - if (option) { - res = this.config.options[addr] && this.config.options[addr][option]; - } else { - res = !(this.config.options[addr] && this.config.options[addr].disabled); - } + const result = option ? this.config.options[addr] && this.config.options[addr][option] : !(this.config.options[addr] && this.config.options[addr].disabled); - this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); - return res; + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + result); + return result; } constructor(config, node) { diff --git a/homematic-devices/hmipw-smi55.js b/homematic-devices/hmipw-smi55.js index 77b2e06..d39de23 100644 --- a/homematic-devices/hmipw-smi55.js +++ b/homematic-devices/hmipw-smi55.js @@ -1 +1 @@ -module.exports = require('./hmip-smi55'); +module.exports = require('./hmip-smi55.js'); diff --git a/homematic-devices/hmipw-wth.js b/homematic-devices/hmipw-wth.js index 29d3ecd..082c0de 100644 --- a/homematic-devices/hmipw-wth.js +++ b/homematic-devices/hmipw-wth.js @@ -1 +1 @@ -module.exports = require('./hmip-wth'); +module.exports = require('./hmip-wth.js'); diff --git a/homematic-devices/hmw-io-12-sw7-dr.js b/homematic-devices/hmw-io-12-sw7-dr.js index c5cf82d..253424f 100644 --- a/homematic-devices/hmw-io-12-sw7-dr.js +++ b/homematic-devices/hmw-io-12-sw7-dr.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hmw-lc-bl1-dr-2.js b/homematic-devices/hmw-lc-bl1-dr-2.js index d431470..9054ead 100644 --- a/homematic-devices/hmw-lc-bl1-dr-2.js +++ b/homematic-devices/hmw-lc-bl1-dr-2.js @@ -1 +1 @@ -module.exports = require('./hmw-lc-bl1-dr'); +module.exports = require('./hmw-lc-bl1-dr.js'); diff --git a/homematic-devices/hmw-lc-bl1-dr.js b/homematic-devices/hmw-lc-bl1-dr.js index fe8fa85..a7f005a 100644 --- a/homematic-devices/hmw-lc-bl1-dr.js +++ b/homematic-devices/hmw-lc-bl1-dr.js @@ -1,19 +1,11 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmwLcBl1 extends Accessory { init(config) { this.addService('WindowCovering', config.name) - .get('CurrentPosition', config.deviceAddress + ':3.LEVEL', value => { - return value * 100; - }) - - .get('TargetPosition', config.deviceAddress + ':3.LEVEL', value => { - return value * 100; - }) - .set('TargetPosition', config.deviceAddress + ':3.LEVEL', value => { - return value / 100; - }) - + .get('CurrentPosition', config.deviceAddress + ':3.LEVEL', value => value * 100) + .get('TargetPosition', config.deviceAddress + ':3.LEVEL', value => value * 100) + .set('TargetPosition', config.deviceAddress + ':3.LEVEL', value => value / 100) .get('PositionState', config.deviceAddress + ':3.DIRECTION', (value, c) => { switch (value) { case 1: diff --git a/homematic-devices/hmw-lc-dim1l-dr.js b/homematic-devices/hmw-lc-dim1l-dr.js index 05d0133..53b9704 100644 --- a/homematic-devices/hmw-lc-dim1l-dr.js +++ b/homematic-devices/hmw-lc-dim1l-dr.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class HmwDim extends Accessory { init(config) { diff --git a/homematic-devices/hmw-lc-sw2-dr.js b/homematic-devices/hmw-lc-sw2-dr.js index c5cf82d..253424f 100644 --- a/homematic-devices/hmw-lc-sw2-dr.js +++ b/homematic-devices/hmw-lc-sw2-dr.js @@ -1 +1 @@ -module.exports = require('./lib/generic-switch'); +module.exports = require('./lib/generic-switch.js'); diff --git a/homematic-devices/hmw-sen-sc-12-dr.js b/homematic-devices/hmw-sen-sc-12-dr.js index 743ecb2..47a4dbb 100644 --- a/homematic-devices/hmw-sen-sc-12-dr.js +++ b/homematic-devices/hmw-sen-sc-12-dr.js @@ -1,6 +1,6 @@ /* eslint-disable no-new */ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); function addService(type, name, dp) { let service; @@ -38,9 +38,7 @@ function addService(type, name, dp) { default: this.addService('ContactSensor', name) - .get('ContactSensorState', dp, (value, c) => { - return value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED; - }); + .get('ContactSensorState', dp, (value, c) => value ? c.CONTACT_NOT_DETECTED : c.CONTACT_DETECTED); } } diff --git a/homematic-devices/hmw-sen-sc-12-fm.js b/homematic-devices/hmw-sen-sc-12-fm.js index 2d7db59..ed910aa 100644 --- a/homematic-devices/hmw-sen-sc-12-fm.js +++ b/homematic-devices/hmw-sen-sc-12-fm.js @@ -1 +1 @@ -module.exports = require('./hmw-sen-sc-12-dr'); +module.exports = require('./hmw-sen-sc-12-dr.js'); diff --git a/homematic-devices/lib/accessory.js b/homematic-devices/lib/accessory.js index a73a7a8..238badc 100644 --- a/homematic-devices/lib/accessory.js +++ b/homematic-devices/lib/accessory.js @@ -2,6 +2,7 @@ class Service { constructor(acc, subtype) { this.acc = acc; this.subtype = subtype; + // eslint-disable-next-line no-constructor-return return this; } @@ -34,8 +35,8 @@ class Service { return this; } - fault(datapointNameArr, transformArr) { - this.acc.datapointsFault(this.subtype, datapointNameArr, transformArr); + fault(datapointNameArray, transformArray) { + this.acc.datapointsFault(this.subtype, datapointNameArray, transformArray); return this; } } @@ -149,9 +150,9 @@ module.exports = class Accessory { cache: true, change: true, stable: true, - datapointName - }, msg => { - callback(msg.value); + datapointName, + }, message => { + callback(message.value); })); } @@ -159,39 +160,40 @@ module.exports = class Accessory { this.subscriptions.push(this.ccu.subscribe({ cache: true, change: true, - datapointName - }, msg => { - this.unreach = msg.value; + datapointName, + }, message => { + this.unreach = message.value; })); } - datapointsFault(subtype, datapointNameArr, transformArr) { - if (!transformArr) { - transformArr = []; + datapointsFault(subtype, datapointNameArray, transformArray) { + if (!transformArray) { + transformArray = []; } const values = {}; - datapointNameArr.forEach((dp, i) => { + for (const [i, dp] of datapointNameArray.entries()) { this.subscriptions.push(this.ccu.subscribe({ cache: true, change: true, - datapointName: dp - }, msg => { - values[msg.datapointName] = msg.value; + datapointName: dp, + }, message => { + values[message.datapointName] = message.value; let value = this.hap.Characteristic.StatusFault.NO_FAULT; - if (typeof transformArr[i] === 'function') { - value = transformArr[i](value); + if (typeof transformArray[i] === 'function') { + value = transformArray[i](value); } - Object.keys(values).forEach(key => { + for (const key of Object.keys(values)) { if (values[key]) { value = this.hap.Characteristic.StatusFault.GENERAL_FAULT; } - }); + } + this.node.debug('update ' + this.config.name + ' (' + subtype + ') StatusFault ' + value); this.acc.getService(subtype).updateCharacteristic(this.hap.Characteristic.StatusFault, value); })); - }); + } } datapointGet(subtype, characteristic, datapointName, transform) { @@ -211,9 +213,9 @@ module.exports = class Accessory { cache: true, change: true, stable: !datapointName.endsWith('.DIRECTION') && !datapointName.endsWith('.ACTIVITY_STATE'), - datapointName - }, msg => { - const valueOrig = msg.value; + datapointName, + }, message => { + const valueOrig = message.value; let value = valueOrig; if (typeof transform === 'function') { value = transform(value, this.hap.Characteristic[characteristic]); @@ -271,16 +273,10 @@ module.exports = class Accessory { addr = addr + ':' + id; } - let res; - - if (option) { - res = this.config.options[addr] && this.config.options[addr][option]; - } else { - res = !(this.config.options[addr] && this.config.options[addr].disabled); - } + const result = option ? this.config.options[addr] && this.config.options[addr][option] : !(this.config.options[addr] && this.config.options[addr].disabled); - this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); - return res; + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + result); + return result; } percent(value, _, lower = 2, upper = 3) { diff --git a/homematic-devices/lib/generic-hmip-blind.js b/homematic-devices/lib/generic-hmip-blind.js index e4b3bc9..6758edf 100644 --- a/homematic-devices/lib/generic-hmip-blind.js +++ b/homematic-devices/lib/generic-hmip-blind.js @@ -1,6 +1,6 @@ /* eslint-disable no-new */ -const Accessory = require('./accessory'); +const Accessory = require('./accessory.js'); function createService(channel) { let intermediatePosition; // 0-100 @@ -12,9 +12,9 @@ function createService(channel) { this.ccu.subscribe({ datapointName: this.config.deviceAddress + ':' + channelIndex + '.LEVEL', cache: true, - stable: false - }, msg => { - intermediatePosition = msg.value * 100; + stable: false, + }, message => { + intermediatePosition = message.value * 100; }); const service = this.addService('WindowCovering', channel.name, channelIndex); @@ -45,26 +45,26 @@ function createService(channel) { this.node.debug(channel.name + ' intermediatePosition ' + intermediatePosition); service.update('CurrentPosition', intermediatePosition); - const params = { - LEVEL + const parameters = { + LEVEL, }; if (channel.tilt) { - params.LEVEL_2 = LEVEL_2; + parameters.LEVEL_2 = LEVEL_2; } if (channel.tilt || this.config.type === 'BLIND_VIRTUAL_RECEIVER') { if (LEVEL === 0) { - params.LEVEL_2 = 0; + parameters.LEVEL_2 = 0; } if (LEVEL === 1) { - params.LEVEL_2 = 1; + parameters.LEVEL_2 = 1; } } - this.node.debug('set ' + this.config.name + ' (WindowCovering) TargetPosition ' + value + ' -> ' + this.config.description.ADDRESS + ':' + channelIndex + ' ' + JSON.stringify(params)); - this.ccu.methodCall(this.config.iface, 'putParamset', [this.config.description.ADDRESS + ':' + channelIndex, 'VALUES', params]) + this.node.debug('set ' + this.config.name + ' (WindowCovering) TargetPosition ' + value + ' -> ' + this.config.description.ADDRESS + ':' + channelIndex + ' ' + JSON.stringify(parameters)); + this.ccu.methodCall(this.config.iface, 'putParamset', [this.config.description.ADDRESS + ':' + channelIndex, 'VALUES', parameters]) .then(() => { callback(); }) @@ -104,12 +104,12 @@ function createService(channel) { LEVEL_2 = (value + 90) / 180; this.node.debug('set TargetVerticalTiltAngle ' + this.config.name + ' LEVEL_2 ' + LEVEL_2 + ' ' + value); - const params = { + const parameters = { LEVEL, - LEVEL_2 + LEVEL_2, }; - this.node.debug('set ' + channel.name + ' (WindowCovering) TargetVerticalTiltAngle ' + value + ' -> ' + this.config.description.ADDRESS + ':' + channelIndex + ' ' + JSON.stringify(params)); - this.ccu.methodCall(this.config.iface, 'putParamset', [this.config.description.ADDRESS + ':' + channelIndex, 'VALUES', params]) + this.node.debug('set ' + channel.name + ' (WindowCovering) TargetVerticalTiltAngle ' + value + ' -> ' + this.config.description.ADDRESS + ':' + channelIndex + ' ' + JSON.stringify(parameters)); + this.ccu.methodCall(this.config.iface, 'putParamset', [this.config.description.ADDRESS + ':' + channelIndex, 'VALUES', parameters]) .then(() => { callback(); }) @@ -128,9 +128,9 @@ class GenericHmipBlindAcc extends Accessory { } init() { - this.channels.forEach(channel => { + for (const channel of this.channels) { createService.call(this, channel); - }); + } } } @@ -144,7 +144,7 @@ class GenericHmipBlind { let acc = 0; let pos = 0; const channels = []; - this.config.description.CHILDREN.forEach(channel => { + for (const channel of this.config.description.CHILDREN) { const desc = this.ccu.metadata.devices['HmIP-RF'][channel]; if (desc.TYPE === 'BLIND_VIRTUAL_RECEIVER' || desc.TYPE === 'SHUTTER_VIRTUAL_RECEIVER') { if (!channels[acc]) { @@ -152,8 +152,8 @@ class GenericHmipBlind { } const name = this.ccu.channelNames[channel]; - const tilt = desc.TYPE === 'BLIND_VIRTUAL_RECEIVER' && - (!this.config.options[channel] || this.config.options[channel].type !== 'VerticalTilt Disabled'); + const tilt = desc.TYPE === 'BLIND_VIRTUAL_RECEIVER' + && (!this.config.options[channel] || this.config.options[channel].type !== 'VerticalTilt Disabled'); if (pos === 0) { if (!this.config.options[channel] || !this.config.options[channel].disabled) { channels[acc].push({channel, name, tilt}); @@ -167,14 +167,15 @@ class GenericHmipBlind { acc += 1; } } - }); - channels.forEach(accChannels => { + } + + for (const accChannels of channels) { if (accChannels.length > 0) { const conf = Object.assign({}, config, {name: accChannels[0].name}); conf.description = Object.assign({}, config.description, {ADDRESS: accChannels[0].channel}); new GenericHmipBlindAcc(conf, node, accChannels); } - }); + } } } diff --git a/homematic-devices/lib/generic-switch.js b/homematic-devices/lib/generic-switch.js index a9f5a45..a6721d4 100644 --- a/homematic-devices/lib/generic-switch.js +++ b/homematic-devices/lib/generic-switch.js @@ -1,6 +1,6 @@ /* eslint-disable no-new */ -const Accessory = require('./accessory'); +const Accessory = require('./accessory.js'); function addService(type, dp, name) { switch (type) { @@ -12,11 +12,11 @@ function addService(type, dp, name) { service.update('ValveType', type === 'ValveIrrigation' ? 1 : 0); service - .get('Active', dp, val => val ? 1 : 0) - .get('InUse', dp, val => val ? 1 : 0) - .set('Active', dp, val => { - service.update('InUse', val); - return Boolean(val); + .get('Active', dp, value => value ? 1 : 0) + .get('InUse', dp, value => value ? 1 : 0) + .set('Active', dp, value => { + service.update('InUse', value); + return Boolean(value); }); break; } diff --git a/homematic-devices/zel_stg_rm_fep_230v.js b/homematic-devices/zel_stg_rm_fep_230v.js index 36ab5d7..4d02675 100644 --- a/homematic-devices/zel_stg_rm_fep_230v.js +++ b/homematic-devices/zel_stg_rm_fep_230v.js @@ -1 +1 @@ -module.exports = require('./hm-lc-bl1-fm'); +module.exports = require('./hm-lc-bl1-fm.js'); diff --git a/homematic-devices/zel_stg_rm_ffk.js b/homematic-devices/zel_stg_rm_ffk.js index 573cbde..1ad21a2 100644 --- a/homematic-devices/zel_stg_rm_ffk.js +++ b/homematic-devices/zel_stg_rm_ffk.js @@ -1 +1 @@ -module.exports = require('./hm-sec-sc'); +module.exports = require('./hm-sec-sc.js'); diff --git a/nodes/redmatic-homekit-bridge.js b/nodes/redmatic-homekit-bridge.js index 0a6fdce..f868daf 100644 --- a/nodes/redmatic-homekit-bridge.js +++ b/nodes/redmatic-homekit-bridge.js @@ -6,18 +6,18 @@ const pkg = require('../package.json'); const bridges = {}; module.exports = function (RED) { - hap.init(path.join(RED.settings.userDir, 'homekit')); + hap.HAPStorage.setCustomStoragePath(path.join(RED.settings.userDir, 'homekit')); - RED.httpAdmin.get('/redmatic-homekit', (req, res) => { - if (req.query.config && req.query.config !== '_ADD_') { - const config = RED.nodes.getNode(req.query.config); + RED.httpAdmin.get('/redmatic-homekit', (request, response) => { + if (request.query.config && request.query.config !== '_ADD_') { + const config = RED.nodes.getNode(request.query.config); if (!config || !config.bridge.isPublished) { - res.status(500).send(JSON.stringify({})); + response.status(500).send(JSON.stringify({})); } else { - res.status(200).send(JSON.stringify({setupURI: config.bridge.setupURI()})); + response.status(200).send(JSON.stringify({setupURI: config.bridge.setupURI()})); } } else { - res.status(404).send(JSON.stringify({})); + response.status(404).send(JSON.stringify({})); } }); @@ -95,16 +95,16 @@ module.exports = function (RED) { .setCharacteristic(hap.Characteristic.FirmwareRevision, pkg.version); const testPort = net.createServer() - .once('error', err => { - this.error(err); + .once('error', error => { + this.error(error); }) .once('listening', () => { testPort.once('close', () => { this.bridge.publish({ username: this.username, - port: parseInt(this.port, 10), + port: Number.parseInt(this.port, 10), pincode: this.pincode, - category: hap.Accessory.Categories.OTHER + category: hap.Categories.OTHER, }, this.allowInsecureRequest); this.log('published bridge (' + this.bridge.bridgedAccessories.length + ' Accessories) ' + this.name + ' ' + this.username + ' on port ' + this.port); @@ -131,11 +131,11 @@ module.exports = function (RED) { const uuid = hap.uuid.generate(config.id + (config.uuidAddition ? config.uuidAddition : '')); let acc; - this.bridge.bridgedAccessories.forEach(a => { + for (const a of this.bridge.bridgedAccessories) { if (a.UUID === uuid) { acc = a; } - }); + } if (acc) { this.debug('already existing accessory ' + config.id + ' ' + config.name); @@ -143,7 +143,7 @@ module.exports = function (RED) { this.error('maximum of 150 accessories per bridge exceeded, can\'t add ' + config.id + ' ' + config.name); } else { this.debug('addAccessory ' + config.id + ' ' + config.name); - acc = new hap.Accessory(config.name, uuid, hap.Accessory.Categories.OTHER); + acc = new hap.Accessory(config.name, uuid, hap.Categories.OTHER); this.bridge.addBridgedAccessory(acc); } diff --git a/nodes/redmatic-homekit-camera.js b/nodes/redmatic-homekit-camera.js index d543f94..a8f77e9 100644 --- a/nodes/redmatic-homekit-camera.js +++ b/nodes/redmatic-homekit-camera.js @@ -9,18 +9,18 @@ const pkg = require('../package.json'); const accessories = {}; module.exports = function (RED) { - hap.init(path.join(RED.settings.userDir, 'homekit')); + hap.HAPStorage.setCustomStoragePath(path.join(RED.settings.userDir, 'homekit')); - RED.httpAdmin.get('/redmatic-homekit-camera', (req, res) => { - if (req.query.config) { - const acc = accessories[req.query.config]; + RED.httpAdmin.get('/redmatic-homekit-camera', (request, response) => { + if (request.query.config) { + const acc = accessories[request.query.config]; if (acc) { - res.status(200).send(JSON.stringify({setupURI: acc.setupURI()})); + response.status(200).send(JSON.stringify({setupURI: acc.setupURI()})); } else { - res.status(500).send(JSON.stringify({})); + response.status(500).send(JSON.stringify({})); } } else { - res.status(404).send(JSON.stringify({})); + response.status(404).send(JSON.stringify({})); } }); @@ -28,15 +28,13 @@ module.exports = function (RED) { constructor(config) { RED.nodes.createNode(this, config); - const that = this; - function logger(...args) { - let str = args.join(' '); - if (str.match(/^(error: )/i)) { - str = str.replace(/^error: (.*)/i, '$1'); - that.error(str); + let string_ = args.join(' '); + if (/^(error: )/i.test(string_)) { + string_ = string_.replace(/^error: (.*)/i, '$1'); + this.error(string_); } else if (config.debug) { - that.debug(str); + this.debug(string_); } } @@ -50,7 +48,7 @@ module.exports = function (RED) { this.name = config.name || ('Camera ' + this.id); - const acc = new Accessory(this.name, uuid.generate(config.id), Accessory.Categories.CAMERA); + const acc = new Accessory(this.name, uuid.generate(config.id), hap.Categories.CAMERA); accessories[this.id] = acc; this.debug('camera created' + this.name + ' ' + this.id + ' ' + config.username); @@ -71,8 +69,8 @@ module.exports = function (RED) { if (config.doorbell) { this.debug('add doorbell service'); const doorbellService = acc.addService(hap.Service.Doorbell, this.name); - this.on('input', msg => { - console.log(msg); + this.on('input', message => { + console.log(message); this.debug('update ProgrammableSwitchEvent SINGLE_PRESS'); doorbellService.getCharacteristic(hap.Characteristic.ProgrammableSwitchEvent).updateValue(0); }); @@ -85,9 +83,9 @@ module.exports = function (RED) { this.log('publishing camera ' + this.name + ' ' + config.username); const testPort = net.createServer() - .once('error', err => { - this.error(err); - this.status({fill: 'red', shape: 'dot', text: err.message}); + .once('error', error => { + this.error(error); + this.status({fill: 'red', shape: 'dot', text: error.message}); }) .once('listening', () => { testPort.once('close', () => { @@ -95,7 +93,7 @@ module.exports = function (RED) { username: config.username, port: config.port, pincode: config.pincode, - category: Accessory.Categories.CAMERA + category: hap.Categories.CAMERA, }); acc._server.on('listening', () => { @@ -118,8 +116,7 @@ module.exports = function (RED) { }) .listen(config.port); - this.on('close', () => { - }); + this.on('close', () => {}); } } diff --git a/nodes/redmatic-homekit-homematic-devices.js b/nodes/redmatic-homekit-homematic-devices.js index 5a95806..e0e10a2 100644 --- a/nodes/redmatic-homekit-homematic-devices.js +++ b/nodes/redmatic-homekit-homematic-devices.js @@ -6,16 +6,16 @@ module.exports = function (RED) { const devPath = path.join(__dirname, '..', 'homematic-devices'); fs.readdir(devPath, (error, files) => { if (!error && files) { - files.forEach(file => { + for (const file of files) { if (file.endsWith('.js')) { homematicValidDevices.push(file.replace('.js', '')); } - }); + } } }); - RED.httpAdmin.get('/redmatic-homekit/homematic-devices', (req, res) => { - res.status(200).send(JSON.stringify(homematicValidDevices)); + RED.httpAdmin.get('/redmatic-homekit/homematic-devices', (_request, response) => { + response.status(200).send(JSON.stringify(homematicValidDevices)); }); class RedMaticHomeKitHomematicDevices { @@ -63,39 +63,40 @@ module.exports = function (RED) { const queue = []; - Object.keys(this.ccu.channelNames).forEach(address => { + for (const address of Object.keys(this.ccu.channelNames)) { if (this.devices[address] && this.devices[address].disabled) { - return; + continue; } - if (!address.match(/:\d+$/)) { + if (!/:\d+$/.test(address)) { const iface = this.ccu.findIface(address); if (iface && this.ccu.enabledIfaces.includes(iface) && this.ccu.metadata.devices[iface]) { const options = {}; - Object.keys(this.devices).forEach(addr => { + for (const addr of Object.keys(this.devices)) { + // eslint-disable-next-line max-depth if (addr === address || addr.startsWith(address + ':')) { options[addr] = this.devices[addr]; } - }); - - queue.push(() => { - return new Promise(resolve => { - this.createHomematicDevice({ - name: this.ccu.channelNames[address], - iface, - deviceAddress: iface + '.' + address, - description: this.ccu.metadata.devices[iface][address], - options - }); - setTimeout(() => { - resolve(); - }, 50); + } + + queue.push(() => new Promise(resolve => { + this.createHomematicDevice({ + name: this.ccu.channelNames[address], + iface, + deviceAddress: iface + '.' + address, + description: this.ccu.metadata.devices[iface][address], + options, }); - }); + setTimeout(() => { + resolve(); + }, 50); + })); } } - }); + } + this.log('publish ' + queue.length + ' devices'); + // eslint-disable-next-line unicorn/no-array-reduce queue.reduce((p, task) => p.then(task), Promise.resolve()).then(() => { callback(); }); @@ -117,7 +118,7 @@ module.exports = function (RED) { try { this.homematicDevices[type] = require('../homematic-devices/' + type); this.debug('loaded homematic-devices/' + type); - } catch (error) { + } catch { this.warn('missing homematic-devices/' + type); return; } @@ -139,11 +140,12 @@ module.exports = function (RED) { setStatus(data) { this.ccuStatus = data; let status = 0; - Object.keys(data.ifaceStatus).forEach(s => { + for (const s of Object.keys(data.ifaceStatus)) { if (data.ifaceStatus[s]) { status += 1; } - }); + } + this.debug(JSON.stringify(data)); if (status < 1) { this.status({fill: 'red', shape: 'dot', text: 'disconnected'}); diff --git a/nodes/redmatic-homekit-homematic-garage.js b/nodes/redmatic-homekit-homematic-garage.js index 59c3c28..40f3f11 100644 --- a/nodes/redmatic-homekit-homematic-garage.js +++ b/nodes/redmatic-homekit-homematic-garage.js @@ -42,14 +42,14 @@ module.exports = function (RED) { if (ps && ps.ON_TIME) { this.ccu.methodCall(config.ifaceActuator, 'putParamset', [channel, 'VALUES', { STATE: true, - ON_TIME: this.ccu.paramCast(config.ifaceActuator, channel, 'VALUES', 'ON_TIME', config.onTime || 0.4) + ON_TIME: this.ccu.paramCast(config.ifaceActuator, channel, 'VALUES', 'ON_TIME', config.onTime || 0.4), }]).then(() => { if (revert) { this.valueCurrent = 4; this.updateSensor(); setTimeout(() => { move(direction).then(resolve).catch(reject); - }, (parseFloat(config.revertTime) || 0.5) * 1000); + }, (Number.parseFloat(config.revertTime) || 0.5) * 1000); } else { resolve(); } @@ -65,12 +65,12 @@ module.exports = function (RED) { this.updateSensor(); setTimeout(() => { move(direction).then(resolve).catch(reject); - }, (parseFloat(config.revertTime) || 0.5) * 1000); + }, (Number.parseFloat(config.revertTime) || 0.5) * 1000); } else { resolve(); } }).catch(reject); - }, (parseFloat(config.onTime) || 0.4) * 1000); + }, (Number.parseFloat(config.onTime) || 0.4) * 1000); }) .catch(reject); } @@ -106,6 +106,7 @@ module.exports = function (RED) { Characteristic.CurrentDoorState.STOPPED = 4; */ + // eslint-disable-next-line complexity this.updateSensor = (timeout, source) => { let valueCurrent = 4; let obstruction = false; @@ -269,10 +270,10 @@ module.exports = function (RED) { change: true, iface: config.ifaceSensor, channel: config.channelSensorClosed.split(' ')[0], - datapoint: /STATE|MOTION|SENSOR/ - }, msg => { - this.closed = config.directionClosed ? msg.value : !msg.value; - this.log(config.channelSensorClosed + ' ' + msg.value + ' closed=' + this.closed); + datapoint: /STATE|MOTION|SENSOR/, + }, message => { + this.closed = config.directionClosed ? message.value : !message.value; + this.log(config.channelSensorClosed + ' ' + message.value + ' closed=' + this.closed); this.updateSensor(false, 'c'); }); } @@ -284,10 +285,10 @@ module.exports = function (RED) { change: true, iface: config.ifaceSensor, channel: config.channelSensorOpened.split(' ')[0], - datapoint: /STATE|MOTION|SENSOR/ - }, msg => { - this.opened = config.directionOpened ? msg.value : !msg.value; - this.log(config.channelSensorOpened + ' ' + msg.value + ' openend=' + this.opened); + datapoint: /STATE|MOTION|SENSOR/, + }, message => { + this.opened = config.directionOpened ? message.value : !message.value; + this.log(config.channelSensorOpened + ' ' + message.value + ' openend=' + this.opened); this.updateSensor(false, 'o'); }); } @@ -328,9 +329,9 @@ module.exports = function (RED) { }); }; - this.on('input', msg => { + this.on('input', message => { let value; - switch (msg.payload) { + switch (message.payload) { case 'close': value = 1; break; diff --git a/nodes/redmatic-homekit-homematic-irrigation.js b/nodes/redmatic-homekit-homematic-irrigation.js index 06c6235..a3fbc07 100644 --- a/nodes/redmatic-homekit-homematic-irrigation.js +++ b/nodes/redmatic-homekit-homematic-irrigation.js @@ -15,7 +15,7 @@ module.exports = function (RED) { this.iface = config.iface; - this.onTime = this.context().get('onTime') || parseFloat(config.onTime) || 5; + this.onTime = this.context().get('onTime') || Number.parseFloat(config.onTime) || 5; this.remaining = this.onTime * 60; const channel = config.channel.split(' ')[0]; @@ -72,19 +72,35 @@ module.exports = function (RED) { }, 1000); }; - const start = () => { - return new Promise((resolve, reject) => { - const dev = this.ccu.metadata.devices[config.iface] && this.ccu.metadata.devices[config.iface][channel]; - if (dev) { - const ps = this.ccu.getParamsetDescription(config.iface, dev, 'VALUES'); - if (ps && ps.STATE) { - if (ps.ON_TIME) { - this.debug('starting with ON_TIME ' + (this.onTime * 60)); - - this.ccu.methodCall(config.iface, 'putParamset', [channel, 'VALUES', { - ON_TIME: this.ccu.paramCast(config.iface, channel, 'VALUES', 'ON_TIME', this.onTime * 60), - STATE: true - }]).then(() => { + const start = () => new Promise((resolve, reject) => { + const dev = this.ccu.metadata.devices[config.iface] && this.ccu.metadata.devices[config.iface][channel]; + if (dev) { + const ps = this.ccu.getParamsetDescription(config.iface, dev, 'VALUES'); + if (ps && ps.STATE) { + if (ps.ON_TIME) { + this.debug('starting with ON_TIME ' + (this.onTime * 60)); + + this.ccu.methodCall(config.iface, 'putParamset', [channel, 'VALUES', { + ON_TIME: this.ccu.paramCast(config.iface, channel, 'VALUES', 'ON_TIME', this.onTime * 60), + STATE: true, + }]).then(() => { + // this.state = true; + this.remaining = this.onTime * 60; + this.debug('update Valve 0 RemainingDuration ' + this.remaining); + service.updateCharacteristic(hap.Characteristic.RemainingDuration, this.remaining); + + this.debug('update Valve 0 Active 1'); + service.updateCharacteristic(hap.Characteristic.InUse, 1); + this.debug('update Valve 0 InUse true'); + service.updateCharacteristic(hap.Characteristic.Active, true); + + resolve(); + startInterval(); + }).catch(reject); + } else { + this.debug('starting with timeout'); + this.ccu.setValue(config.iface, channel, 'STATE', true) + .then(() => { // this.state = true; this.remaining = this.onTime * 60; this.debug('update Valve 0 RemainingDuration ' + this.remaining); @@ -94,39 +110,21 @@ module.exports = function (RED) { service.updateCharacteristic(hap.Characteristic.InUse, 1); this.debug('update Valve 0 InUse true'); service.updateCharacteristic(hap.Characteristic.Active, true); - + setTimeout(() => { + stop().catch(() => {}); + }, (this.onTime * 60 * 1000) + 1000); resolve(); startInterval(); - }).catch(reject); - } else { - this.debug('starting with timeout'); - this.ccu.setValue(config.iface, channel, 'STATE', true) - .then(() => { - // this.state = true; - this.remaining = this.onTime * 60; - this.debug('update Valve 0 RemainingDuration ' + this.remaining); - service.updateCharacteristic(hap.Characteristic.RemainingDuration, this.remaining); - - this.debug('update Valve 0 Active 1'); - service.updateCharacteristic(hap.Characteristic.InUse, 1); - this.debug('update Valve 0 InUse true'); - service.updateCharacteristic(hap.Characteristic.Active, true); - setTimeout(() => { - stop().catch(() => {}); - }, (this.onTime * 60 * 1000) + 1000); - resolve(); - startInterval(); - }) - .catch(reject); - } - } else { - reject(); + }) + .catch(reject); } } else { reject(); } - }); - }; + } else { + reject(); + } + }); const {hap, version} = this.bridgeConfig; @@ -167,18 +165,18 @@ module.exports = function (RED) { datapoint: 'STATE', cache: true, change: true, - stable: true - }, msg => { - this.state = msg.value; + stable: true, + }, message => { + this.state = message.value; if (!this.state) { stop().catch(() => {}); } this.debug('this.state=' + this.state); - this.debug('update Valve 0 InUse ' + msg.value); - service.updateCharacteristic(hap.Characteristic.InUse, msg.value); - this.debug('update Valve 0 Active ' + (msg.value ? 1 : 0)); - service.updateCharacteristic(hap.Characteristic.Active, msg.value ? 1 : 0); + this.debug('update Valve 0 InUse ' + message.value); + service.updateCharacteristic(hap.Characteristic.InUse, message.value); + this.debug('update Valve 0 Active ' + (message.value ? 1 : 0)); + service.updateCharacteristic(hap.Characteristic.Active, message.value ? 1 : 0); if (!changeExpected) { this.status({fill: this.state ? 'green' : 'grey', shape: 'ring', text: '?'}); this.send([{topic: config.topic, payload: true}, {topic: config.topic, payload: 0}]); @@ -233,20 +231,20 @@ module.exports = function (RED) { }; const getRemainingDuration = callback => { - const res = this.remaining; // || (this.onTime * 60); - this.debug('get Valve 0 RemainingDuration ' + res); - callback(res); + const result = this.remaining; // || (this.onTime * 60); + this.debug('get Valve 0 RemainingDuration ' + result); + callback(result); }; - this.on('input', msg => { - if (typeof msg.payload === 'boolean') { - if (msg.payload) { + this.on('input', message => { + if (typeof message.payload === 'boolean') { + if (message.payload) { start().catch(() => {}); } else { stop().catch(() => {}); } } else { - const time = parseFloat(msg.payload) || 0; + const time = Number.parseFloat(message.payload) || 0; if (time) { this.onTime = time; this.context().set('onTime', this.onTime); diff --git a/nodes/redmatic-homekit-pseudobutton.js b/nodes/redmatic-homekit-pseudobutton.js index 40fe0f5..e5b79bf 100644 --- a/nodes/redmatic-homekit-pseudobutton.js +++ b/nodes/redmatic-homekit-pseudobutton.js @@ -34,31 +34,31 @@ module.exports = function (RED) { const setListener = (value, callback) => { this.log('set Switch 0 On ' + value); if (value) { - const msg = {}; - msg.topic = config.topic; + const message = {}; + message.topic = config.topic; if (this.payloadType !== 'flow' && this.payloadType !== 'global') { try { if ((!this.payloadType && !this.payload) || this.payloadType === 'date') { - msg.payload = Date.now(); + message.payload = Date.now(); } else if (!this.payloadType) { - msg.payload = this.payload; + message.payload = this.payload; } else if (this.payloadType === 'none') { - msg.payload = ''; + message.payload = ''; } else { - msg.payload = RED.util.evaluateNodeProperty(this.payload, this.payloadType, this, msg); + message.payload = RED.util.evaluateNodeProperty(this.payload, this.payloadType, this, message); } - this.send(msg); + this.send(message); } catch (error) { - this.error(error, msg); + this.error(error, message); } } else { - RED.util.evaluateNodeProperty(this.payload, this.payloadType, this, msg, (err, res) => { - if (err) { - this.error(err, msg); + RED.util.evaluateNodeProperty(this.payload, this.payloadType, this, message, (error, response) => { + if (error) { + this.error(error, message); } else { - msg.payload = res; - this.send(msg); + message.payload = response; + this.send(message); } }); } diff --git a/nodes/redmatic-homekit-statelessprogrammableswitch.js b/nodes/redmatic-homekit-statelessprogrammableswitch.js index 5f7d271..adc3e6e 100644 --- a/nodes/redmatic-homekit-statelessprogrammableswitch.js +++ b/nodes/redmatic-homekit-statelessprogrammableswitch.js @@ -12,7 +12,7 @@ module.exports = function (RED) { const {hap, version} = this.bridgeConfig; this.name = config.name || ('Switch ' + this.id); - this.count = parseInt(config.count, 10) || 1; + this.count = Number.parseInt(config.count, 10) || 1; const acc = this.bridgeConfig.accessory({id: this.id, name: this.name}); @@ -39,25 +39,20 @@ module.exports = function (RED) { acc.isConfigured = true; } - this.on('input', msg => { - let [button, type] = String(msg.topic).split('/'); - button = parseInt(button, 10); + this.on('input', message => { + let [button, type] = String(message.topic).split('/'); + button = Number.parseInt(button, 10); if (button < 1 || button > this.count) { - this.error('invalid topic ' + msg.topic); + this.error('invalid topic ' + message.topic); return; } const subtype = String(button); - let val; - if (String(type).match(/long/i)) { - val = 2; - } else { - val = 0; - } + const value = /long/i.test(String(type)) ? 2 : 0; - this.debug('update ' + config.name + ' ' + subtype + ' ProgrammableSwitchEvent ' + (val === 2 ? 'LONG_PRESS' : 'SINGLE_PRESS')); - acc.getService(subtype).getCharacteristic(hap.Characteristic.ProgrammableSwitchEvent).updateValue(val); + this.debug('update ' + config.name + ' ' + subtype + ' ProgrammableSwitchEvent ' + (value === 2 ? 'LONG_PRESS' : 'SINGLE_PRESS')); + acc.getService(subtype).getCharacteristic(hap.Characteristic.ProgrammableSwitchEvent).updateValue(value); }); } } diff --git a/nodes/redmatic-homekit-switch.js b/nodes/redmatic-homekit-switch.js index 46ca96c..622a4a6 100644 --- a/nodes/redmatic-homekit-switch.js +++ b/nodes/redmatic-homekit-switch.js @@ -49,8 +49,8 @@ module.exports = function (RED) { acc.getService(subtype).getCharacteristic(hap.Characteristic.On).on('set', setListener); acc.getService(subtype).getCharacteristic(hap.Characteristic.On).on('get', getListener); - this.on('input', msg => { - this.valueOn = Boolean(msg.payload); + this.on('input', message => { + this.valueOn = Boolean(message.payload); update(); }); diff --git a/nodes/redmatic-homekit-tv.js b/nodes/redmatic-homekit-tv.js index e392a9e..72ad6b4 100644 --- a/nodes/redmatic-homekit-tv.js +++ b/nodes/redmatic-homekit-tv.js @@ -8,18 +8,18 @@ const pkg = require('../package.json'); const accessories = {}; module.exports = function (RED) { - hap.init(path.join(RED.settings.userDir, 'homekit')); + hap.HAPStorage.setCustomStoragePath(path.join(RED.settings.userDir, 'homekit')); - RED.httpAdmin.get('/redmatic-homekit-tv', (req, res) => { - if (req.query.config) { - const acc = accessories[req.query.config]; + RED.httpAdmin.get('/redmatic-homekit-tv', (request, response) => { + if (request.query.config) { + const acc = accessories[request.query.config]; if (acc) { - res.status(200).send(JSON.stringify({setupURI: acc.setupURI()})); + response.status(200).send(JSON.stringify({setupURI: acc.setupURI()})); } else { - res.status(500).send(JSON.stringify({})); + response.status(500).send(JSON.stringify({})); } } else { - res.status(404).send(JSON.stringify({})); + response.status(404).send(JSON.stringify({})); } }); @@ -56,7 +56,7 @@ module.exports = function (RED) { tvService.setCharacteristic( Characteristic.SleepDiscoveryMode, - Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE + Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE, ); tvService.setCharacteristic(Characteristic.ActiveIdentifier, 1); @@ -68,7 +68,7 @@ module.exports = function (RED) { .setCharacteristic(Characteristic.VolumeControlType, Characteristic.VolumeControlType.ABSOLUTE); this.debug('creating ' + config.inputsources.length + ' input sources'); - config.inputsources.forEach((src, i) => { + for (const [i, src] of config.inputsources.entries()) { const id = i + 1; const inputService = acc.addService(Service.InputSource, src.name, src.name); inputService @@ -80,15 +80,15 @@ module.exports = function (RED) { .setCharacteristic(Characteristic.TargetVisibilityState, Characteristic.TargetVisibilityState.SHOWN); tvService.addLinkedService(inputService); - }); + } // tvService.addLinkedService(speakerService); this.log('publishing tv ' + this.name + ' ' + config.username); const testPort = net.createServer() - .once('error', err => { - this.error(err); - this.status({fill: 'red', shape: 'dot', text: err.message}); + .once('error', error => { + this.error(error); + this.status({fill: 'red', shape: 'dot', text: error.message}); }) .once('listening', () => { testPort.once('close', () => { @@ -96,7 +96,7 @@ module.exports = function (RED) { username: config.username, port: config.port, pincode: config.pincode, - category: Accessory.Categories.TELEVISION + category: hap.Categories.TELEVISION, }); acc._server.on('listening', () => { @@ -138,62 +138,62 @@ module.exports = function (RED) { }; const setRemoteKey = (newValue, callback) => { - const msg = {topic: 'RemoteKey'}; + const message = {topic: 'RemoteKey'}; switch (newValue) { case 0: - msg.payload = 'REWIND'; - msg.lgtv = 'REWIND'; + message.payload = 'REWIND'; + message.lgtv = 'REWIND'; break; case 1: - msg.payload = 'FAST_FORWARD'; - msg.lgtv = 'FASTFORWARD'; + message.payload = 'FAST_FORWARD'; + message.lgtv = 'FASTFORWARD'; break; case 2: - msg.payload = 'NEXT_TRACK'; + message.payload = 'NEXT_TRACK'; break; case 3: - msg.payload = 'PREVIOUS_TRACK'; + message.payload = 'PREVIOUS_TRACK'; break; case 4: - msg.payload = 'ARROW_UP'; - msg.lgtv = 'UP'; + message.payload = 'ARROW_UP'; + message.lgtv = 'UP'; break; case 5: - msg.payload = 'ARROW_DOWN'; - msg.lgtv = 'DOWN'; + message.payload = 'ARROW_DOWN'; + message.lgtv = 'DOWN'; break; case 6: - msg.payload = 'ARROW_LEFT'; - msg.lgtv = 'LEFT'; + message.payload = 'ARROW_LEFT'; + message.lgtv = 'LEFT'; break; case 7: - msg.payload = 'ARROW_RIGHT'; - msg.lgtv = 'RIGHT'; + message.payload = 'ARROW_RIGHT'; + message.lgtv = 'RIGHT'; break; case 8: - msg.payload = 'SELECT'; - msg.lgtv = 'ENTER'; + message.payload = 'SELECT'; + message.lgtv = 'ENTER'; break; case 9: - msg.payload = 'BACK'; - msg.lgtv = 'BACK'; + message.payload = 'BACK'; + message.lgtv = 'BACK'; break; case 10: - msg.payload = 'EXIT'; - msg.lgtv = 'EXIT'; + message.payload = 'EXIT'; + message.lgtv = 'EXIT'; break; case 11: - msg.payload = 'PLAY_PAUSE'; + message.payload = 'PLAY_PAUSE'; break; case 15: - msg.payload = 'INFORMATION'; - msg.lgtv = 'INFO'; + message.payload = 'INFORMATION'; + message.lgtv = 'INFO'; break; default: } - msg.characteristicValue = newValue; - this.send(msg); + message.characteristicValue = newValue; + this.send(message); callback(null); }; @@ -219,20 +219,20 @@ module.exports = function (RED) { speakerService.getCharacteristic(Characteristic.VolumeSelector) .on('set', setVolumeSelector); - this.on('input', msg => { - switch (msg.topic) { + this.on('input', message => { + switch (message.topic) { case 'InputSource': { - let identifier = msg.payload; - if (typeof msg.payload === 'string') { - config.inputsources.forEach((src, i) => { - if (msg.payload === src.name) { + let identifier = message.payload; + if (typeof message.payload === 'string') { + for (const [i, src] of config.inputsources.entries()) { + if (message.payload === src.name) { identifier = i + 1; } - }); + } } if (config.inputsources[identifier - 1]) { - this.debug('set ActiveIdentifier ' + identifier + ' (payload was ' + msg.payload + ')'); + this.debug('set ActiveIdentifier ' + identifier + ' (payload was ' + message.payload + ')'); this.status({shape: 'dot', fill: 'blue', text: config.inputsources[identifier - 1].name}); tvService.updateCharacteristic(Characteristic.ActiveIdentifier, identifier); } @@ -241,9 +241,9 @@ module.exports = function (RED) { } default: - this.debug('set Active ' + msg.payload); - this.status({shape: msg.payload ? 'dot' : 'ring', fill: msg.payload ? 'blue' : 'grey'}); - tvService.updateCharacteristic(Characteristic.Active, msg.payload ? 1 : 0); + this.debug('set Active ' + message.payload); + this.status({shape: message.payload ? 'dot' : 'ring', fill: message.payload ? 'blue' : 'grey'}); + tvService.updateCharacteristic(Characteristic.Active, message.payload ? 1 : 0); } }); diff --git a/nodes/redmatic-homekit-universal.html b/nodes/redmatic-homekit-universal.html index fab8929..88946ac 100644 --- a/nodes/redmatic-homekit-universal.html +++ b/nodes/redmatic-homekit-universal.html @@ -23,7 +23,7 @@ 'AccessoryInformation', 'AirPurifier', 'AirQualitySensor', - 'BatteryService', + 'Battery', 'CarbonDioxideSensor', 'CarbonMonoxideSensor', 'ContactSensor', @@ -49,7 +49,7 @@ 'Outlet', 'SecuritySystem', 'ServiceLabel', - 'Slat', + 'Slats', 'SmokeSensor', 'Speaker', 'StatelessProgrammableSwitch', diff --git a/nodes/redmatic-homekit-universal.js b/nodes/redmatic-homekit-universal.js index 9f9345d..1684231 100644 --- a/nodes/redmatic-homekit-universal.js +++ b/nodes/redmatic-homekit-universal.js @@ -23,42 +23,42 @@ module.exports = function (RED) { .setCharacteristic(hap.Characteristic.SerialNumber, this.id) .setCharacteristic(hap.Characteristic.FirmwareRevision, version); - this.services.forEach(s => { + for (const s of this.services) { this.debug('addService ' + s.subtype + ' ' + s.service + ' ' + s.name); acc.addService(hap.Service[s.service], s.name, s.subtype); - }); + } acc.isConfigured = true; } this.listeners = []; - this.services.forEach(s => { + for (const s of this.services) { let service = acc.getService(s.subtype); if (!service) { this.debug('addService ' + s.subtype + ' ' + s.service + ' ' + s.name); service = acc.addService(hap.Service[s.service], s.name, s.subtype); } - service.characteristics.forEach(c => { + for (const c of service.characteristics) { this.addListener(s.subtype, c); - }); - }); + } + } - this.on('input', msg => { - const [subtype, c] = msg.topic.split('/'); + this.on('input', message => { + const [subtype, c] = message.topic.split('/'); const service = acc.getService(subtype); if (service) { if (!this.hasListener(subtype, c)) { this.addListener(subtype, service.getCharacteristic(hap.Characteristic[c])); } - if (typeof msg.payload === 'object') { - this.debug('setProps ' + msg.topic + ' ' + JSON.stringify(msg.payload)); - service.getCharacteristic(hap.Characteristic[c]).setProps(msg.payload); + if (typeof message.payload === 'object') { + this.debug('setProps ' + message.topic + ' ' + JSON.stringify(message.payload)); + service.getCharacteristic(hap.Characteristic[c]).setProps(message.payload); } else { - this.debug('-> hap ' + msg.topic + ' ' + msg.payload); - service.updateCharacteristic(hap.Characteristic[c], msg.payload); + this.debug('-> hap ' + message.topic + ' ' + message.payload); + service.updateCharacteristic(hap.Characteristic[c], message.payload); } } else { this.error('unknown subtype ' + subtype); @@ -66,10 +66,10 @@ module.exports = function (RED) { }); this.on('close', () => { - this.listeners.forEach(l => { + for (const l of this.listeners) { this.debug('remove change listener ' + l.subtype + ' ' + l.cName); l.characteristic.removeListener('change', l.listener); - }); + } }); } @@ -77,13 +77,13 @@ module.exports = function (RED) { const cName = c.displayName.replace(/ /g, ''); this.debug('create change listener ' + subtype + ' ' + cName); - const changeListener = obj => { + const changeListener = object => { const topic = subtype + '/' + cName; - this.debug('hap -> ' + topic + ' ' + obj.newValue); - if (obj && obj.context && obj.context.request) { + this.debug('hap -> ' + topic + ' ' + object.newValue); + if (object && object.context && object.context.request) { this.send({ topic, - payload: obj.newValue + payload: object.newValue, }); } }; @@ -94,13 +94,14 @@ module.exports = function (RED) { } hasListener(subtype, characteristicName) { - let res = false; - this.listeners.forEach(l => { + let result = false; + for (const l of this.listeners) { if (subtype === l.subtype && characteristicName === l.cName) { - res = true; + result = true; } - }); - return res; + } + + return result; } } diff --git a/nodes/redmatic-homekit-zigbee-devices.js b/nodes/redmatic-homekit-zigbee-devices.js index e5d1313..68c6099 100644 --- a/nodes/redmatic-homekit-zigbee-devices.js +++ b/nodes/redmatic-homekit-zigbee-devices.js @@ -4,19 +4,17 @@ const path = require('path'); module.exports = function (RED) { const knownDevices = {}; - RED.httpAdmin.get('/redmatic-homekit/zigbee-devices', RED.auth.needsPermission('redmatic.read'), (req, res) => { - if (knownDevices[req.query.id]) { - const devices = knownDevices[req.query.id].map(d => { - return { - ieeeAddr: d.ieeeAddr, - name: d.meta.name, - manufacturerName: d.manufacturerName, - modelID: d.modelID - }; - }); - res.status(200).send(JSON.stringify(devices)); + RED.httpAdmin.get('/redmatic-homekit/zigbee-devices', RED.auth.needsPermission('redmatic.read'), (request, response) => { + if (knownDevices[request.query.id]) { + const devices = knownDevices[request.query.id].map(d => ({ + ieeeAddr: d.ieeeAddr, + name: d.meta.name, + manufacturerName: d.manufacturerName, + modelID: d.modelID, + })); + response.status(200).send(JSON.stringify(devices)); } else { - res.status(500).send(`500 Internal Server Error: Unknown Herdsman ID ${req.query.id}`); + response.status(500).send(`500 Internal Server Error: Unknown Herdsman ID ${request.query.id}`); } }); @@ -45,16 +43,16 @@ module.exports = function (RED) { this.zigbeeDevices = []; - fs.readdirSync(path.join(__dirname, '..', 'zigbee-devices')).forEach(file => { + for (const file of fs.readdirSync(path.join(__dirname, '..', 'zigbee-devices'))) { if (file.endsWith('.js')) { this.zigbeeDevices.push(require(path.join(__dirname, '..', 'zigbee-devices', file))); } - }); + } this.proxy.on('ready', () => { this.devices = this.herdsman.getDevices(); - this.devices.forEach(device => { + for (const device of this.devices) { const Adapter = this.findAdapter(device); if (Adapter) { knownDevices[this.id].push(device); @@ -68,7 +66,7 @@ module.exports = function (RED) { } else { this.debug(`no adapter found for ${device.ieeeAddr} ${device.meta.name}`); } - }); + } }); } diff --git a/package.json b/package.json index bcf51b5..19966f1 100644 --- a/package.json +++ b/package.json @@ -35,16 +35,20 @@ } }, "dependencies": { - "hap-nodejs": "0.4.52", + "hap-nodejs": "0.10.0", "homebridge-camera-ffmpeg": "0.1.14" }, "devDependencies": { - "xo": "0.24.0" + "xo": "0.48.0" }, "xo": { "space": 4, + "prettier": 0, "rules": { "unicorn/filename-case": 0, + "unicorn/prefer-module": 0, + "unicorn/numeric-separators-style": 0, + "import/extensions": 0, "capitalized-comments": 0 } }, diff --git a/zigbee-devices/lib/accessory.js b/zigbee-devices/lib/accessory.js index d0df527..f00db00 100644 --- a/zigbee-devices/lib/accessory.js +++ b/zigbee-devices/lib/accessory.js @@ -2,24 +2,26 @@ class Service { constructor(acc, subtype) { this.acc = acc; this.subtype = subtype; + // eslint-disable-next-line no-constructor-return return this; } sub(endpoint, cluster, attribute, callback) { - this.acc.proxy.on('message', msg => { - if (msg.device.ieeeAddr === this.acc.device.ieeeAddr && msg.endpoint.ID === endpoint && msg.cluster === cluster && typeof msg.data[attribute] !== 'undefined') { - this.acc.node.debug(`sub msg ${this.acc.device.meta.name} ${msg.cluster} ${JSON.stringify(msg.data)}`); - callback(msg.data[attribute]); + this.acc.proxy.on('message', message => { + if (message.device.ieeeAddr === this.acc.device.ieeeAddr && message.endpoint.ID === endpoint && message.cluster === cluster && typeof message.data[attribute] !== 'undefined') { + this.acc.node.debug(`sub msg ${this.acc.device.meta.name} ${message.cluster} ${JSON.stringify(message.data)}`); + callback(message.data[attribute]); } }); if (this.acc.device.getEndpoint(endpoint) && this.acc.device.getEndpoint(endpoint).clusters[cluster]) { - const val = this.acc.device.getEndpoint(endpoint).clusters[cluster].attributes[attribute]; - this.acc.node.debug(`sub initial ${this.acc.device.meta.name} ${cluster} ${val}`); - callback(val); + const value = this.acc.device.getEndpoint(endpoint).clusters[cluster].attributes[attribute]; + this.acc.node.debug(`sub initial ${this.acc.device.meta.name} ${cluster} ${value}`); + callback(value); } } + // eslint-disable-next-line max-params get(characteristic, endpoint, cluster, attribute, transform) { if (!transform) { transform = function (data) { @@ -27,31 +29,32 @@ class Service { }; } - this.acc.proxy.on('message', msg => { - if (msg.device.ieeeAddr === this.acc.device.ieeeAddr && msg.endpoint.ID === endpoint && msg.cluster === cluster && typeof msg.data[attribute] !== 'undefined') { - this.acc.node.debug(`msg ${this.acc.device.meta.name} ${msg.cluster} ${characteristic} ${JSON.stringify(msg.data)}`); + this.acc.proxy.on('message', message => { + if (message.device.ieeeAddr === this.acc.device.ieeeAddr && message.endpoint.ID === endpoint && message.cluster === cluster && typeof message.data[attribute] !== 'undefined') { + this.acc.node.debug(`msg ${this.acc.device.meta.name} ${message.cluster} ${characteristic} ${JSON.stringify(message.data)}`); - const val = transform(msg.data[attribute]); - if (typeof val !== 'undefined' && val !== null && !this.suppressUpdate) { - this.acc.updateCharacteristic(this.subtype, characteristic, val); + const value = transform(message.data[attribute]); + if (typeof value !== 'undefined' && value !== null && !this.suppressUpdate) { + this.acc.updateCharacteristic(this.subtype, characteristic, value); } } }); if (this.acc.device.getEndpoint(endpoint) && this.acc.device.getEndpoint(endpoint).clusters[cluster]) { - let val = transform(this.acc.device.getEndpoint(endpoint).clusters[cluster].attributes[attribute]); - if (isNaN(val)) { - val = 0; + let value = transform(this.acc.device.getEndpoint(endpoint).clusters[cluster].attributes[attribute]); + if (Number.isNaN(value)) { + value = 0; } - if (val !== null) { - this.acc.updateCharacteristic(this.subtype, characteristic, val, true); + if (value !== null) { + this.acc.updateCharacteristic(this.subtype, characteristic, value, true); } } return this; } + // eslint-disable-next-line max-params set(characteristic, endpoint, cluster, transform, suppressUpdate) { this.acc.addListener('set', this.subtype, characteristic, (value, callback) => { this.acc.node.debug(`set ${this.acc.device.meta.name} ${characteristic} ${value}`); @@ -93,8 +96,8 @@ class Service { return this; } - fault(datapointNameArr, transformArr) { - this.acc.datapointsFault(this.subtype, datapointNameArr, transformArr); + fault(datapointNameArray, transformArray) { + this.acc.datapointsFault(this.subtype, datapointNameArray, transformArray); return this; } } diff --git a/zigbee-devices/lumi.sensor_magnet.js b/zigbee-devices/lumi.sensor_magnet.js index 7b4afa5..f40fc50 100644 --- a/zigbee-devices/lumi.sensor_magnet.js +++ b/zigbee-devices/lumi.sensor_magnet.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class LumiMagnet extends Accessory { static get manufacturerName() { @@ -14,10 +14,8 @@ module.exports = class LumiMagnet extends Accessory { this.addService('ContactSensor', device.meta.name) .get('ContactSensorState', 1, 'genOnOff', 'onOff'); - this.addService('BatteryService', device.meta.name) - .get('StatusLowBattery', 1, 'genBasic', '65281', data => { - return data['1'] < 2775 ? 1 : 0; - }) + this.addService('Battery', device.meta.name) + .get('StatusLowBattery', 1, 'genBasic', '65281', data => data['1'] < 2775 ? 1 : 0) .get('BatteryLevel', 1, 'genBasic', '65281', data => this.percent(data['1'], 2725, 3100)) .update('ChargingState', 2); } diff --git a/zigbee-devices/lumi.sensor_motion.js b/zigbee-devices/lumi.sensor_motion.js index 1558925..25cd8fa 100644 --- a/zigbee-devices/lumi.sensor_motion.js +++ b/zigbee-devices/lumi.sensor_motion.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class LumiMotion extends Accessory { static get manufacturerName() { @@ -11,7 +11,7 @@ module.exports = class LumiMotion extends Accessory { init(device) { this.node.debug(`init lumi.sensor_motion ${this.device.ieeeAddr} ${this.device.meta.name}`); - const motionTimeoutVal = 3 * 60 * 1000; + const motionTimeoutValue = 3 * 60 * 1000; let motionTimeout; const motionService = this.addService('MotionSensor', device.meta.name) @@ -23,14 +23,12 @@ module.exports = class LumiMotion extends Accessory { clearTimeout(motionTimeout); motionTimeout = setTimeout(() => { motionService.update('MotionDetected', false); - }, motionTimeoutVal); + }, motionTimeoutValue); return true; }); - this.addService('BatteryService', device.meta.name) - .get('StatusLowBattery', 1, 'genBasic', '65281', data => { - return data['1'] < 2775 ? 1 : 0; - }) + this.addService('Battery', device.meta.name) + .get('StatusLowBattery', 1, 'genBasic', '65281', data => data['1'] < 2775 ? 1 : 0) .get('BatteryLevel', 1, 'genBasic', '65281', data => this.percent(data['1'], 2725, 3100)) .update('ChargingState', 2); } diff --git a/zigbee-devices/lumi.sensor_wleak.js b/zigbee-devices/lumi.sensor_wleak.js index bea6fb4..6b316d7 100644 --- a/zigbee-devices/lumi.sensor_wleak.js +++ b/zigbee-devices/lumi.sensor_wleak.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class LumiWleak extends Accessory { static get manufacturerName() { @@ -14,10 +14,8 @@ module.exports = class LumiWleak extends Accessory { this.addService('LeakSensor', device.meta.name) .get('LeakDetected', 1, 'ssIasZone', 'zonestatus', data => data ? 1 : 0); - this.addService('BatteryService', device.meta.name) - .get('StatusLowBattery', 1, 'genBasic', '65281', data => { - return data['1'] < 2775 ? 1 : 0; - }) + this.addService('Battery', device.meta.name) + .get('StatusLowBattery', 1, 'genBasic', '65281', data => data['1'] < 2775 ? 1 : 0) .get('BatteryLevel', 1, 'genBasic', '65281', data => this.percent(data['1'], 2725, 3100)) .update('ChargingState', 2); } diff --git a/zigbee-devices/lumi.weather.js b/zigbee-devices/lumi.weather.js index 5b31ab0..4d08f2b 100644 --- a/zigbee-devices/lumi.weather.js +++ b/zigbee-devices/lumi.weather.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class LumiWeather extends Accessory { static get manufacturerName() { @@ -18,10 +18,8 @@ module.exports = class LumiWeather extends Accessory { this.addService('HumiditySensor', device.meta.name) .get('CurrentRelativeHumidity', 1, 'msRelativeHumidity', 'measuredValue', data => data / 100); - this.addService('BatteryService', device.meta.name) - .get('StatusLowBattery', 1, 'genBasic', '65281', data => { - return data['1'] < 2775 ? 1 : 0; - }) + this.addService('Battery', device.meta.name) + .get('StatusLowBattery', 1, 'genBasic', '65281', data => data['1'] < 2775 ? 1 : 0) .get('BatteryLevel', 1, 'genBasic', '65281', data => this.percent(data['1'], 2725, 3100)) .update('ChargingState', 2); } diff --git a/zigbee-devices/tradfri.controlOutlet.js b/zigbee-devices/tradfri.controlOutlet.js index c907227..bb7d730 100644 --- a/zigbee-devices/tradfri.controlOutlet.js +++ b/zigbee-devices/tradfri.controlOutlet.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class TradfriControlOutlet extends Accessory { static get manufacturerName() { @@ -17,8 +17,6 @@ module.exports = class TradfriControlOutlet extends Accessory { const ep = device.endpoints[0].ID; this.addService('Switch', device.meta.name) .get('On', ep, 'genOnOff', 'onOff', data => Boolean(data)) - .set('On', ep, 'genOnOff', data => { - return {command: data ? 'on' : 'off', payload: {}}; - }); + .set('On', ep, 'genOnOff', data => ({command: data ? 'on' : 'off', payload: {}})); } }; diff --git a/zigbee-devices/windowcovering.js b/zigbee-devices/windowcovering.js index ddfb1bf..750bd88 100644 --- a/zigbee-devices/windowcovering.js +++ b/zigbee-devices/windowcovering.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class ZllOnOff extends Accessory { static get manufacturerName() { @@ -22,11 +22,9 @@ module.exports = class ZllOnOff extends Accessory { return 100 - data; }) - .set('TargetPosition', ep, 'closuresWindowCovering', data => { - return {command: 'goToLiftPercentage', payload: {percentageliftvalue: 100 - data}}; - }); + .set('TargetPosition', ep, 'closuresWindowCovering', data => ({command: 'goToLiftPercentage', payload: {percentageliftvalue: 100 - data}})); - this.addService('BatteryService', device.meta.name) + this.addService('Battery', device.meta.name) .get('StatusLowBattery', 1, 'genPowerCfg', 'batteryPercentageRemaining', data => data < 10 ? 1 : 0) .get('BatteryLevel', 1, 'genPowerCfg', 'batteryPercentageRemaining', data => data) .update('ChargingState', 2); diff --git a/zigbee-devices/zll.color.js b/zigbee-devices/zll.color.js index d6dc6bf..622ed9f 100644 --- a/zigbee-devices/zll.color.js +++ b/zigbee-devices/zll.color.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class ZllColor extends Accessory { static get manufacturerName() { @@ -9,7 +9,7 @@ module.exports = class ZllColor extends Accessory { return [ 'TRADFRI bulb E27 CWS opal 600lm', 'TRADFRI bulb E26 CWS opal 600lm', - 'TRADFRI bulb E14 CWS opal 600lm' + 'TRADFRI bulb E14 CWS opal 600lm', ]; } @@ -23,14 +23,10 @@ module.exports = class ZllColor extends Accessory { let sat = 0; this.addService('Lightbulb', device.meta.name) .get('On', ep, 'genOnOff', 'onOff', data => Boolean(data)) - .set('On', ep, 'genOnOff', data => { - return {command: data ? 'on' : 'off', payload: {}}; - }) + .set('On', ep, 'genOnOff', data => ({command: data ? 'on' : 'off', payload: {}})) .get('Brightness', ep, 'genLevelCtrl', 'currentLevel', data => Math.round(data / 2.54)) - .set('Brightness', ep, 'genLevelCtrl', data => { - return {command: 'moveToLevel', payload: {level: Math.round(data * 2.54), transtime: 0}}; - }) + .set('Brightness', ep, 'genLevelCtrl', data => ({command: 'moveToLevel', payload: {level: Math.round(data * 2.54), transtime: 0}})) .get('Hue', ep, 'lightingColorCtrl', 'enhancedCurrentHue', data => Math.round(data / 65535 * 360)) .set('Hue', ep, 'lightingColorCtrl', data => { diff --git a/zigbee-devices/zll.dim.js b/zigbee-devices/zll.dim.js index ab1c789..1efc186 100644 --- a/zigbee-devices/zll.dim.js +++ b/zigbee-devices/zll.dim.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class ZllDim extends Accessory { static get manufacturerName() { @@ -17,7 +17,7 @@ module.exports = class ZllDim extends Accessory { 'TRADFRI bulb GU10 WW 400lm', 'TRADFRI bulb GU10 W 400lm', 'TRADFRI bulb E27 opal 1000lm', - 'TRADFRI bulb E27 W opal 1000lm' + 'TRADFRI bulb E27 W opal 1000lm', ]; } @@ -30,13 +30,9 @@ module.exports = class ZllDim extends Accessory { const ep = device.endpoints[0].ID; this.addService('Lightbulb', device.meta.name) .get('On', ep, 'genOnOff', 'onOff', data => Boolean(data)) - .set('On', ep, 'genOnOff', data => { - return {command: data ? 'on' : 'off', payload: {}}; - }) + .set('On', ep, 'genOnOff', data => ({command: data ? 'on' : 'off', payload: {}})) .get('Brightness', ep, 'genLevelCtrl', 'currentLevel', data => Math.round(data / 2.54)) - .set('Brightness', ep, 'genLevelCtrl', data => { - return {command: 'moveToLevel', payload: {level: Math.round(data * 2.54), transtime: 0}}; - }); + .set('Brightness', ep, 'genLevelCtrl', data => ({command: 'moveToLevel', payload: {level: Math.round(data * 2.54), transtime: 0}})); } }; diff --git a/zigbee-devices/zll.extendedcolor.js b/zigbee-devices/zll.extendedcolor.js index 9eaa1ac..b2c648a 100644 --- a/zigbee-devices/zll.extendedcolor.js +++ b/zigbee-devices/zll.extendedcolor.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class ZllExtColor extends Accessory { static get manufacturerName() { @@ -20,14 +20,10 @@ module.exports = class ZllExtColor extends Accessory { const ep = device.endpoints[0].ID; this.addService('Lightbulb', device.meta.name) .get('On', ep, 'genOnOff', 'onOff', data => Boolean(data)) - .set('On', ep, 'genOnOff', data => { - return {command: data ? 'on' : 'off', payload: {}}; - }) + .set('On', ep, 'genOnOff', data => ({command: data ? 'on' : 'off', payload: {}})) .get('Brightness', ep, 'genLevelCtrl', 'currentLevel', data => Math.round(data / 2.54)) - .set('Brightness', ep, 'genLevelCtrl', data => { - return {command: 'moveToLevel', payload: {level: Math.round(data * 2.54), transtime: 0}}; - }) + .set('Brightness', ep, 'genLevelCtrl', data => ({command: 'moveToLevel', payload: {level: Math.round(data * 2.54), transtime: 0}})) .get('Hue', ep, 'lightingColorCtrl', 'enhancedCurrentHue', data => Math.round(data / 65535 * 360)) .set('Hue', ep, 'lightingColorCtrl', data => { diff --git a/zigbee-devices/zll.onoff.js b/zigbee-devices/zll.onoff.js index 20dad9c..35718a8 100644 --- a/zigbee-devices/zll.onoff.js +++ b/zigbee-devices/zll.onoff.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class ZllOnOff extends Accessory { static get manufacturerName() { @@ -18,8 +18,6 @@ module.exports = class ZllOnOff extends Accessory { const ep = device.endpoints[0].ID; this.addService('Switch', device.meta.name) .get('On', ep, 'genOnOff', 'onOff', data => Boolean(data)) - .set('On', ep, 'genOnOff', data => { - return {command: data ? 'on' : 'off', payload: {}}; - }); + .set('On', ep, 'genOnOff', data => ({command: data ? 'on' : 'off', payload: {}})); } }; diff --git a/zigbee-devices/zll.tw.js b/zigbee-devices/zll.tw.js index a35e314..3379aaf 100644 --- a/zigbee-devices/zll.tw.js +++ b/zigbee-devices/zll.tw.js @@ -1,4 +1,4 @@ -const Accessory = require('./lib/accessory'); +const Accessory = require('./lib/accessory.js'); module.exports = class ZllTw extends Accessory { static get manufacturerName() { @@ -19,7 +19,7 @@ module.exports = class ZllTw extends Accessory { 'TRADFRI bulb E27 WS opal 1000lm', 'TRADFRI bulb E26 WS opal 1000lm', 'TRADFRI bulb E27 WS clear 806lm', - 'LEPTITER Recessed spot light, dimmable, white spectrum' + 'LEPTITER Recessed spot light, dimmable, white spectrum', ]; } @@ -32,18 +32,12 @@ module.exports = class ZllTw extends Accessory { const ep = device.endpoints[0].ID; this.addService('Lightbulb', device.meta.name) .get('On', ep, 'genOnOff', 'onOff', data => Boolean(data)) - .set('On', ep, 'genOnOff', data => { - return {command: data ? 'on' : 'off', payload: {}}; - }) + .set('On', ep, 'genOnOff', data => ({command: data ? 'on' : 'off', payload: {}})) .get('Brightness', ep, 'genLevelCtrl', 'currentLevel', data => Math.round(data / 2.54)) - .set('Brightness', ep, 'genLevelCtrl', data => { - return {command: 'moveToLevel', payload: {level: Math.round(data * 2.54), transtime: 0}}; - }) + .set('Brightness', ep, 'genLevelCtrl', data => ({command: 'moveToLevel', payload: {level: Math.round(data * 2.54), transtime: 0}})) .get('ColorTemperature', ep, 'lightingColorCtrl', 'colorTemperature', data => data) - .set('ColorTemperature', ep, 'lightingColorCtrl', data => { - return {command: 'moveToColorTemp', payload: {colortemp: data, transtime: 0}}; - }); + .set('ColorTemperature', ep, 'lightingColorCtrl', data => ({command: 'moveToColorTemp', payload: {colortemp: data, transtime: 0}})); } }; From 71760b93bbdee160c7798680d3e295985d84273f Mon Sep 17 00:00:00 2001 From: sreinhold95 Date: Mon, 6 Jun 2022 15:30:54 +0200 Subject: [PATCH 2/2] fix HMIPW-DRD3 Multi accessory --- homematic-devices/hmipw-drd3.js | 150 +++++++++++++----- nodes/redmatic-homekit-homematic-devices.html | 4 +- 2 files changed, 115 insertions(+), 39 deletions(-) diff --git a/homematic-devices/hmipw-drd3.js b/homematic-devices/hmipw-drd3.js index 18d5b08..35865f3 100644 --- a/homematic-devices/hmipw-drd3.js +++ b/homematic-devices/hmipw-drd3.js @@ -1,52 +1,128 @@ +/* eslint-disable no-new */ + const Accessory = require('./lib/accessory'); -module.exports = class HmipwDrd extends Accessory { - init(config, node) { - const {ccu} = node; +function addService(type, name, channel) { + let service + this.node.debug("HMIPW-DRD3: "+ name +" "+channel); + switch (type) { + case 'ValveIrrigation': + // intentional fallthrough + case 'Valve': + // intentional fallthrough + case 'Lightbulb': + service=this.addService(type,name); + service.get('On', channel + '.LEVEL', value => { + this.node.debug("HMIPW-DRD3 get : "+channel); + valueBrightness = value; + return value > 0; + }) - let valueBrightness = 0; + service.set('On', (value, callback) => { + this.node.debug("HMIPW-DRD3 set : "+channel); + if (value) { + setTimeout(() => { + if (valueBrightness === 0) { + value = 1; + } else { + value = valueBrightness / 100; + } + this.ccuSetValue(channel + '.LEVEL', value, callback); + }, 100); + } else { + this.ccuSetValue(channel + '.LEVEL', 0, callback); + } + }) + + service.get('Brightness', channel + '.LEVEL', value => { + valueBrightness = value * 100; + return value * 100; + }) + + service.set('Brightness', channel + '.LEVEL', value => { + valueBrightness = value; + return value / 100; + }); + case 'Fan': + // intentional fallthrough + case 'Outlet': + // intentional fallthrough + default: + /*this.addService(type, name, type === 'Switch' ? '' : type) + .get('On', dp) + .set('On', dp);*/ + } +} + +class AccSingleService extends Accessory { + init(config, node) { + const {ccu} = node; + node.debug(config.accChannel + ' ' + "Lightbulb" + ' '); + addService.call(this, "Lightbulb", config.accChannelName, config.accChannel); + } +} + +class AccMultiService extends Accessory { + init(config, node) { + const {ccu} = node; + for (let j = 0; j < 3; j++) { for (let c = 0; c < 3; c++) { const i = (j * 4) + (c + 2); if ((c === 0 && this.option(i)) || (c !== 0 && this.option(i, 'enabled'))) { const channel = config.deviceAddress + ':' + i; const name = ccu.channelNames[channel]; + this.node.debug("HMIPW-DRD3 call MultiService Channel: "+name+" "+channel); + addService.call(this,"Lightbulb",name,channel) + } + } + } + } +} + +module.exports = class HmipwDrd { + option(id, option) { + let addr = this.config.description.ADDRESS; + if (!addr.includes(':')) { + addr = addr + ':' + id; + } + + let res; + + if (option) { + res = this.config.options[addr] && this.config.options[addr][option]; + } else { + res = !(this.config.options[addr] && this.config.options[addr].disabled); + } + + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); + return res; + } + + constructor(config, node) { + const {ccu} = node; + this.node = node; + this.ccu = ccu; + this.config = config; + if (this.option('SingleAccessory')) { + new AccMultiService(config, node); + } else { + for (let j = 0; j < 3; j++) { + for (let c = 0; c < 3; c++) { + const i = (j * 4) + (c + 2); + if ((c === 0 && this.option(i)) || (c !== 0 && this.option(i, 'enabled'))) { + const channel = config.deviceAddress + ':' + i; + const name = ccu.channelNames[channel]; + this.node.debug("HMIPW-DRD3 call SingleService Channel: "+name+" "+channel); + + const chConfig = Object.assign({}, config, {accChannel: channel,accChannelName: name}); + chConfig.description = Object.assign({}, config.description, {ADDRESS: channel}); - this.addService('Lightbulb', name) - - .get('On', channel + '.LEVEL', value => { - valueBrightness = value; - return value > 0; - }) - - .set('On', (value, callback) => { - if (value) { - setTimeout(() => { - if (valueBrightness === 0) { - value = 1; - } else { - value = valueBrightness / 100; - } - - this.ccuSetValue(channel + '.LEVEL', value, callback); - }, 100); - } else { - this.ccuSetValue(channel + '.LEVEL', 0, callback); - } - }) - - .get('Brightness', channel + '.LEVEL', value => { - valueBrightness = value * 100; - return value * 100; - }) - - .set('Brightness', channel + '.LEVEL', value => { - valueBrightness = value; - return value / 100; - }); + new AccSingleService(chConfig, node); + } } } } } -}; +}; \ No newline at end of file diff --git a/nodes/redmatic-homekit-homematic-devices.html b/nodes/redmatic-homekit-homematic-devices.html index 369ba46..91b1794 100644 --- a/nodes/redmatic-homekit-homematic-devices.html +++ b/nodes/redmatic-homekit-homematic-devices.html @@ -597,10 +597,10 @@ break; case 'hmipw-drd3': - addVirtualChannels(addr, 2, 12, 4); + addOption(addr, 'SingleAccessory'); + addVirtualChannels(addr, 2, channelCount -1, 4); break; - case 'hmipw-drs4': case 'hmipw-drs8': addOption(addr, 'SingleAccessory');