Socket
Socket
Sign inDemoInstall

iobroker.wifilight

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iobroker.wifilight - npm Package Compare versions

Comparing version 0.0.10 to 0.0.14

14

devices.js

@@ -58,4 +58,3 @@ "use strict";

decodeResponse: function(data) {
if (data[0] == 0x66 && data[1] == 0x01) {
}
if (data[0] != 0x66 || data[1] != 0x01) return null;
var result = {

@@ -65,3 +64,3 @@ power: ((data[2] === 0x23) ? true : false),

progOn: data[4] === 33, //modeRun
speed: data[5], //modeSpeed
rogSpeed: data[5], //modeSpeed
red: data[6],

@@ -80,2 +79,3 @@ green: data[7],

port: 5577,
//onlyConnectOnWrite: true,

@@ -95,3 +95,3 @@ delay: 10,

decodeResponse: function(data) {
if (data.length < 14 || data[0] !== 129) return null;
if (data[0] !== 129) return null;
//[129, 4, 35, 97, 33, 9, 11, 22, 33, 255, 3, 0, 0, 119]

@@ -104,3 +104,3 @@ return {

progOn: data[4] === 33, //modeRun
speed: data[5], //modeSpeed
preogSpeed: data[5], //modeSpeed
red: data[6],

@@ -130,3 +130,3 @@ green: data[7],

decodeResponse: function(data) {
if (data.length < 14 || data[0] !== 129) return null;
if (data[0] !== 129) return null;
//[129, 4, 35, 97, 33, 9, 11, 22, 33, 255, 3, 0, 0, 119]

@@ -139,3 +139,3 @@ return {

progOn: data[4] === 33, //modeRun
speed: data[5], //modeSpeed
progSpeed: data[5], //modeSpeed
red: data[6],

@@ -142,0 +142,0 @@ green: data[7],

{
"common": {
"name": "wifilight",
"version": "0.0.10",
"version": "0.0.14",
"title": "WiFi Light",

@@ -11,2 +11,8 @@ "desc": {

},
"keywords": [
"ioBroker",
"wifilight",
"lw12",
"ld382"
],
"platform": "Javascript/Node.js",

@@ -13,0 +19,0 @@ "mode": "daemon",

@@ -738,3 +738,3 @@ /**

}
that.setraw(id, { val: states[fullId].val });
that.setraw(id, { val: states[fullId] ? states[fullId].val : null});
}

@@ -741,0 +741,0 @@

{
"name": "iobroker.wifilight",
"version": "0.0.10",
"version": "0.0.14",
"description": "WiFi Light Adapter",

@@ -5,0 +5,0 @@ "author": {

@@ -7,3 +7,3 @@ ![Logo](admin/wifilight.png)

#### Info
First only LW12 supported
First only LW12, LD382 and LD382A supported

@@ -30,2 +30,5 @@ ###### How to use the command state:

###### r, g, b, w States:
+ Values 0..255
+ \#rrggbb[ww]

@@ -32,0 +35,0 @@ #### Installation

@@ -13,3 +13,25 @@ "use strict";

var wifi = {};
var debug = false;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function hex(ar, len) {
var s = "";
if (len == undefined) len = ar.length;
for (var i=0; i<len; i++) {
s += ('0' + ar[i].toString(16)).substr(-2) + ' ';
}
return s;
}
Array.prototype.hex = function () {
return hex(this);
};
Array.prototype.eq = function (arr) {
return this.length==arr.length && this.every(function(v,i) { return v === arr[i]});
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var adapter = utils.adapter({

@@ -43,6 +65,17 @@ name: 'wifilight',

ready: function () {
//adapter.log.debug = console.log;
devices.init(adapter, function(err) {
main();
adapter.getForeignObject('system.adapter.' + adapter.namespace, function(err, obj) {
if (!err && obj && obj.common && obj.common.enabled === false) {
// running in debuger
adapter.log.debug = console.log;
adapter.log.info = console.log;
adapter.log.warn = console.log;
debug = true;
}
devices.init(adapter, function(err) {
main();
});
});
//devices.init(adapter, function(err) {
// main();
//});
}

@@ -82,3 +115,3 @@ });

return true;
};
}

@@ -89,3 +122,2 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var usedStateNames = {

@@ -102,3 +134,3 @@ online: { n: 'reachable', val: 0, common: { write: false, min: false, max: true }},

progOn: { n: 'progOn', val: false, common: { min: false, max: true, desc: 'program on/off' }},
speed: { n: 'speed', val: 10, common: { min: 0, max: 255 }, desc: 'speed for preogram'},
progSpeed: { n: 'progSpeed', val: 10, common: { min: 0, max: 255 }, desc: 'speed for preogram'},
refresh: { n: 'refresh', val: false, common: { min: false, max: true, desc: 'read states from device' }},

@@ -150,5 +182,5 @@ //alpha: { n: 'sat', val: 0, common: { min: 0, max: 255 }},

break;
case usedStateNames.speed.n:
case usedStateNames.progSpeed.n:
var progNo = device.get(channel, usedStateNames.progNo.n).val;
device.add(channel, device.cmds.progNo, progNo, state.val);
device.addToQueue(channel, device.cmds.progNo, progNo, state.val);
break;

@@ -164,8 +196,8 @@ case usedStateNames.progNo.n:

} else {
var speed = device.get(channel, usedStateNames.speed.n).val | 30;
var speed = device.get(channel, usedStateNames.progSpeed.n).val | 30;
}
device.add(channel, device.cmds.progNo, state.val >> 0, speed);
device.addToQueue(channel, device.cmds.progNo, state.val >> 0, speed);
break;
case usedStateNames.progOn.n:
device.add(channel, state.val ? device.cmds.progOn : device.cmds.progOff);
device.addToQueue(channel, state.val ? device.cmds.progOn : device.cmds.progOff);
break;

@@ -214,2 +246,3 @@ case usedStateNames.command.n:

this.config = config;
this.isOnline = false;

@@ -224,9 +257,15 @@ this.cmds = cmds[config.type];

//this._updateTimer = null;
this.createDevice(function(err) {
this.setOnline(false);
if (this.cmds.onlyConnectOnWrite) {
this.USE_SOCKET_ONCE = true;
this.setOnline('on demand');
}
this.locked = 0;
this.queue = [];
this.dataBuffer = new Uint8Array(200);
//this.dataBuffer = new Buffer(200);
this.dataBuffer.pos = 0;
//this.dataBuffer = null;
this.states = { red: this.get('r'), green: this.get('g'), blue: this.get('b') };

@@ -238,2 +277,6 @@ this.start(cb);

wifiLight.prototype.log = function (msg) {
adapter.log.debug('[' + this.config.ip + '] ' + msg);
};
wifiLight.prototype.createDevice = function (cb) {

@@ -251,2 +294,10 @@ this.dev = new devices.CDevice(0, '');

wifiLight.prototype.reconnect = function (cb, timeout) {
if (this.client) {
this.destroyClient();
//setTimeout(this.start.bind(this), 5000);
setTimeout(this.start.bind(this, cb), timeout == undefined ? 5000 : timeout);
}
};
wifiLight.prototype.start = function (cb) {

@@ -261,7 +312,13 @@ if (this.USE_SOCKET_ONCE) {

self.destroyClient();
if (debug) {
this.ts = new Date().getTime();
}
self.client = new net.Socket();
self.client.setKeepAlive(true,30000);
self.client.setNoDelay(true);
self._write = this.USE_SOCKET_ONCE ? this.writeOnce : this.client.write.bind(this.client);
//self.client.setKeepAlive(true,10000);
//self.client.setNoDelay(true);
self.client.setTimeout(5000, function () {
//adapter.log.debug('self.client.setTimeout for ' + self.config.ip);
//self.log('self.client.setTimeout for ' + self.config.ip);
});

@@ -271,13 +328,15 @@ self.client.on('data', function(data) {

});
self.client.on('close', function(error) {
self.client.on('close', function(hasError) {
self.setOnline(false);
adapter.log.debug('onClose (' + self.config.ip + ')');
var ts = debug ? '(' + parseInt((new Date().getTime() - self.ts) / 1000) + ' sec) ' : "";
self.log('onClose ' + ts + 'hasError=' + hasError + ' client=' + self.client);
});
self.client.on('error', function(error) {
adapter.log.debug('onError (' + self.config.ip + '): ' + JSON.stringify(error));
var ts = debug ? '(' + parseInt((new Date().getTime() - self.ts) / 1000) + ' sec) ' : "";
self.log('onError: ' + ts + (error.code != undefined ? error.code : "") + error.message);
switch (error.errno) { //error.code
case 'ECONNRESET':
case 'ETIMEDOUT':
self.destroyClient();
setTimeout(self.start.bind(self), 5000);
case 'EPIPE':
self.reconnect(5000);
break;

@@ -287,9 +346,13 @@ }

});
self.client.on('connect', function(error) {
adapter.log.debug(self.config.ip + ' connected');
self.setOnline(true);
});
//self.client.on('connect', function(error) {
// wifi[self.dev.getFullId()] = self;
// self.log(self.config.ip + ' connected');
// self.setOnline(true);
// self.runUpdateTimer();
// if (cb) cb();
//});
self.client.connect(self.config.port, self.config.ip, function() {
wifi[self.dev.getFullId()] = self;
self.log(self.config.ip + ' connected');
self.setOnline(true);

@@ -312,5 +375,4 @@ self.runUpdateTimer();

wifiLight.prototype._write = function(data, cb) {
wifiLight.prototype.writeOnce = function(data, cb) {
var self = this;
if (this.client) {

@@ -322,5 +384,6 @@ this.client.write(data, cb);

this.client.setTimeout(5000, function () {
//adapter.log.debug('self.client.setTimeout for ' + self.config.ip);
//this.log('self.client.setTimeout for ' + self.config.ip);
});
var self = this;
this.client.on('data', function(data) {

@@ -345,3 +408,3 @@ self.onData(data);

wifiLight.prototype.unlock = function () {
this.add({unlock: true});
this.addToQueue({unlock: true});
};

@@ -367,9 +430,10 @@ wifiLight.prototype.lock = function () {

wifiLight.prototype.setOnline = function (val) {
this.dev.set(usedStateNames.online.n, !!val);
this.dev.set(usedStateNames.online.n, val);
//this.dev.update();
devices.update();
this.isOnline = val;
};
wifiLight.prototype.doRrefresh = function(channel) {
adapter.log.debug('sending refresh...');
wifiLight.prototype.directRefresh = function(channel) {
this.log('sending refresh...');
this.write(channel, this.cmds.statusRequest);

@@ -379,3 +443,3 @@ };

wifiLight.prototype.refresh = function(channel, ctrl) {
this.add(channel, this.cmds.statusRequest, { ctrl: ctrl|true });
this.addToQueue(channel, this.cmds.statusRequest, { ctrl: ctrl|true });
};

@@ -396,4 +460,14 @@

}
adapter.log.debug(buf);
this.USE_SOCKET_ONCE ? this._write(buf, cb) : this.client.write(buf, cb);
//var s = buf.inspect();
//this.log('writing: ' + buf.toString('hex').match(/.{2}/g).join(' '));
this.log('write: ' + hex(buf));
if (!this.isOnline) {
this.reconnect(function() {
//this.USE_SOCKET_ONCE ? this._write(buf, cb) : this.client.write(buf, cb);
this._write(buf, cb);
}.bind(this), 0);
return;
}
//this.USE_SOCKET_ONCE ? this._write(buf, cb) : this.client.write(buf, cb);
this._write(buf, cb);
};

@@ -405,3 +479,3 @@

wifiLight.prototype.add = function (varArgArray) {
wifiLight.prototype.addToQueue = function (varArgArray) {
var varArgs = arguments,

@@ -440,21 +514,15 @@ channel = "",

if (this.queue.length && this.queue[0].inProcess === 1) {
adapter.log.debug('add: return without calling exec');
//this.log('addToQueue: return without calling exec');
return;
}
adapter.log.debug('add: calling exec');
//this.log('addToQueue: calling exec');
this.exec();
};
wifiLight.prototype.send = wifiLight.prototype.add;
Array.prototype.eq = function (arr) {
return this.length==arr.length && this.every(function(v,i) { return v === arr[i]});
};
wifiLight.prototype.exec = function () {
adapter.log.debug('exec: queue.length=' + this.queue.length + (this.queue.length ? ' inProcess=' + this.queue[0].inProcess : ""));
//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) {
adapter.log.debug('exec: returning queue.length=0');
//this.log('exec: returning queue.length=0');
return;

@@ -466,5 +534,5 @@ }

}
adapter.log.debug('exec: removing queue entry ' + akt.cmd);
//this.log('exec: removing queue entry ' + akt.cmd.hex());
if (this.queue.length <= 1 && !akt.cmd.eq (this.cmds.statusRequest)) {
this.doRrefresh(akt.channel);
this.directRefresh(akt.channel);
}

@@ -477,5 +545,5 @@ this.queue.shift();

}
adapter.log.debug('exec: write: ' + akt.cmd);
//this.log('exec: write: ' + akt.cmd.hex());
this.write (akt.channel, akt.cmd, function() {
adapter.log.debug('exec: setTimeout: ' + akt.delay);
//this.log('exec: setTimeout: ' + akt.delay);
setTimeout(this.exec.bind(this), akt.delay);

@@ -488,3 +556,3 @@ }.bind(this));

wifiLight.prototype.on_off = function (channel, state) {
this.send(channel, state ? this.cmds.on : this.cmds.off);
this.addToQueue(channel, state ? this.cmds.on : this.cmds.off);
};

@@ -511,12 +579,7 @@

// }
// //this.send(channel, state ? this.cmds.on : this.cmds.off);
// //this.ad(channel, state ? this.cmds.on : this.cmds.off);
//};
wifiLight.prototype.fade = function (channel, rgbw,g,b, transitionTime) {
if (typeof rgbw != 'object') {
rgbw = { g: g, b: b, r: rgbw };
} else {
transitionTime = g;
}
if (transitionTime === 0) {
wifiLight.prototype.fade = function (channel, rgbw, transitionTime) {
if (!transitionTime) {
this.color(channel, rgbw);

@@ -538,3 +601,2 @@ return;

for (var i = 0; i<steps; i++) {
//this.color(channel, parseInt(co.r+0.5), parseInt(co.g+0.5), parseInt(co.b+0.5), { delay:delay });
co.r += dif.r;

@@ -548,13 +610,52 @@ co.g += dif.g;

wifiLight.prototype.color = function (channel, rgbw, g, b, opt) {
if (typeof rgbw != 'object') {
rgbw = { g: g, b: b, r: rgbw };
} else {
opt = g;
}
//wifiLight.prototype.fade = function (channel, rgbw,g,b, transitionTime) {
// if (typeof rgbw != 'object') {
// rgbw = { g: g, b: b, r: rgbw };
// } else {
// transitionTime = g;
// }
// if (transitionTime === 0) {
// this.color(channel, rgbw);
// return;
// }
// var co = { r: this.states.red, g: this.states.green, b: this.states.blue, w: this.states.white};
// var dif= { r: rgbw.r - co.r, g: rgbw.g - co.g, b: rgbw.b - co.b};
// dif.w = (rgbw.w != undefined && co.w != undefined) ? rgbw.w - co.w : 0;
// var maxSteps = Math.max(Math.abs(dif.r), Math.abs(dif.g), Math.abs(dif.b), Math.abs(dif.w), 1);
// dif.r /= maxSteps;
// dif.g /= maxSteps;
// dif.b /= maxSteps;
// dif.w /= maxSteps;
//
// var steps = maxSteps;
// var delay = parseInt(transitionTime*100 / maxSteps);
//
// for (var i = 0; i<steps; i++) {
// co.r += dif.r;
// co.g += dif.g;
// co.b += dif.b;
// if (co.w != undefined) co.w += dif.w;
// this.color(channel, roundRGB(co, true), { delay:delay });
// }
//};
//wifiLight.prototype.color = function (channel, rgbw, g, b, opt) {
// if (typeof rgbw != 'object') {
// rgbw = { g: g, b: b, r: rgbw };
// } else {
// opt = g;
// }
// rgbw.w == undefined ?
// this.addToQueue(channel, this.cmds.rgb, rgbw.r, rgbw.g, rgbw.b, opt) :
// this.addToQueue(channel, this.cmds.rgbw, rgbw.r, rgbw.g, rgbw.b, rgbw.w, opt);
//};
wifiLight.prototype.color = function (channel, rgbw, opt) {
rgbw.w == undefined ?
this.send(channel, this.cmds.rgb, rgbw.r, rgbw.g, rgbw.b, opt) :
this.send(channel, this.cmds.rgbw, rgbw.r, rgbw.g, rgbw.b, rgbw.w, opt);
this.addToQueue(channel, this.cmds.rgb, rgbw.r, rgbw.g, rgbw.b, opt) :
this.addToQueue(channel, this.cmds.rgbw, rgbw.r, rgbw.g, rgbw.b, rgbw.w, opt);
};
wifiLight.prototype.temperature = function (channel, temp, transitionTime) {

@@ -599,8 +700,6 @@ var co = ct2rgb(temp);

var b = new Uint8Array(newPos + 200);
//var b = new Buffer(newPos + 200);
for (var i=0; i<this.dataBuffer.pos; i++) {
b [i] = this.dataBuffer[i];
}
//this.dataBuffer.forEach(function (v, i) {
// b [i] = v;
//});
b.pos = this.dataBuffer.pos;

@@ -615,4 +714,7 @@ this.dataBuffer = b;

{
var buf = this.dataBuffer.subarray(0, this.cmds.responseLen);
var states = this.cmds.decodeResponse(buf);
//var buf = this.dataBuffer.subarray(0, this.cmds.responseLen);
//var buf = new Buffer(this.dataBuffer, 0, this.cmds.responseLen);
//var states = this.cmds.decodeResponse(buf);
var states = this.cmds.decodeResponse(this.dataBuffer);
this.log('onData: raw: ' + hex(this.dataBuffer, this.cmds.responseLen));
this.dataBuffer.copyWithin(0, this.cmds.responseLen, this.dataBuffer.pos);

@@ -622,4 +724,3 @@ this.dataBuffer.pos -= this.cmds.responseLen;

this.states = states;
adapter.log.debug('onData: raw:' + JSON.stringify(buf));
adapter.log.debug('onData: ' + JSON.stringify(this.states));
this.log('onData: ' + JSON.stringify(this.states));
if (this.states) {

@@ -632,3 +733,3 @@ set(usedStateNames.status.n, this.states.power);

set(usedStateNames.progOn.n, this.states.progOn);
set(usedStateNames.speed.n, this.states.speed);
set(usedStateNames.progSpeed.n, this.states.progSpeed);
set(usedStateNames.white.n, this.states.white);

@@ -680,3 +781,3 @@ devices.update();

// set(usedStateNames.progOn.n, this.states.progOn);
// set(usedStateNames.speed.n, this.states.speed);
// set(usedStateNames.progSpeed.n, this.states.progSpeed);
// devices.update();

@@ -683,0 +784,0 @@ // }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc