diff --git a/lib/discovery.js b/lib/discovery.js index aaf3e0b..f69c55e 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -2,11 +2,11 @@ Thanks to Jonas Hermsmeier who has written the original code, which can be found here: https://github.com/jhermsmeier/node-net-ssdp */ -var os = require( 'os' ) -var dgram = require( 'dgram' ) -var net = require( 'net' ) -var Emitter = require( 'events' ) -var SSDP = require( './ssdp' ) +var os = require('os') +var dgram = require('dgram') +var net = require('net') +var Emitter = require('events') +var SSDP = require('./ssdp') class Discovery extends Emitter { @@ -18,11 +18,11 @@ class Discovery extends Emitter { * @param {Number} [options.multicastTTL] * @returns {Discovery} */ - constructor( options ) { + constructor(options) { super() - options = Object.assign( {}, options ) + options = Object.assign({}, options) this.reuseAddr = options.reuseAddr !== false @@ -31,17 +31,17 @@ class Discovery extends Emitter { } - _createSockets( interfaces ) { + _createSockets(interfaces) { interfaces = interfaces || os.networkInterfaces() - Object.keys( interfaces ).forEach(( name ) => { - interfaces[ name ].forEach(( info ) => { + Object.keys(interfaces).forEach((name) => { + interfaces[name].forEach((info) => { // Skip internal interfaces - if( info.internal ) { return } + if (info.internal) { return } - var iface = new Interface( name, info ) + var iface = new Interface(name, info) iface.socket = dgram.createSocket({ type: iface.family === 'IPv6' ? 'udp6' : 'udp4', @@ -49,49 +49,49 @@ class Discovery extends Emitter { reuseAddr: this.reuseAddr, }) - this.interfaces.set( iface.address, iface ) + this.interfaces.set(iface.address, iface) }) }) } - _handleMessage( msg, rinfo, iface ) { + _handleMessage(msg, rinfo, iface) { var message = null - if( msg.indexOf( 'HTTP' ) === 0 ) { - message = SSDP.parseResponse( msg ) + if (msg.indexOf('HTTP') === 0) { + message = SSDP.parseResponse(msg) //console.log(message); - this.emit( 'message', message, rinfo, iface ) + this.emit('message', message, rinfo, iface) } else { - message = SSDP.parseRequest( msg ) - if( message.method === 'M-SEARCH' ) { - this.emit( 'search', message, rinfo, iface ) + message = SSDP.parseRequest(msg) + if (message.method === 'M-SEARCH') { + this.emit('search', message, rinfo, iface) // TODO/FIXME: Determine if the search came from ourselves - this._handleSearch( message, rinfo, iface ) - } else if( message.method === 'NOTIFY' ) { - this.emit( 'notify', message, rinfo, iface ) + this._handleSearch(message, rinfo, iface) + } else if (message.method === 'NOTIFY') { + this.emit('notify', message, rinfo, iface) } } } - _handleSearch( msg, rinfo, iface ) { + _handleSearch(msg, rinfo, iface) { - var services = /^ssdp:all$/i.test( msg.headers.st ) ? + var services = /^ssdp:all$/i.test(msg.headers.st) ? this.services.slice() : - this.services.filter(( service ) => { + this.services.filter((service) => { return service.type === msg.headers.st }) // Calculate a random timeout up to MX until transmitting response - var mx = parseInt( msg.headers.mx, 10 ) || SSDP.DEFAULT_MX + var mx = parseInt(msg.headers.mx, 10) || SSDP.DEFAULT_MX var delay = mx * Math.random() * 1000 setTimeout(() => { var date = new Date().toGMTString() - services.forEach(( service ) => { + services.forEach((service) => { this.respond({ 'date': date, 'cache-control': `max-age=${service.maxAge}`, @@ -99,40 +99,40 @@ class Discovery extends Emitter { 'location': iface.family === 'IPv6' ? service.location.ipv6 : service.location.ipv4, 'st': service.type, 'usn': service.usn, - }, rinfo, iface ) + }, rinfo, iface) }) - }, delay ) + }, delay) } - respond( options, rinfo, iface ) { + respond(options, rinfo, iface) { var message = `HTTP/1.1 200 OK\r\n` - Object.keys( options ).forEach(( field ) => { - message += `${ field.toUpperCase() }: ${ options[field] }\r\n` + Object.keys(options).forEach((field) => { + message += `${field.toUpperCase()}: ${options[field]}\r\n` }) message += '\r\n' - var buffer = Buffer.from( message ) + var buffer = Buffer.from(message) var length = buffer.length var offset = 0 - iface.socket.send( buffer, offset, length, rinfo.port, rinfo.address ) + iface.socket.send(buffer, offset, length, rinfo.port, rinfo.address) } - search( options, callback ) { + search(options, callback) { var headers = Object.assign({ 'host': '', 'man': '"ssdp:discover"', 'mx': '1', 'st': 'ssdp:all' - }, options ) + }, options) - for( var [ address, iface ] of this.interfaces ) { + for (var [address, iface] of this.interfaces) { let message = `M-SEARCH * HTTP/1.1\r\n` let host = iface.family === 'IPv6' ? SSDP.IPv6 : SSDP.IPv4 @@ -140,89 +140,89 @@ class Discovery extends Emitter { headers.host = iface.family === 'IPv6' ? `[${host}]:${SSDP.PORT}` : `${host}:${SSDP.PORT}` - for( var field in headers ) { + for (var field in headers) { message += field.toUpperCase() + ': ' + headers[field] + '\r\n' } message += '\r\n' - var buffer = Buffer.from( message ) + var buffer = Buffer.from(message) var length = buffer.length var offset = 0 - iface.socket.send( buffer, offset, length, SSDP.PORT, host ) + iface.socket.send(buffer, offset, length, SSDP.PORT, host) } - if( typeof callback === 'function' ) { + if (typeof callback === 'function') { setTimeout(() => { - callback.call( this, null, [] ) - }, 5000 ) + callback.call(this, null, []) + }, 5000) } } - announce( options, callback ) { - if( typeof callback === 'function' ) { + announce(options, callback) { + if (typeof callback === 'function') { process.nextTick(() => { - callback.call( this, new Error( 'Not implemented' ) ) + callback.call(this, new Error('Not implemented')) }) } } - publish( service, callback ) { - this.services.push( service ) - this.announce( service, callback ) + publish(service, callback) { + this.services.push(service) + this.announce(service, callback) } - listen( interfaces, callback ) { + listen(interfaces, callback) { - if( typeof interfaces === 'function' ) { + if (typeof interfaces === 'function') { callback = interfaces interfaces = null } - this._createSockets( interfaces ) + this._createSockets(interfaces) var interfaceCount = this.interfaces.size var socketsBound = 0 - this.interfaces.forEach(( iface, address ) => { + this.interfaces.forEach((iface, address) => { var socket = iface.socket - socket.on( 'error', ( error ) => { this.emit( 'warning', error, socket ) }) - socket.on( 'message', ( msg, rinfo ) => { this._handleMessage( msg, rinfo, iface ) }) - socket.on( 'listening', () => { this.emit( 'listening', socket ) }) + socket.on('error', (error) => { this.emit('warning', error, socket) }) + socket.on('message', (msg, rinfo) => { this._handleMessage(msg, rinfo, iface) }) + socket.on('listening', () => { this.emit('listening', socket) }) var address = iface.family === 'IPv6' ? SSDP.IPv6 : SSDP.IPv4 - socket.bind( SSDP.PORT, () => { + socket.bind(SSDP.PORT, () => { var addr = socket.address() try { - socket.setMulticastTTL( SSDP.MULTICAST_TTL ) - socket.setMulticastLoopback( true ) - socket.setBroadcast( true ) - if( iface.family === 'IPv6' ) { - socket.addMembership( SSDP.IPv6, iface.address ) + socket.setMulticastTTL(SSDP.MULTICAST_TTL) + socket.setMulticastLoopback(true) + socket.setBroadcast(true) + if (iface.family === 'IPv6') { + socket.addMembership(SSDP.IPv6, iface.address) } else { - socket.addMembership( SSDP.IPv4, iface.address ) + socket.addMembership(SSDP.IPv4, iface.address) } - } catch( error ) { - this.emit( 'warning', error, iface ) - this.interfaces.delete( iface.address ) + } catch (error) { + this.emit('warning', error, iface) + this.interfaces.delete(iface.address) iface.socket.removeAllListeners() iface.socket.close() iface.socket = null } - if( ( socketsBound += 1 ) === interfaceCount ) { + if ((socketsBound += 1) === interfaceCount) { var error = !this.interfaces.size ? - new Error( 'No interfaces bound' ) : null - callback.call( this, error ) + new Error('No interfaces bound') : null + callback.call(this, error) } }) @@ -232,8 +232,8 @@ class Discovery extends Emitter { } close() { - this.interfaces.forEach(( iface, address ) => { - if( iface.socket ) { + this.interfaces.forEach((iface, address) => { + if (iface.socket) { iface.socket.close(() => { iface.socket.removeAllListeners() iface.socket = null @@ -245,7 +245,7 @@ class Discovery extends Emitter { } class Interface { - constructor( name, options ) { + constructor(name, options) { this.name = name || '' this.address = options.address || '' this.netmask = options.netmask || '' diff --git a/lib/ssdp.js b/lib/ssdp.js index 4e97872..702bfd3 100644 --- a/lib/ssdp.js +++ b/lib/ssdp.js @@ -36,10 +36,10 @@ SSDP.METHODS = [ 'M-SEARCH', ] -SSDP.Discovery = require( './discovery' ) +SSDP.Discovery = require('./discovery') SSDP.Service = class Service { - constructor( options ) { + constructor(options) { options = options || {} @@ -51,16 +51,16 @@ SSDP.Service = class Service { ipv6: options.ipv6 || '', } - this.maxAge = parseInt( options.maxAge, 10 ) || 1800 + this.maxAge = parseInt(options.maxAge, 10) || 1800 } } -SSDP.parseResponse = function( buffer ) { +SSDP.parseResponse = function (buffer) { - var eod = buffer.indexOf( '\r\n\r\n' ) - var header = buffer.toString( 'utf8', 0, eod ) - .split( /\r\n/g ) + var eod = buffer.indexOf('\r\n\r\n') + var header = buffer.toString('utf8', 0, eod) + .split(/\r\n/g) var status = header.shift() @@ -69,20 +69,20 @@ SSDP.parseResponse = function( buffer ) { version: '', statusCode: '', statusMessage: '', - headers: Object.create( null ) + headers: Object.create(null) } - eod = status.indexOf( '/' ) + eod = status.indexOf('/') - message.protocol = status.slice( 0, eod ).toLowerCase() - message.version = status.slice( eod + 1, eod = status.indexOf( ' ', eod + 1 ) ) - message.statusCode = parseInt( status.slice( eod + 1, eod = status.indexOf( ' ', eod + 1 ) ), 10 ) - message.statusMessage = status.slice( eod + 1 ) + message.protocol = status.slice(0, eod).toLowerCase() + message.version = status.slice(eod + 1, eod = status.indexOf(' ', eod + 1)) + message.statusCode = parseInt(status.slice(eod + 1, eod = status.indexOf(' ', eod + 1)), 10) + message.statusMessage = status.slice(eod + 1) - for( var i = 0; i < header.length; i++ ) { - eod = header[i].indexOf( ':' ) - let k = header[i].slice( 0, eod ).toLowerCase() - let v = header[i].slice( eod + 1 ).trim() + for (var i = 0; i < header.length; i++) { + eod = header[i].indexOf(':') + let k = header[i].slice(0, eod).toLowerCase() + let v = header[i].slice(eod + 1).trim() message.headers[k] = message.headers[k] != null ? message.headers[k] + ', ' + v : v } @@ -91,27 +91,27 @@ SSDP.parseResponse = function( buffer ) { } -SSDP.parseRequest = function( buffer ) { +SSDP.parseRequest = function (buffer) { - var eod = buffer.indexOf( '\r\n\r\n' ) - var header = buffer.toString( 'utf8', 0, eod ) - .split( /\r\n/g ) + var eod = buffer.indexOf('\r\n\r\n') + var header = buffer.toString('utf8', 0, eod) + .split(/\r\n/g) - var [ method, path, protocol ] = header.length ? - header.shift().split( /\s/g ) : [] + var [method, path, protocol] = header.length ? + header.shift().split(/\s/g) : [] var message = { - protocol: protocol ? protocol.split( '/' ).shift().toLowerCase() : '', - version: protocol ? protocol.split( '/' ).pop() : '', + protocol: protocol ? protocol.split('/').shift().toLowerCase() : '', + version: protocol ? protocol.split('/').pop() : '', method, path, - headers: Object.create( null ), + headers: Object.create(null), } - for( var i = 0; i < header.length; i++ ) { - eod = header[i].indexOf( ':' ) - let k = header[i].slice( 0, eod ).toLowerCase() - let v = header[i].slice( eod + 1 ).trim() + for (var i = 0; i < header.length; i++) { + eod = header[i].indexOf(':') + let k = header[i].slice(0, eod).toLowerCase() + let v = header[i].slice(eod + 1).trim() message.headers[k] = message.headers[k] != null ? message.headers[k] + ', ' + v : v } diff --git a/main.js b/main.js index 81a667b..ef8706a 100755 --- a/main.js +++ b/main.js @@ -100,8 +100,7 @@ class deconz extends utils.Adapter { switch (dp) { case "bri": - if (state.val > 0 && (transitionTime === "none" || transitionTime === 0)) - { + if (state.val > 0 && (transitionTime === "none" || transitionTime === 0)) { parameters = '{"bri": ' + JSON.stringify(state.val) + ', "on": true}'; } else if (state.val > 0) { parameters = '{"transitiontime": ' + JSON.stringify(transitionTime) + ', "bri": ' + JSON.stringify(state.val) + ', "on": true}'; @@ -117,8 +116,7 @@ class deconz extends utils.Adapter { ); break; case "level": - if (state.val > 0 && (transitionTime === "none" || transitionTime === 0)) - { + if (state.val > 0 && (transitionTime === "none" || transitionTime === 0)) { parameters = '{"bri": ' + Math.floor((255 / 100) * state.val) + ', "on": true}'; } else if (state.val > 0) { parameters = '{"transitiontime": ' + JSON.stringify(transitionTime) + ', "bri": ' + Math.floor((255 / 100) * state.val) + ', "on": true}'; @@ -214,11 +212,11 @@ class deconz extends utils.Adapter { effectspeed = 1; } parameters = `{"effect": ${JSON.stringify(state.val)}, "effectSpeed": ${JSON.stringify(effectspeed)}, "effectColours": ${JSON.stringify(effectcolours ? effectcolours.val - : [ - [255, 0, 0], - [0, 255, 0], - [0, 0, 255], - ] + : [ + [255, 0, 0], + [0, 255, 0], + [0, 0, 255], + ] )}}`; } else { parameters = '{"effect": ' + JSON.stringify(state.val) + "}"; @@ -231,8 +229,7 @@ class deconz extends utils.Adapter { this.name + "." + this.instance + "." + id + ".dimspeed" ); - if (dimspeed === null || dimspeed === undefined || dimspeed.val === 0) - { + if (dimspeed === null || dimspeed === undefined || dimspeed.val === 0) { dimspeed = 10; this.setState(this.name + "." + this.instance + "." + id + ".dimspeed", 10, true); } @@ -244,8 +241,7 @@ class deconz extends utils.Adapter { } break; case "action": - if (state.val === null || state.val === undefined || state.val === 0) - { + if (state.val === null || state.val === undefined || state.val === 0) { return; } parameters = `{ ${state.val} }`; @@ -280,7 +276,7 @@ class deconz extends utils.Adapter { }, }); break; - //set boolean&number + //set boolean&number case "boost": case "charging": case "delay": @@ -313,7 +309,7 @@ class deconz extends utils.Adapter { case "windowopen_set": parameters = `{ "${dp}": ${state.val} }`; break; - //set string + //set string case "colormode": case "clickmode": case "devicemode": @@ -324,7 +320,7 @@ class deconz extends utils.Adapter { case "triggerdistance": parameters = `{ "${dp}": "${state.val}" }`; break; - //set temperature + //set temperature case "heatsetpoint": case "coolsetpoint": case "externalsensortemp": @@ -360,8 +356,8 @@ class deconz extends utils.Adapter { controlId, this.name + "." + this.instance + "." + id + "." + dp ); - if ('stop' === dp){ - await getLightState( id.split('.').pop() ); + if ('stop' === dp) { + await getLightState(id.split('.').pop()); } break; case "group": @@ -409,7 +405,7 @@ class deconz extends utils.Adapter { this.sendTo( obj.from, obj.command, - { native: { user: JSON.stringify(res.message).replace(/"/g, '') } }, + { native: { user: JSON.stringify(res.message).replace(/"/g, '') } }, obj.callback ); }); @@ -418,10 +414,10 @@ class deconz extends utils.Adapter { case "deleteAPIkey": await deleteAPIkey(); this.sendTo( - obj.from, - obj.command, - { native: { user: "" } }, - obj.callback + obj.from, + obj.command, + { native: { user: "" } }, + obj.callback ); wait = true; break; @@ -509,17 +505,17 @@ async function main() { heartbeat(); - if (adapter.config.ip === "undefined") { - //only on first start - autoDiscovery(); + if (adapter.config.ip === "undefined") { + //only on first start + autoDiscovery(); + } else { + if (adapter.config.user === "" || adapter.config.user === null) { + adapter.log.warn("No API Key found"); } else { - if (adapter.config.user === "" || adapter.config.user === null) { - adapter.log.warn("No API Key found"); - } else { - await getConfig(); - await getAutoUpdates(); - } + await getConfig(); + await getAutoUpdates(); } + } } //search for Gateway @@ -532,7 +528,7 @@ function autoDiscovery() { discovery.on("message", (msg, rinfo, iface) => { if (msg.headers.st === "urn:schemas-upnp-org:device:basic:1") { - adapter.log.debug( `M-SEARCH from ${rinfo.address} for "${msg.headers.st}"` ); + adapter.log.debug(`M-SEARCH from ${rinfo.address} for "${msg.headers.st}"`); if (msg.headers["gwid.phoscon.de"] !== undefined) { let loc = msg.headers.location.replace("/description.xml", ""); loc = loc.replace("http://", ""); @@ -647,7 +643,7 @@ async function deleteAPIkey() { let response; try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } if (res !== undefined) { if (await logging(res, body, "delete API key")) { if (response[0]["success"]) { @@ -685,7 +681,7 @@ function autoReconnect(host, port) { async function getAutoUpdates() { const host = adapter.config.bridge ? adapter.config.bridge : null; - const port = adapter.config.port ? adapter.config.websocketport : 443; + const port = adapter.config.websocketport ? adapter.config.websocketport : 443; const user = adapter.config.user ? adapter.config.user : null; if (user !== null && host !== null && port !== null) { @@ -866,7 +862,7 @@ async function getAutoUpdates() { async function modifyConfig(parameters) { let ip = adapter.config.bridge; const port = adapter.config.port; - const user = adapter.config.user + const user = adapter.config.user; let ot; const results = await adapter.getObjectAsync("Gateway_info"); @@ -888,10 +884,9 @@ async function modifyConfig(parameters) { if (error) adapter.log.warn(error); try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } - if ((await logging(res, body, "modify config")) && response !== undefined && response !== "undefined") - { + if ((await logging(res, body, "modify config")) && response !== undefined && response !== "undefined") { if (response[0]["success"]) { switch (JSON.stringify(response[0]["success"])) { case `{"/config/permitjoin":${ot}}`: @@ -1200,7 +1195,6 @@ function getGroupScenes(group, sceneList) { id: scene.id, }, }); - adapter.setObjectNotExists(`${group}.Scene_${scene.id}.recall`, { type: "state", common: { @@ -1251,7 +1245,6 @@ function getGroupScenes(group, sceneList) { ); } ); - adapter.setObjectNotExists( `${group}.Scene_${scene.id}.transitiontime`, { @@ -1317,10 +1310,9 @@ async function setGroupState(parameters, groupId, stateId) { let response; try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } - if ((await logging(res, body, "set group state " + groupId)) && response !== undefined && response !== "undefined") - { + if ((await logging(res, body, "set group state " + groupId)) && response !== undefined && response !== "undefined") { new ackStateVal(stateId, response); } } @@ -1362,10 +1354,9 @@ async function setGroupScene( let response; try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } - if ((await logging(res, body, "set group scene " + groupId)) && response !== undefined && response !== "undefined") - { + if ((await logging(res, body, "set group scene " + groupId)) && response !== undefined && response !== "undefined") { new ackStateVal(stateId, response); } } @@ -1418,10 +1409,9 @@ async function deleteGroup(groupId) { let response; try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } - if ((await logging(res, body, "delete group " + groupId)) && response !== undefined && response !== "undefined") - { + if ((await logging(res, body, "delete group " + groupId)) && response !== undefined && response !== "undefined") { if (response[0]["success"]) { adapter.log.info("The group with id " + groupId + " was removed."); adapter.getForeignObjects( @@ -1571,8 +1561,7 @@ async function getSensor(sensorId) { for (let z = 0; z <= count2; z++) { let stateName = Object.keys(list["state"])[z]; - if (stateName === "buttonevent" && list["modelid"] === "lumi.Sensors.switch.aq2") - { + if (stateName === "buttonevent" && list["modelid"] === "lumi.Sensors.switch.aq2") { let LastUpdate = Number(new Date(list["state"]["lastupdated"])); let Now = Number(new Date().getTime()); let dateOff = new Date(); @@ -1636,10 +1625,9 @@ async function setSensorParameters(parameters, sensorId, stateId, callback) { let response; try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } - if ((await logging(res, body, "set sensor parameters")) && response !== undefined && response !== "undefined") - { + if ((await logging(res, body, "set sensor parameters")) && response !== undefined && response !== "undefined") { new ackStateVal(stateId, response); } @@ -1667,10 +1655,9 @@ async function deleteSensor(sensorId) { let response; try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } - if ((await logging(res, body, "delete sensor " + sensorId)) && response !== undefined && response !== "undefined") - { + if ((await logging(res, body, "delete sensor " + sensorId)) && response !== undefined && response !== "undefined") { if (response[0]["success"]) { adapter.log.info("The sensor with id " + sensorId + " was removed."); adapter.getForeignObjects( @@ -1682,8 +1669,7 @@ async function deleteSensor(sensorId) { for (let i = 0; i <= count; i++) { //jedes durchgehen und prüfen ob es sich um ein Objekt vom Typ sensor handelt let keyName = Object.keys(enums)[i]; - if (enums[keyName].common.role === "sensor" && enums[keyName].native.id === sensorId) - { + if (enums[keyName].common.role === "sensor" && enums[keyName].native.id === sensorId) { adapter.log.info("delete device Object: " + enums[keyName]._id); let name = enums[keyName]._id; @@ -1727,7 +1713,7 @@ async function getAllLights() { //mac = mac.match(/..:..:..:..:..:..:..:../g).toString(); //let lightID = mac.replace(/:/g, ''); - switch (list[keyName]['type']){ + switch (list[keyName]['type']) { case 'Window covering device': // is this a window covering unit? case 'Window covering controller': // is this a window covering unit? adapter.setObjectNotExists(`Lights.${lightID}`, { @@ -1778,32 +1764,32 @@ async function getAllLights() { } } //END getAllLights -async function createLightDevice(list, keyName, lightID){ +async function createLightDevice(list, keyName, lightID) { if (list[keyName]["state"]) { let count2 = Object.keys(list[keyName]["state"]).length - 1; //create states for light device for (let z = 0; z <= count2; z++) { let stateName = Object.keys(list[keyName]["state"])[z]; await SetObjectAndState( - lightID, - list[keyName]["name"], - "Lights", - stateName, - list[keyName]["state"][stateName] + lightID, + list[keyName]["name"], + "Lights", + stateName, + list[keyName]["state"][stateName] ); await SetObjectAndState( - lightID, - list[keyName]["name"], - "Lights", - "transitiontime", - null + lightID, + list[keyName]["name"], + "Lights", + "transitiontime", + null ); await SetObjectAndState( - lightID, - list[keyName]["name"], - "Lights", - "level", - null + lightID, + list[keyName]["name"], + "Lights", + "level", + null ); adapter.setObjectNotExists(`Lights.${lightID}.dimspeed`, { type: "state", @@ -1852,25 +1838,25 @@ async function createLightDevice(list, keyName, lightID){ } } -async function createBlindsDevice(list, keyName, lightID){ +async function createBlindsDevice(list, keyName, lightID) { if (list[keyName]["state"]) { let count2 = Object.keys(list[keyName]["state"]).length - 1; //create states for light device for (let z = 0; z <= count2; z++) { let stateName = Object.keys(list[keyName]["state"])[z]; await SetObjectAndState( - lightID, - list[keyName]["name"], - "Lights", - stateName, - list[keyName]["state"][stateName] + lightID, + list[keyName]["name"], + "Lights", + stateName, + list[keyName]["state"][stateName] ); await SetObjectAndState( - lightID, - list[keyName]["name"], - "Lights", - "transitiontime", - null + lightID, + list[keyName]["name"], + "Lights", + "transitiontime", + null ); adapter.setObjectNotExists(`Lights.${lightID}.stop`, { type: "state", @@ -1880,7 +1866,7 @@ async function createBlindsDevice(list, keyName, lightID){ role: "button", read: false, write: true, - default:false + default: false }, native: {}, }); @@ -1918,7 +1904,7 @@ async function getLightState(lightId) { let list = JSON.parse(body); let keyName = Object.keys(list)[0]; //create object for light device - switch(list['type']){ + switch (list['type']) { case 'Window covering device': // is this a window covering unit? case 'Window covering controller': // is this a window covering unit? adapter.extendObject(`Lights.${lightId}`, { @@ -1995,14 +1981,13 @@ async function setLightState(parameters, lightId, stateId, callback) { let response; try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } - if ((await logging(res, body, "set light state " + lightId)) && response !== undefined && response !== "undefined") - { + if ((await logging(res, body, "set light state " + lightId)) && response !== undefined && response !== "undefined") { let oldParameters; try { oldParameters = JSON.parse(parameters); - } catch (err) {} + } catch (err) { } if (oldParameters) { let retryParameters = {}; response.forEach((message) => { @@ -2054,7 +2039,7 @@ async function deleteLight(lightId) { let response; try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } if ( (await logging(res, body, "delete light " + lightId)) && @@ -2072,8 +2057,7 @@ async function deleteLight(lightId) { for (let i = 0; i <= count; i++) { //jedes durchgehen und prüfen ob es sich um ein Objekt vom Typ sensor handelt let keyName = Object.keys(enums)[i]; - if (enums[keyName].common.role === "light" && enums[keyName].native.id === lightId) - { + if (enums[keyName].common.role === "light" && enums[keyName].native.id === lightId) { adapter.log.info("delete device Object: " + enums[keyName]._id); let name = enums[keyName]._id; @@ -2108,10 +2092,9 @@ async function removeFromGroups(lightId) { let response; try { response = JSON.parse(body); - } catch (err) {} + } catch (err) { } - if ((await logging(res, body, "remove light from groups " + lightId)) && response !== undefined && response !== "undefined") - { + if ((await logging(res, body, "remove light from groups " + lightId)) && response !== undefined && response !== "undefined") { if (response[0]["success"]) { adapter.log.info("The light with id " + lightId + " was removed from all groups."); } else if (response[0]["error"]) { @@ -2241,7 +2224,7 @@ function nameFilter(name) { * @param {number} deviceID * @param {string} type - first letter has to be upper case. Possible: Lights, Sensors */ -async function getDeviceByID(deviceID, type) {} +async function getDeviceByID(deviceID, type) { } /** * Retrieves gateway parameters including IP address, port, and user. @@ -2255,11 +2238,11 @@ async function getDeviceByID(deviceID, type) {} * - user: {string} The user of the gateway. */ async function getGatewayParam() { - return { - ip: adapter.config.bridge ? adapter.config.bridge : "none", - port: adapter.config.port ? adapter.config.port : "none", - user: adapter.config.user ? adapter.config.user : "none", - }; + return { + ip: adapter.config.bridge ? adapter.config.bridge : "none", + port: adapter.config.port ? adapter.config.port : "none", + user: adapter.config.user ? adapter.config.user : "none", + }; } async function deleteDevice(deviceId) { @@ -2301,8 +2284,7 @@ function ackStateVal(stateId, response) { * @return {string} */ function UTCtoLocal(timeString) { - if (timeString !== "none" && timeString !== null && timeString !== undefined) - { + if (timeString !== "none" && timeString !== null && timeString !== undefined) { let jsT = Date.parse(timeString + "Z"); let d = new Date(); @@ -2810,7 +2792,7 @@ async function SetObjectAndState(id, name, type, stateName, value) { case "lat": objType = "number"; objRole = "value.gps.latitude"; - objRead= false; + objRead = false; break; case "ledindication": objType = "boolean"; @@ -2847,7 +2829,7 @@ async function SetObjectAndState(id, name, type, stateName, value) { case "long": objType = "number"; objRole = "value.gps.longitude"; - objRead= false; + objRead = false; break; case "lift": objType = "number";