iobroker.wifilight
Advanced tools
Comparing version 0.1.10 to 0.2.0
{ | ||
"common": { | ||
"name": "wifilight", | ||
"version": "0.1.10", | ||
"version": "0.2.0", | ||
"news": { | ||
"0.2.0": { | ||
"en": "device config handling changed", | ||
"de": "Handhabung der Gerätekonfiguration geändert" | ||
}, | ||
"0.1.10": { | ||
@@ -7,0 +12,0 @@ "en": "AK001-ZJ200 added (matze1708)", |
{ | ||
"name": "iobroker.wifilight", | ||
"version": "0.1.10", | ||
"version": "0.2.0", | ||
"description": "WiFi Light Adapter", | ||
@@ -51,2 +51,3 @@ "author": { | ||
} | ||
} | ||
} | ||
100
wifilight.js
@@ -28,2 +28,6 @@ "use strict"; | ||
function fromDeviceName(name) { | ||
return cmds.knownDeviceNames[name] || cmds.knownDeviceNames[name.toUpperCase()]; | ||
} | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
@@ -38,6 +42,6 @@ | ||
var ret = !adapter.config.devices.some(function(e,i) { | ||
return e.ip == entry.ip; | ||
return e.ip === entry.ip; | ||
}); | ||
if (ret) { | ||
var dev = cmds.knownDeviceNames[entry.name]; | ||
var dev = fromDeviceName(entry.name); | ||
entry.type = dev ? dev.type : ''; | ||
@@ -153,3 +157,2 @@ entry.port = dev && dev.port ? dev.port : 5577; | ||
if (!config) return this; | ||
//this.USE_SOCKET_ONCE = false; //true; | ||
this.config = config; | ||
@@ -167,3 +170,3 @@ this.isOnline = false; | ||
} | ||
if (this.cmds.vmax == undefined) this.cmds.vmax = 255; | ||
if (this.cmds.vmax === undefined) this.cmds.vmax = 255; | ||
this.cmds.g = this.cmds.g || 1; | ||
@@ -173,3 +176,3 @@ | ||
this.setOnline(false); | ||
if (this.cmds.onlyConnectOnWrite) { | ||
@@ -182,5 +185,3 @@ this.USE_SOCKET_ONCE = true; | ||
this.dataBuffer = new Uint8Array(200); | ||
//this.dataBuffer = new Buffer(200); | ||
this.dataBuffer.pos = 0; | ||
//this.states = { red: this.getval('r',0), green: this.getval('g', 0), blue: this.getval('b',0) }; | ||
this.states = { red: 0, green: 0, blue: 0 }; | ||
@@ -281,4 +282,2 @@ this.start(cb); | ||
case usedStateNames.command.n: | ||
// var v = val.replace(/(^on$|red|green|blue|transition|bri|off)/g, function(match, p) { return { '#': '#', off:'off:1', on:'on:1', red:'r', green:'g', blue:'b', white: 'w', transition:'x', bri:'l'/*, off:'on:0'*/} [match] }); | ||
// v = v.replace(/\s|\"|;$|,$/g, '').replace(/=/g, ':').replace(/;/g, ',').replace(/true/g, 1).replace(/((on|off),{1})/g, '$2:1,').replace(/#((\d|[a-f]|[A-F]|[.])*)/g, 'h:"$1"').replace(/(r|g|b|w|x|l|sat|off|on|ct|h)/g, '"$1"').replace(/^\{?(.*?)\}?$/, '{$1}'); | ||
var v = val.replace(/(^on$|red|green|blue|transition|bri|off)/g, function(match, p) { return { '#': '#', off:'off:1', on:'on:1', red:'r', green:'g', blue:'b', white: 'w', transition:'x', bri:'l'/*, off:'on:0'*/} [match] }); | ||
@@ -340,3 +339,3 @@ v = v.replace(/\s|\"|;$|,$/g, '').replace(/=/g, ':').replace(/;/g, ',').replace(/true/g, 1).replace(/((on|off),{1})/g, '$2:1,').replace(/#((\d|[a-f]|[A-F]|[.])*)/g, 'h:"$1"').replace(/(r|g|b|w|x|l|sat|off|on|ct|h|p)/g, '"$1"').replace(/^\{?(.*?)\}?$/, '{$1}'); | ||
self.clearQueue(); | ||
function doIt() { | ||
@@ -383,6 +382,4 @@ if (self.queue.length > 0) { | ||
WifiLight.prototype.start = function (cb) { | ||
if (this.USE_SOCKET_ONCE) { | ||
//wifi[this.dev.getFullId()] = this; | ||
//this._write = this.cmds.udp ? this.writeUdp : this.writeOnce; | ||
if (this.__proto__._write === WifiLight.prototype._write) { | ||
@@ -421,3 +418,2 @@ WifiLight.prototype._write = this.writeOnce; | ||
self.client.connect(self.config.port, self.config.ip, function() { | ||
//wifi[self.dev.getFullId()] = self; | ||
self.log(self.config.ip + ' connected'); | ||
@@ -449,5 +445,2 @@ self.setOnline(true); | ||
this.client = new net.Socket(); | ||
// this.client.setTimeout(5000, function () { | ||
// //this.log('self.client.setTimeout for ' + self.config.ip); | ||
// }); | ||
@@ -511,5 +504,3 @@ var self = this; | ||
this.dev.set(usedStateNames.online.n, val); | ||
//this.dev.update(); | ||
devices.update(); | ||
//this.isOnline = val; | ||
}; | ||
@@ -572,3 +563,2 @@ | ||
for (var i = 0, j=idx+1; i < varArgs[idx].length; i++) { | ||
//cmd[i] = varArgs[idx][i] < 0 && varArgs[idx][i] !== cmds.VARS.separator ? varArgs[j++] : varArgs[idx][i]; | ||
cmd[i] = varArgs[idx][i] < 0 && varArgs[idx][i] !== cmds.VARS.separator && varArgs[idx][i] !== cmds.VARS.sepNoDelay ? varArgs[j++] : varArgs[idx][i]; | ||
@@ -583,3 +573,3 @@ } | ||
} | ||
var _cmd = []; | ||
@@ -607,13 +597,3 @@ var last = cmd.length - 1; | ||
}.bind(this)); | ||
// this.queue.push ({ | ||
// cmd: cmd, | ||
// ctrl: opt && opt.ctrl ? true : false, | ||
// channel: channel, | ||
// delay: opt && opt.delay ? opt.delay : this.cmds.delay != undefined ? this.cmds.delay : 10, | ||
// ts: 0, | ||
// inProcess: 0, | ||
// unlock: 0 | ||
// }); | ||
if (this.queue.length && this.queue[0].inProcess === 1) { | ||
//this.log('addToQueue: return without calling exec'); | ||
return; | ||
@@ -625,7 +605,5 @@ } | ||
WifiLight.prototype.exec = function () { | ||
//this.log('exec: queue.length=' + this.queue.length + (this.queue.length ? ' inProcess=' + this.queue[0].inProcess : "")); | ||
var akt; | ||
while(true) { | ||
if (this.queue.length <= 0) { | ||
//this.log('exec: returning queue.length=0'); | ||
return; | ||
@@ -637,3 +615,2 @@ } | ||
} | ||
//this.log('exec: removing queue entry ' + akt.cmd.hex()); | ||
if (this.queue.length <= 1 && !akt.cmd.eq (this.cmds.statusRequest)) { | ||
@@ -648,5 +625,3 @@ this.directRefresh(akt.channel); | ||
} | ||
//this.log('exec: write: ' + akt.cmd.hex()); | ||
this.write (akt.channel, akt.cmd, function() { | ||
//this.log('exec: setTimeout: ' + akt.delay); | ||
this.writeTimeout = setTimeout(this.exec.bind(this), akt.delay); | ||
@@ -660,3 +635,2 @@ }.bind(this)); | ||
this.addToQueue(channel, state ? this.cmds.on : this.cmds.off); | ||
//if (!state && this.cmds.udp) this.addToQueue(channel, [0x4E,0x19,0x55]); | ||
}; | ||
@@ -673,5 +647,5 @@ | ||
var maxSteps = Math.max(Math.abs(dif.r), Math.abs(dif.g), Math.abs(dif.b), Math.abs(dif.w), 1); | ||
maxSteps = Math.min ((transitionTime*100) / this.cmds.delay, maxSteps); | ||
dif.r /= maxSteps; | ||
@@ -727,3 +701,2 @@ dif.g /= maxSteps; | ||
}; | ||
//WifiLight.prototype.brightness = WifiLight.prototype.bri; | ||
@@ -748,3 +721,3 @@ WifiLight.prototype.onTime = function (channel, val) { | ||
WifiLight.prototype.onData = function (data) { | ||
if (adapter.common.loglevel == 'debug') { | ||
@@ -761,3 +734,2 @@ adapter.log.debug('raw data length: ' + data.length); | ||
} | ||
//this.dataBuffer.copy(b, 0, 0, this.dataBuffer.pos); | ||
b.pos = this.dataBuffer.pos; | ||
@@ -802,11 +774,5 @@ this.dataBuffer = b; | ||
var MiLight = function MiLight (config, zone, cb) { | ||
// MiLight.prototype._zone = function() { | ||
// return zone; | ||
// }; | ||
WifiLight.call(this, config); | ||
if (!this.cmds) return; | ||
//extend(this, WifiLight.call(this, config)); | ||
this.zone = zone; | ||
//this.cmds = Object.assign({}, tmp, {v:1}); | ||
//this.cmds = fullExtend({}, this.cmds); | ||
this.cmds = clone(this.cmds); | ||
@@ -823,9 +789,7 @@ this.cmds.setZone(this.zone); | ||
MiLight.prototype._write = function writeUdp (data, cb) { | ||
var self = this; | ||
//??this.writeTimer.clear(); | ||
if (!this.client) { | ||
var dgram = require('dgram'); | ||
self.client = dgram.createSocket('udp4'); | ||
//self.client = dgram.createSocket({ type: 'udp4', reuseAddr: true }); | ||
self.client.on("listening", function (error) { | ||
@@ -846,3 +810,3 @@ if (error) return cb && cb(error); | ||
} | ||
self.client.send(data, 0, data.length, self.config.port, self.config.ip, function(error, bytes) { | ||
@@ -925,3 +889,3 @@ self.writeTimer.set(function() { | ||
dcs.del(id, next); | ||
}, | ||
}, | ||
cb); | ||
@@ -934,20 +898,25 @@ }); | ||
function normalizeConfig (config) { | ||
var changed = false; | ||
var types = []; | ||
config.devices.forEach(function (d, i) { | ||
var dev, old = Object.assign({}, d); | ||
if (!(dev = cmds.knownDeviceNames[d.name])) { | ||
var err = "config.device " + d.name + ' is not a known device. Skipping this device!'; | ||
err += '\nKnown names are: ' + Object.keys(cmds.knownDeviceNames).join(', '); | ||
var c, old = Object.assign({}, d); | ||
var dev = fromDeviceName(d.name); | ||
if (d.type === undefined) d.type = dev ? dev.type : ''; | ||
if (!(c = cmds[d.type])) { | ||
var 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 (typeof cmds[n] === 'object' && cmds[n].on) types.push(n); | ||
}); | ||
err += '\nKnown types are: ' + types.join(', '); | ||
adapter.log.error(err); | ||
return; | ||
} | ||
if (d.pollIntervall === undefined) d.pollIntervall = 30; | ||
d.pollIntervall = parseInt(d.pollIntervall) | 0; | ||
if (d.pollIntervall && d.pollIntervall < 5) d.pollIntervall = 5; | ||
d.port = parseInt(d.port) || 5577; | ||
if (d.type === undefined) d.type = dev ? dev.type : ''; | ||
if (d.port === undefined) d.port = dev && dev.port ? dev.port : 5577; | ||
if (d.pollIntervall === undefined) d.pollIntervall = 30; | ||
d.port = parseInt(d.port) || (c && c.port ? c.port : dev && dev.port ? dev.port : 5577); | ||
Object.keys(d).forEach(function(key) { | ||
@@ -965,7 +934,4 @@ changed = changed || d[key] !== old[key]; | ||
function main() { | ||
//onMessage({command: 'discovery'}); | ||
//return; | ||
if (!adapter.config.devices) return; | ||
checkDeletedDevices(function(err) { | ||
// \/ | ||
}); | ||
@@ -972,0 +938,0 @@ normalizeConfig(adapter.config); |
76757
1405