diff --git a/app.js b/app.js index 9f485ffc0d..0b2f34a216 100644 --- a/app.js +++ b/app.js @@ -1,26 +1,24 @@ -var express = require('express'), - reqlib = require('app-root-path').require, - logger = require('morgan'), - cookieParser = require('cookie-parser'), - bodyParser = require('body-parser'), - app = express(), - fs = require('fs'), - SerialPort = require('serialport'), - jsonStore = reqlib('/lib/jsonStore.js'), - cors = require('cors'), - ZWaveClient = reqlib('/lib/ZwaveClient'), - MqttClient = reqlib('/lib/MqttClient'), - Gateway = reqlib('/lib/Gateway'), - store = reqlib('config/store.js'), - config = reqlib('config/app.js'), - debug = reqlib('/lib/debug')('App'), - history = require('connect-history-api-fallback'), - utils = reqlib('/lib/utils.js'); +var express = require('express') +var reqlib = require('app-root-path').require +var logger = require('morgan') +var cookieParser = require('cookie-parser') +var bodyParser = require('body-parser') +var app = express() +var SerialPort = require('serialport') +var jsonStore = reqlib('/lib/jsonStore.js') +var cors = require('cors') +var ZWaveClient = reqlib('/lib/ZwaveClient') +var MqttClient = reqlib('/lib/MqttClient') +var Gateway = reqlib('/lib/Gateway') +var store = reqlib('config/store.js') +var debug = reqlib('/lib/debug')('App') +var history = require('connect-history-api-fallback') +var utils = reqlib('/lib/utils.js') var gw; //the gateway instance let io; -debug("Application path:" + utils.getPath(true)); +debug('Application path:' + utils.getPath(true)) // view engine setup app.set('views', utils.joinPath(false, 'views')); diff --git a/lib/Gateway.js b/lib/Gateway.js index 0055952980..e3c71ba3ef 100755 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -400,35 +400,6 @@ function copy (obj) { return JSON.parse(JSON.stringify(obj)) } -/** - * Get Hass configurations based on valueID units - * - * @param {String} units The valueID units - * @returns An array with compatible configurations - */ -// eslint-disable-next-line no-unused-vars -function typeByUnits (units) { - var cfg = null - - // TODO: Support more units: https://github.com/OpenZWave/open-zwave/blob/master/config/SensorMultiLevelCCTypes.xml - - if (/\b(%)\b/gi.test(units)) { - cfg = ['sensor_illuminance', 'sensor_humidity', 'sensor_gas_density'] - } else if (/\b(m\/s|mph|km\/h|kmh)\b/gi.test(units)) { - cfg = ['sensor_speed'] - } else if (/\b(°)\b/gi.test(units)) { - cfg = ['sensor_angle'] - } else if (/\b(c|f)\b/gi.test(units)) { - cfg = ['sensor_temperature'] - } else if (/\b(w|v|watt|volt|kw|kwh|kw\/h)\b/gi.test(units)) { - cfg = ['sensor_electricity'] - } else if (/\b(bar|pa|g\/m3|mmhg)\b/gi.test(units)) { - cfg = ['sensor_humidity'] - } - - return cfg -} - /** * Get the device Object to send in discovery payload * @@ -551,10 +522,10 @@ Gateway.prototype.parsePayload = function (payload, valueId, valueConf) { let op = valueConf.postOperation // revert operation to write - if (op.includes('/')) op = op.replace('/', '*') - else if (op.includes('*')) op = op.replace('*', '/') - else if (op.includes('+')) op = op.replace('+', '-') - else if (op.includes('-')) op = op.replace('-', '+') + if (op.includes('/')) op = op.replace(/\//, '*') + else if (op.includes('*')) op = op.replace(/\*/g, '/') + else if (op.includes('+')) op = op.replace(/\+/, '-') + else if (op.includes('-')) op = op.replace(/-/, '+') payload = eval(payload + op) } diff --git a/lib/MqttClient.js b/lib/MqttClient.js index 82503aefd0..536f29396f 100644 --- a/lib/MqttClient.js +++ b/lib/MqttClient.js @@ -222,11 +222,10 @@ function onMessageReceived (topic, payload) { */ MqttClient.prototype.getClientTopic = function (...devices) { var subTopic = '' - if (devices) { - for (var i = 0; i < devices.length; i++) { - var name = this.cleanName(devices[i]) - subTopic += '/' + DEVICES_PREFIX + '/' + name - } + + for (var i = 0; i < devices.length; i++) { + var name = this.cleanName(devices[i]) + subTopic += '/' + DEVICES_PREFIX + '/' + name } return this.config.prefix + '/' + CLIENTS_PREFIX + '/' + this.clientID + subTopic + '/status' @@ -236,7 +235,7 @@ MqttClient.prototype.cleanName = function (name) { if (!isNaN(name)) return name name = name.replace(/\s/g, '_') - return name.replace(/[+*#\\.''``!?^=(),""%[\]:;{}]+/g, '') + return name.replace(/[+*#\\.'`!?^=(),"%[\]:;{}]+/g, '') } /** diff --git a/lib/ZwaveClient.js b/lib/ZwaveClient.js index 01b72dc2e8..2e96e4658d 100644 --- a/lib/ZwaveClient.js +++ b/lib/ZwaveClient.js @@ -24,8 +24,6 @@ const ZWAVE_STATUS = { 6: 'closed' } -// eslint-disable-next-line no-unused-vars -const nop = () => { } const ZWAVE_LOG_FILE = utils.joinPath(storeDir, 'OZW_Log.txt') const readFile = (path) => new Promise((resolve, reject) => fs.readFile(path, 'utf8', (err, data) => err ? reject(err) : resolve(data))) @@ -521,25 +519,16 @@ function sceneEvent (nodeid, sceneCode) { } function notification (nodeid, notif, help) { - // eslint-disable-next-line no-unused-vars - var msg var ozwnode = this.nodes[nodeid] switch (notif) { - case 0: - msg = 'node' + nodeid + ': message complete' - break - case 1: - msg = 'node' + nodeid + ': timeout' - break - case 2: - msg = 'node' + nodeid + ': nop' + case 0: // message complete + case 1: // timeout + case 2: // nop break case 3: // awake case 4: // sleep case 5: // dead case 6: // alive - msg = 'node' + nodeid + ': node ' + NODE_STATUS[notif] - // eslint-disable-next-line no-case-declarations const ready = notif !== 5 // eslint-disable-next-line no-case-declarations @@ -555,10 +544,6 @@ function notification (nodeid, notif, help) { this.emit('nodeStatus', ozwnode) } - - break - default: - msg = 'Unknown notification code ' + notif } debug('Notification from node %d: %s (%s)', nodeid, help, notif) diff --git a/lib/jsonStore.js b/lib/jsonStore.js index 70b182ff64..2edcbc1a7b 100644 --- a/lib/jsonStore.js +++ b/lib/jsonStore.js @@ -72,4 +72,4 @@ StorageHelper.prototype.put = function (model, data) { } // eslint-disable-next-line camelcase -var storage_helper = module.exports = exports = new StorageHelper() +var storage_helper = module.exports = new StorageHelper()