From 5dc13045581e8dc7895d81c1e6565eb3ccbea7f0 Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Wed, 4 Sep 2024 00:22:32 +0800 Subject: [PATCH] * (bluefox) Formatting of the code --- README.md | 3 + lib/devices.js | 16 +- lib/dontBeSoSoef.js | 478 ++++++++++++++++++-------------------------- main.js | 149 +++++++++----- 4 files changed, 305 insertions(+), 341 deletions(-) diff --git a/README.md b/README.md index 5fc8b8f..facbadd 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,9 @@ For example, `red = 0`, blue and green will stay unchanged. Placeholder for the next version (at the beginning of the line): ### **WORK IN PROGRESS** --> +### **WORK IN PROGRESS** +* (bluefox) Formatting of the code + ### 1.3.3 (2024-09-03) * (bluefox) Just renamed some functions diff --git a/lib/devices.js b/lib/devices.js index a1d6f96..5007207 100644 --- a/lib/devices.js +++ b/lib/devices.js @@ -116,7 +116,7 @@ exports.LD382A = { //power: ((data[13] & 0x01) ? false : true), progNo: data[3],//mode progOn: data[4] === 33, //modeRun - preogSpeed: data[5], //modeSpeed + progSpeed: data[5], //modeSpeed red: data[6], green: data[7], blue: data[8], @@ -148,15 +148,15 @@ exports.LD686 = { if (data[0] !== 129) { return [0, null]; } - //[129, 4, 35, 97, 33, 9, 11, 22, 33, 255, 3, 0, 0, 119] + // [129, 4, 35, 97, 33, 9, 11, 22, 33, 255, 3, 0, 0, 119] return [14, { - //power: ((data[2] === 0x23) ? true : false), + // power: ((data[2] === 0x23) ? true : false), on: (data[2] === 0x23), - //power: ((data[13] & 0x01) ? true : false), - //power: ((data[13] & 0x01) ? false : true), - progNo: data[3],//mode - progOn: data[4] === 33, //modeRun - preogSpeed: data[5], //modeSpeed + // power: ((data[13] & 0x01) ? true : false), + // power: ((data[13] & 0x01) ? false : true), + progNo: data[3], // mode + progOn: data[4] === 33, // modeRun + progSpeed: data[5], // modeSpeed red: data[6], green: data[7], blue: data[8], diff --git a/lib/dontBeSoSoef.js b/lib/dontBeSoSoef.js index e42a105..016e8ff 100644 --- a/lib/dontBeSoSoef.js +++ b/lib/dontBeSoSoef.js @@ -11,9 +11,9 @@ const utils = require(`@iobroker/adapter-core`); if (!Object.assign) { Object.prototype.assign = function (target) { target = target || {}; - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; - for (var key in source) { + for (let i = 1; i < arguments.length; i++) { + const source = arguments[i]; + for (const key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } @@ -25,86 +25,114 @@ if (!Object.assign) { function hasProp (obj, propString) { - if (!obj) return false; - var ar = propString.split('.'); - var len = ar.length; - for (var i = 0; i < len; i++) { + if (!obj) { + return false; + } + const ar = propString.split('.'); + const len = ar.length; + for (let i = 0; i < len; i++) { obj = obj[ar[i]]; - if (obj === undefined) return false; + if (obj === undefined) { + return false; + } } return true; } + exports.hasProp = hasProp; exports.hasProperty = hasProp; -function getLastValidProp (obj, propString) { - if (!obj) return undefined; - var ar = propString.split('.'); - var len = ar.length; - for (var i = 0; i < len; i++) { - if (obj[ar[i]] === undefined) return obj; +function getLastValidProp(obj, propString) { + if (!obj) { + return undefined; + } + const ar = propString.split('.'); + const len = ar.length; + for (let i = 0; i < len; i++) { + if (obj[ar[i]] === undefined) { + return obj; + } obj = obj[ar[i]]; } return obj; } exports.getLastValidProp = getLastValidProp; -function getLastValidPropEx (obj, propString) { - if (!obj) return undefined; - var ar = propString.split('.'); - var len = ar.length; - for (var i = 0; i < len; i++) { +function getLastValidPropEx(obj, propString) { + if (!obj) { + return undefined; + } + const ar = propString.split('.'); + const len = ar.length; + for (let i = 0; i < len; i++) { if (obj[ar[i]] === undefined) { - var ret = { obj: {}, invalifName: '', errPath: ''}; - try { ret = {obj: obj, invalidName: ar[i], errPath: ar.slice(i).join('.')}; } - catch (e) {} + let ret = { obj: {}, invalidName: '', errPath: '' }; + try { + ret = { + obj, + invalidName: ar[i], + errPath: ar.slice(i).join('.'), + }; + } catch { + // ignore + } return ret; } obj = obj[ar[i]]; } - return { obj: {}, invalifName: '', errPath: ''}; + return { obj: {}, invalidName: '', errPath: ''}; } exports.getLastValidPropEx = getLastValidPropEx; - -function getProp (obj, propString) { - if (!obj) return undefined; - var ar = propString.split('.'); - var len = ar.length; - for (var i = 0; i < len; i++) { +function getProp(obj, propString) { + if (!obj) { + return undefined; + } + const ar = propString.split('.'); + const len = ar.length; + for (let i = 0; i < len; i++) { obj = obj[ar[i]]; - if (obj === undefined) return undefined; + if (obj === undefined) { + return undefined; + } } return obj; } exports.getProp = getProp; function safeFunction(root, path, log) { - var fn = getProp(root, path); - if (typeof fn === 'function') return fn; + const fn = getProp(root, path); + if (typeof fn === 'function') { + return fn; + } if (log) { - var err = getLastValidPropEx(root, path); - if (typeof log !== 'function') log = adapter.log.debug; - log(err.errPath + ' is not a function (' + path +')'); + const err = getLastValidPropEx(root, path); + if (typeof log !== 'function') { + log = adapter.log.debug; + } + log(`${err.errPath} is not a function (${path})`); } return function (params, callback) { - if (!arguments.length) return; - var fn = arguments [arguments.length-1]; + if (!arguments.length) { + return; + } + const fn = arguments[arguments.length - 1]; if (typeof fn === 'function') { - fn(new Error(path + ' is not a function')); + fn(new Error(`${path} is not a function`)); } - } + }; } exports.safeFunction = safeFunction; -exports.getFnProp = function(root, path, log) { - if (typeof log !== 'function') log = function() {}; +exports.getFnProp = function (root, path, log) { + if (typeof log !== 'function') { + log = function() {}; + } return safeFunction(root, path, log); }; //////////////////////////////////////////////////////////////////////////////////// var njs = { - pasProp: hasProp, iscb: function (cb) { return typeof cb === 'function'; @@ -117,12 +145,13 @@ var njs = { }, _fullExtend: function (dest, from) { - var props = Object.getOwnPropertyNames(from), destination; + const props = Object.getOwnPropertyNames(from); + let destination; props.forEach(function (name) { if (typeof from[name] === 'object') { if (typeof dest[name] !== 'object') { - dest[name] = {} + dest[name] = {}; } _fullExtend(dest[name],from[name]); } else { @@ -137,16 +166,17 @@ var njs = { }, clone: function (from) { - var props = Object.getOwnPropertyNames(from), destination, dest = {}; + const props = Object.getOwnPropertyNames(from); + let destination; + const dest = {}; props.forEach(function (name) { if (from[name] instanceof Array) { //dest[name] = new Array(from[name]); dest[name] = [].concat(from[name]); - } else - if (typeof from[name] === 'object') { + } else if (typeof from[name] === 'object') { if (typeof dest[name] !== 'object') { - dest[name] = {} + dest[name] = {}; } _fullExtend(dest[name],from[name]); } else { @@ -380,7 +410,9 @@ var njs = { formatValue: function (value, decimals, _format) { if (_format === undefined) _format = ".,"; - if (typeof value !== "number") value = parseFloat(value); + if (typeof value !== "number") { + value = parseFloat(value); + } var ret = isNaN(value) ? "" : value.toFixed(decimals || 0).replace(_format[0], _format[1]).replace(/\B(?=(\d{3})+(?!\d))/g, _format[0]); return (ret); @@ -399,7 +431,9 @@ function extendGlobalNamespace() { } var adapter; -function errmsg () { console.debug("adapter not assigned, use Device.setAdapter(yourAdapter)") }; +function errmsg () { + console.debug('adapter not assigned, use Device.setAdapter(yourAdapter)'); +} if (hasProp(module, 'parent.exports.adapter')) { adapter = module.parent.exports.adapter; @@ -441,7 +475,6 @@ function setObjectNotExists(id, newObj, callback) { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function Devices (_adapter, _callback) { - if (!_adapter || !_adapter.adapterDir) { _callback = _adapter; _adapter = undefined; @@ -469,7 +502,9 @@ function Devices (_adapter, _callback) { this.getobjex = function (id) { var obj = this.get(id); - if (obj || !adapter || !adapter.namespace) return obj; + if (obj || !adapter || !adapter.namespace) { + return obj; + } id = id.substr(adapter.namespace.length+1); return objects[id]; }; @@ -517,8 +552,8 @@ function Devices (_adapter, _callback) { name: id, type: 'string', role: obj.type || 'state', - //enumerable: true - //writable: false + // enumerable: true + // writable: false }, native: { } }; @@ -534,7 +569,7 @@ function Devices (_adapter, _callback) { //that.states[newobj._id] = newobj; objects[newobj._id] = newobj; if (val !== undefined) { - that.setState(newobj._id, val, true) + that.setState(newobj._id, val, true); } } safeCallback(callback, err, o); @@ -552,7 +587,7 @@ function Devices (_adapter, _callback) { this.setStateEx = function (id, newObj, ack, callback) { if (typeof ack === 'function') { callback = ack; - ack = true + ack = true; } if (typeof newObj !== 'object') { newObj = { val: newObj }; @@ -580,7 +615,6 @@ function Devices (_adapter, _callback) { } } if (showName && !hasProp(obj, 'common.name')) { - //_fullExtend(obj, { common: { name: showName}}); _setobjname(obj, showName); } return obj; @@ -995,7 +1029,7 @@ function savePrevVersion() { return; } set(); - }) + }); } function checkIfUpdated(doUpdateCallback, callback) { @@ -1095,13 +1129,11 @@ exports.Adapter = function (_args) { } catch (e) { callback(); } - } + }; } if (!options.stateChange && fns.onStateChange) { options.stateChange = function (id, state) { if (state && !state.ack) { - - ///!!/////xxxxxxxxxxx////////////////////////////////////// //var _id = id.substr(fns.adapter.namespace.length+1); //_id = id.slice(fns.adapter.namespace.length+1); @@ -1119,19 +1151,19 @@ exports.Adapter = function (_args) { checkIfUpdated(fns.onUpdate, function() { _main(fns.main); }); - } + }; } if (!options.objectChange) { options.objectChange = function (id, obj) { if (id && obj == null && global.devices) { global.devices.remove(idWithoutNamespace(id)); } - } + }; } if (!options.message && fns.onMessage) { options.message = function(obj) { if (obj) fns.onMessage(obj); - } + }; } fns.adapter = fns.adapter(options); if (!adapter || !adapter.adapterDir) { @@ -1141,11 +1173,11 @@ exports.Adapter = function (_args) { }; function changeAdapterConfig (_adapter, changeCallback, doneCallback) { - _adapter.getForeignObject("system.adapter." + _adapter.namespace, function (err, obj) { + _adapter.getForeignObject(`system.adapter.${_adapter.namespace}`, function (err, obj) { if (!err && obj && !obj.native) obj['native'] = {}; if (!err && obj && changeCallback(obj.native) !== false) { _adapter.setForeignObject(obj._id, obj, {}, function (err, s_obj) { - _adapter.log.info("soef.changeAdapterConfig: changed"); + _adapter.log.info('soef.changeAdapterConfig: changed'); //_adapter.config = obj.native; //?!? nrmalisieren fehlt dann!! //_adapter.normalizeConfig ... if (doneCallback) doneCallback(err, obj); @@ -1156,9 +1188,11 @@ function changeAdapterConfig (_adapter, changeCallback, doneCallback) { exports.changeAdapterConfig = changeAdapterConfig; exports.changeConfig = function changeConfig(changeCallback, doneCallback) { - if (!adapter) return false; - return changeAdapterConfig(adapter, changeCallback, doneCallback) -} + if (!adapter) { + return false; + } + return changeAdapterConfig(adapter, changeCallback, doneCallback); +}; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1186,11 +1220,12 @@ exports.TimeDiff = function () { this.start = process.hrtime(); return this; -} - +}; exports.bufferIndexOf = function (buffer, search, offset, encoding){ - if (!Buffer.isBuffer(buffer)) return -1; + if (!Buffer.isBuffer(buffer)) { + return -1; + } if (typeof offset === 'string') { encoding = offset; @@ -1204,8 +1239,12 @@ exports.bufferIndexOf = function (buffer, search, offset, encoding){ search = new Buffer([search]); break; default: - if (Array.isArray(search)) break; - if (Buffer.isBuffer(search)) break; + if (Array.isArray(search)) { + break; + } + if (Buffer.isBuffer(search)) { + break; + } return -1; } @@ -1218,24 +1257,31 @@ exports.bufferIndexOf = function (buffer, search, offset, encoding){ if (offset < 0) offset = 0; for (var i=offset; i < blen; i++) { - - if(buffer[i] != search[0]) continue; - for (var j=1; j= res.rows.length) return readyCallback && readyCallback(); - var o = res.rows[i++]; - if (o) callback(o, doIt, type); else doIt(); + if (i >= res.rows.length) { + return readyCallback && readyCallback(); + } + const o = res.rows[i++]; + if (o) { + callback(o, doIt, type); + } else { + doIt(); + } } doIt(); }); -}; +} njs.dcs.delOS = delObjectAndState; function delObjectAndState(id, options, callback) { @@ -1347,7 +1402,7 @@ function forEachObjectChild(id, options, readyCallback, callback) { forEachInSystemObjectView('state', id, doDevices, callback); }; -//callback first all devices, then all channels and then all states +// callback first all devices, then all channels and then all states njs.dcs.forEach2 = forEachObjectChild2; function forEachObjectChild2(id, options, readyCallback, callback) { if (typeof options === 'function') { @@ -1360,7 +1415,7 @@ function forEachObjectChild2(id, options, readyCallback, callback) { readyCallback = null; } - if (!adapter._namespaceRegExp.test(id)) id = adapter.namespace + (id ? '.' + id : ''); + if (!adapter._namespaceRegExp.test(id)) id = adapter.namespace + (id ? `.${id}` : ''); function doStates() { forEachInSystemObjectView('state', id, readyCallback, callback); @@ -1369,8 +1424,7 @@ function forEachObjectChild2(id, options, readyCallback, callback) { forEachInSystemObjectView('channel', id, doStates, callback); } forEachInSystemObjectView('device', id, doChannels, callback); -}; - +} njs.dcs.del = delObjectWithStates; function delObjectWithStates (id, options, callback) { @@ -1378,16 +1432,15 @@ function delObjectWithStates (id, options, callback) { callback = options; options = undefined; } - //if (!adapter._namespaceRegExp.test(id)) id = adapter.namespace + '.' + id; + // if (!adapter._namespaceRegExp.test(id)) id = adapter.namespace + '.' + id; exports.ns.add(id); delObjectAndState(id, options, function (err) { - forEachObjectChild(id, callback, function(o, next, type) { + forEachObjectChild(id, callback, function (o, next, type) { delObjectAndState(o.id, options, next); devices.remove(idWithoutNamespace(o.id)); }); }); -}; - +} njs.dcs.delall = function (callback) { var options = null; @@ -1399,30 +1452,30 @@ njs.dcs.delall = function (callback) { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function toHex (val) { - return ('0' + val.toString(16)).substr(-2); + return `0${val.toString(16)}`.substr(-2); } exports.toHex = toHex; function arrayToHex(ar, len) { - var s = ""; - if (len == undefined) len = ar.length; - for (var i=0; i { + if (typeof from[name] === 'object') { + if (typeof dest[name] !== 'object') { + dest[name] = {}; + } + _fullExtendEx(dest[name],from[name]); + } else { + destination = Object.getOwnPropertyDescriptor(from, name); + Object.defineProperty(dest, name, destination); + } + }); +} + +function fullExtendEx(dest, from) { + _fullExtendEx(dest, from); + return dest; +} + +function cloneEx(from) { + const props = Object.getOwnPropertyNames(from); + let destination; + const dest = {}; + + props.forEach(function (name) { + if (from[name] instanceof Array) { + //dest[name] = new Array(from[name]); + dest[name] = [].concat(from[name]); + } else if (typeof from[name] === 'object') { + if (typeof dest[name] !== 'object') { + dest[name] = {}; + } + _fullExtendEx(dest[name],from[name]); + } else { + destination = Object.getOwnPropertyDescriptor(from, name); + Object.defineProperty(dest, name, destination); + } + }); + return dest; +} + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// soef.extendAll(); @@ -15,12 +60,12 @@ const hex = soef.arrayToHex; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -const adapter = soef.Adapter ( +const adapter = soef.Adapter( main, onStateChange, onMessage, onUnload, - { name: 'wifilight' }, + {name: 'wifilight'}, ); function fromDeviceName(name) { @@ -29,7 +74,7 @@ function fromDeviceName(name) { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function onMessage (obj) { +function onMessage(obj) { if (!obj) { return; } @@ -48,7 +93,7 @@ function onMessage (obj) { }, function (result) { if (obj.callback) { - adapter.sendTo (obj.from, obj.command, JSON.stringify(result), obj.callback); + adapter.sendTo(obj.from, obj.command, JSON.stringify(result), obj.callback); } } ); @@ -59,7 +104,7 @@ function onMessage (obj) { break; } if (obj.callback) { - adapter.sendTo (obj.from, obj.command, obj.message, obj.callback); + adapter.sendTo(obj.from, obj.command, obj.message, obj.callback); } return true; } @@ -83,7 +128,7 @@ function onUnload(callback) { const cmds = require('./lib/devices'); const usedStateNames = { - online: { n: 'reachable', g: 1, val: false, common: { write: false, type: 'boolean', role: 'indicator.reachable'}}, + online: { n: 'reachable', g: 1, val: false, common: { write: false, type: 'boolean', role: 'indicator.reachable' }}, on: { n: 'on', g: 3, val: false, common: { type: 'boolean', role: 'switch' }}, bri: { n: 'bri', g: 3, val: 100, common: { type: 'number', min: 0, max: 100, unit: '%', desc: '0..100%', role: 'level.dimmer' }}, ct: { n: 'ct', g: 1, val: 0, common: { type: 'number', min: 0, max: 5000, unit: '°K', desc: 'temperature in °Kelvin 0..5000', role: 'level.color.temperature' }}, @@ -98,8 +143,8 @@ const usedStateNames = { refresh: { n: 'refresh', g: 1, val: false, common: { type: 'boolean', desc: 'read states from device' }}, transition: { n: 'trans', g: 1, val: 30, common: { type: 'number', unit: '\u2152 s', desc: 'in 10th seconds'} }, command: { n: 'command', g: 3, val: 'r:0, g:0, b:0, on:true, transition:30', desc: 'r:0, g:0, b:0, on:true, transition:2' }, - rgb: { n: 'rgb', g: 3, val: '', common: { type: 'text', desc: '000000..ffffff' , role: 'level.color.rgb'}}, - onTime: { n: 'onTime', g: 3, val: '', common: {}} + rgb: { n: 'rgb', g: 3, val: '', common: { type: 'text', desc: '000000..ffffff' , role: 'level.color.rgb' }}, + onTime: { n: 'onTime', g: 3, val: '', common: {} }, }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -189,7 +234,7 @@ WifiLight.prototype.run = function (cb) { this.queue = []; this.dataBuffer = new Uint8Array(200); this.dataBuffer.pos = 0; - this.states = { red: 0, green: 0, blue: 0 }; + this.states = {red: 0, green: 0, blue: 0}; this.start(cb); }.bind(this)); @@ -352,7 +397,7 @@ WifiLight.prototype.onStateChange = function (channel, stateName, val) { this.states.blue = 0; if (this.states.white !== undefined) this.states.white = 0; } - const o = fullExtend(this.getRGBStates(channel), colors); + const o = fullExtendEx(this.getRGBStates(channel), colors); adapter.log.debug(JSON.stringify(o)); if (o.x !== undefined) { transitionTime = o.x >> 0; @@ -382,16 +427,16 @@ WifiLight.prototype.stopRunningProgram = function () { this.clearQueue(); }; -WifiLight.prototype.runJsonProgram = function (channel, cmds) { +WifiLight.prototype.runJsonProgram = function (channel, cmds) { let i = -1; const self = this; - const lastCo = { red: self.states.red, green: self.states.green, blue: self.states.blue}; + const lastCo = {red: self.states.red, green: self.states.green, blue: self.states.blue}; this.prgTimer.clear(); self.clearQueue(); function doIt() { if (self.queue.length > 0) { - setTimeout(doIt, self.queue.length*2); + setTimeout(doIt, self.queue.length * 2); return; } if (++i >= cmds.length) { @@ -414,11 +459,11 @@ WifiLight.prototype.runJsonProgram = function (channel, cmds) { } self.prgTimer.set(doIt, 10 + delay * 10); } + if (cmds.length > 0) { this.refreshPaused = true; doIt(); - } - else this.stopRunningProgram(); + } else this.stopRunningProgram(); }; @@ -433,7 +478,7 @@ WifiLight.prototype.reconnect = function (cb, timeout) { } }; -WifiLight.prototype._write = function(data, cb) { +WifiLight.prototype._write = function (data, cb) { this.client.write(data, cb); }; @@ -491,7 +536,7 @@ WifiLight.prototype.destroyClient = function () { } }; -WifiLight.prototype.writeOnce = function(data, cb) { +WifiLight.prototype.writeOnce = function (data, cb) { if (this.client) { this.client.write(data, cb); return; @@ -523,7 +568,7 @@ WifiLight.prototype.getval = function (channel, state, def) { return def; }; -WifiLight.prototype.close = function() { +WifiLight.prototype.close = function () { this.clearQueue(); this.destroyClient(); if (this.writeTimeout) { @@ -564,11 +609,11 @@ WifiLight.prototype.directRefresh = function (channel) { this.write(channel, this.cmds.statusRequest); }; -WifiLight.prototype.refresh = function(channel, ctrl) { +WifiLight.prototype.refresh = function (channel, ctrl) { if (!this.cmds.statusRequest || this.refreshPaused) { return; } - this.addToQueue(channel, this.cmds.statusRequest, { ctrl: ctrl === undefined ? true : ctrl }); + this.addToQueue(channel, this.cmds.statusRequest, {ctrl: ctrl === undefined ? true : ctrl}); }; WifiLight.prototype.write = function (channel, cmd, cb) { @@ -594,7 +639,7 @@ WifiLight.prototype.write = function (channel, cmd, cb) { this._write(buf, cb); }; -WifiLight.prototype.clearQueue = function() { +WifiLight.prototype.clearQueue = function () { this.queue.length = 0; }; @@ -627,10 +672,15 @@ WifiLight.prototype.addToQueue = function (...args) { const last = cmd.length - 1; cmd.forEach((c, i) => { let sep = 0; - switch(c) { - case cmds.VARS.separator: sep = 1; break; - case cmds.VARS.sepNoDelay: sep = 2; break; - default: _cmd.push(c); + switch (c) { + case cmds.VARS.separator: + sep = 1; + break; + case cmds.VARS.sepNoDelay: + sep = 2; + break; + default: + _cmd.push(c); } if (sep || i === last) { this.queue.push({ @@ -662,7 +712,7 @@ WifiLight.prototype.exec = function () { if (!(akt.inProcess || (!akt.ctrl && akt.ts && akt.ts < new Date().getTime()))) { break; } - if (this.queue.length <= 1 && !akt.cmd.eq (this.cmds.statusRequest)) { + if (this.queue.length <= 1 && !akt.cmd.eq(this.cmds.statusRequest)) { this.directRefresh(akt.channel); } this.queue.shift(); @@ -689,7 +739,7 @@ WifiLight.prototype.fade = function (channel, rgbw, transitionTime) { b: this.states.blue, w: this.states.white, }; - const dif= { + const dif = { r: rgbw.r - co.r, g: rgbw.g - co.g, b: rgbw.b - co.b, @@ -716,7 +766,7 @@ WifiLight.prototype.fade = function (channel, rgbw, transitionTime) { if (co.w !== undefined) { co.w += dif.w; } - this.color(channel, roundRGB(co, true), { delay }); + this.color(channel, roundRGB(co, true), {delay}); } }; @@ -782,7 +832,7 @@ WifiLight.prototype.onData = function (data) { if (newPos > this.dataBuffer.length) { const b = new Uint8Array(newPos + 200); //const b = new Buffer(newPos + 200); - for (let i=0; i {}); - this.client.on('error', (/* error */) => {}); + this.client.on('message', (/* data, rinfo */) => { + }); + this.client.on('error', (/* error */) => { + }); this.client.on('close', (/* error */) => { this.client = null; adapter.log.debug('udp socked closed'); @@ -895,12 +947,12 @@ MiLight.prototype.color = function (channel, rgbw /* , opt */) { MiLight.prototype.pair = function (channel) { for (let i = 0; i < 3; i++) { - this.addToQueue(channel, this.pair, { delay: 1000 }); + this.addToQueue(channel, this.pair, {delay: 1000}); } }; MiLight.prototype.unPair = function (channel) { for (let i = 0; i < 15; i++) { - this.addToQueue(channel, this.unPair, { delay: 200 }); + this.addToQueue(channel, this.unPair, {delay: 200}); } }; @@ -927,13 +979,13 @@ MiLight.prototype.onStateChange = function (channel, stateName, val) { }; function checkDeletedDevices(cb) { - adapter.getDevices(function(err, res) { + adapter.getDevices(function (err, res) { if (err || !res || res.length <= 0) { return cb && cb(); } const reIp = /[^0-9]/g; const toDelete = []; - res.forEach(function(obj) { + res.forEach(function (obj) { const ar = obj._id.split('.'); const ip = ar[2].replace(reIp, '.'); const found = adapter.config.devices.find(v => v.ip === ip); // xxxx @@ -947,7 +999,7 @@ function checkDeletedDevices(cb) { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function normalizeConfig (config) { +function normalizeConfig(config) { let changed = false; const types = []; config.devices.forEach(d => { @@ -960,7 +1012,7 @@ function normalizeConfig (config) { const c = cmds[d.type]; if (!c) { let err = `config.device.type "${d.type}" (${d.name}) is not a known device type. Skipping this device!`; - if (!types.length) Object.keys(cmds).forEach(function(n) { + if (!types.length) Object.keys(cmds).forEach(function (n) { if (typeof cmds[n] === 'object' && cmds[n].on) { types.push(n); } @@ -979,12 +1031,12 @@ function normalizeConfig (config) { } d.port = parseInt(d.port) || (c && c.port ? c.port : dev && dev.port ? dev.port : 5577); - Object.keys(d).forEach(function(key) { + Object.keys(d).forEach(function (key) { changed = changed || d[key] !== old[key]; }); }); if (changed) { - soef.changeAdapterConfig (adapter, conf => conf.devices = config.devices); + soef.changeAdapterConfig(adapter, conf => conf.devices = config.devices); } } @@ -992,7 +1044,8 @@ function main() { if (!adapter.config.devices) { return; } - checkDeletedDevices((/* err */) => {}); + checkDeletedDevices((/* err */) => { + }); normalizeConfig(adapter.config); const miLight = []; @@ -1001,11 +1054,13 @@ function main() { if (adapter.config.devices[i].type === 'MiLight') { for (let zone = 0; zone <= 4; zone++) { miLight[zone] = new MiLight(adapter.config.devices[i], zone); - miLight[zone].run(() => {}); + miLight[zone].run(() => { + }); } } else { const wifiLight = new WifiLight(adapter.config.devices[i]); - wifiLight.run(() => {}); + wifiLight.run(() => { + }); wifiLight.bri('aaa', 100); } }