Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.15 to 0.0.17

9

devices.js

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

var result = {
power: ((data[2] === 0x23) ? true : false),
//power: ((data[2] === 0x23) ? true : false),
on: ((data[2] === 0x23) ? true : false),
progNo: data[3],//mode

@@ -96,3 +97,4 @@ progOn: data[4] === 33, //modeRun

return {
power: ((data[2] === 0x23) ? true : false),
//power: ((data[2] === 0x23) ? true : false),
on: ((data[2] === 0x23) ? true : false),
//power: ((data[13] & 0x01) ? true : false),

@@ -130,3 +132,4 @@ //power: ((data[13] & 0x01) ? false : true),

return {
power: ((data[2] === 0x23) ? true : false),
//power: ((data[2] === 0x23) ? true : false),
on: ((data[2] === 0x23) ? true : false),
//power: ((data[13] & 0x01) ? true : false),

@@ -133,0 +136,0 @@ //power: ((data[13] & 0x01) ? false : true),

{
"common": {
"name": "wifilight",
"version": "0.0.15",
"version": "0.0.17",
"title": "WiFi Light",

@@ -6,0 +6,0 @@ "desc": {

{
"name": "iobroker.wifilight",
"version": "0.0.15",
"version": "0.0.17",
"description": "WiFi Light Adapter",

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

"use strict";
var utils = require(__dirname + '/lib/utils'),
//soef = require(__dirname + '/lib/soef'),
var //utils = require(__dirname + '/lib/utils'),
discovery = require(__dirname + '/lib/discovery'),
colors = require(__dirname + '/lib/colors'),
soef = require('soef'),
//devices = new soef.Devices(),
net = require('net'),
discovery = require(__dirname + '/lib/discovery'),
colors = require(__dirname + '/lib/colors');
net = require('net');

@@ -37,50 +35,55 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var adapter = utils.adapter({
name: 'wifilight',
unload: function (callback) {
try {
for (var i in wifi) {
wifi[i].close();
}
callback();
} catch (e) {
callback();
var adapter = soef.Adapter (
main,
onStateChange,
onMessage,
{
name: 'wifilight',
//discover: function (callback) {
//},
//install: function (callback) {
//},
uninstall: function (callback) {
}
},
//discover: function (callback) {
//},
//install: function (callback) {
//},
//uninstall: function (callback) {
//},
objectChange: function (id, obj) {
},
stateChange: function (id, state) {
if (state && !state.ack) {
stateChange(id, state);
}
},
message: onMessage,
ready: function () {
soef.main(adapter, 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();
//});
//objectChange: function (id, obj) {
//}
}
});
);
//var utils = require(__dirname + '/lib/utils');
//
//var adapter = utils.adapter({
// name: 'wifilight',
//
// unload: function (callback) {
// try {
// for (var i in wifi) {
// wifi[i].close();
// }
// callback();
// } catch (e) {
// callback();
// }
// },
// //discover: function (callback) {
// //},
// //install: function (callback) {
// //},
// //uninstall: function (callback) {
// //},
// objectChange: function (id, obj) {
// },
// stateChange: function (id, state) {
// if (state && !state.ack) {
// onStateChange(id, state);
// }
// },
// message: onMessage,
// ready: function () {
// soef.main(adapter, main);
// }
//});
//
function onMessage (obj) {

@@ -122,7 +125,11 @@ if (!obj) return;

var usedStateNames = {
online: { n: 'reachable', val: 0, common: { write: false, min: false, max: true }},
status: { n: 'on', val: false, common: { min: false, max: true }},
brightness: { n: 'bri', val: 0, common: { min: 0, max: 100, unit: '%', desc: '0..100%' }},
temperature: { n: 'ct', val: 0, common: { min: 0, max: 5000, unit: '°K', desc: 'in °Kelvin 0..5000' }},
//status: { n: 'on', val: false, common: { min: false, max: true }},
on: { n: 'on', val: false, common: { min: false, max: true }},
//brightness: { n: 'bri', val: 0, common: { min: 0, max: 100, unit: '%', desc: '0..100%' }},
bri: { n: 'bri', val: 0, common: { min: 0, max: 100, unit: '%', desc: '0..100%' }},
//temperature: { n: 'ct', val: 0, common: { min: 0, max: 5000, unit: '°K', desc: 'temperature in °Kelvin 0..5000' }},
ct: { n: 'ct', val: 0, common: { min: 0, max: 5000, unit: '°K', desc: 'temperature in °Kelvin 0..5000' }},
red: { n: 'r', val: 0, common: { min: 0, max: 255, desc: '0..255 or #rrggbb[ww] (hex)' }},

@@ -143,3 +150,3 @@ green: { n: 'g', val: 0, common: { min: 0, max: 255, desc: '0..255 or #rrggbb[ww] (hex)' }},

function parseHexColor(val) {
function parseHexColors(val) {
var co = {

@@ -154,3 +161,3 @@ r: parseInt(val.substr(1, 2), 16),

function stateChange(id, state) {
function onStateChange(id, state) {
var ar = id.split('.');

@@ -164,2 +171,3 @@ //var dcs = adapter.idToDCS(id);

device.clearQueue();
devices.invalidate(id);
switch (stateName) {

@@ -176,8 +184,2 @@ case 'on':

var co = parseHexColors(state.val);
//var co = {
// r: parseInt(state.val.substr(1, 2), 16),
// g: parseInt(state.val.substr(3, 2), 16),
// b: parseInt(state.val.substr(5, 2), 16),
// w: state.val.length > 7 ? parseInt(state.val.substr(7, 2), 16) : undefined
//};
device.color(channel, co);

@@ -190,8 +192,14 @@ break;

break;
case usedStateNames.brightness.n:
device.brightness(channel, state.val >> 0, transitionTime);
case usedStateNames.refresh.n:
device.refresh();
device.dev.set(usedStateNames.refresh.n, false);
device.dev.update();
//devices.update();
break;
case usedStateNames.temperature.n:
device.temperature(channel, state.val >> 0, transitionTime);
case usedStateNames.bri.n:
device.bri(channel, state.val >> 0, transitionTime);
break;
case usedStateNames.ct.n:
device.ct(channel, state.val >> 0, transitionTime);
break;
case usedStateNames.progSpeed.n:

@@ -218,4 +226,6 @@ var progNo = device.get(channel, usedStateNames.progNo.n).val;

case usedStateNames.command.n:
var v = state.val.replace(/^on$|red|green|blue|transition|bri|off|#/g, function(match) { return { '#': '#', of:'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(/#((\d|[a-f]|[A-F])*)/g, 'h:"$1"').replace(/(r|g|b|w|x|l|sat|of|on|ct|h)/g, '"$1"').replace(/^\{?(.*?)\}?$/, '{$1}');
//var v = state.val.replace(/^on$|red|green|blue|transition|bri|off|#/g, function(match) { return { '#': '#', of:'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(/#((\d|[a-f]|[A-F])*)/g, 'h:"$1"').replace(/(r|g|b|w|x|l|sat|of|on|ct|h)/g, '"$1"').replace(/^\{?(.*?)\}?$/, '{$1}');
var v = state.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}');
try {

@@ -228,3 +238,3 @@ var colors = JSON.parse(v);

if (colors.h) {
var co = parseHexColor('#'+colors.h);
var co = parseHexColors('#'+colors.h);
colors.r = co.r; colors.g = co.g; colors.b = co.b;

@@ -234,2 +244,6 @@ delete colors.h;

if (!colors || typeof colors !== 'object') return;
if(colors.off !== undefined) {
device.color(channel, {r:0, g:0, b:0, w: colors.w != undefined ? 0 : undefined});
device.states.red = 0; device.states.green = 0; device.states.blue = 0; if (device.states.white != undefined) device.states.white = 0;
}
var o = fullExtend(device.getRGBStates(channel), colors);

@@ -240,5 +254,5 @@ adapter.log.debug(JSON.stringify(o));

}
if(o.of !== undefined) {
device.color(channel, {r:0, g:0, b:0, w: o.w != undefined ? 0 : undefined});
}
//if(o.of !== undefined) {
// device.color(channel, {r:0, g:0, b:0, w: o.w != undefined ? 0 : undefined});
//}
if (o['on'] !== undefined) {

@@ -251,6 +265,6 @@ device.on_off(channel, o.on >> 0 ? true : false);

if (o['ct'] !== undefined) {
device.temperature(channel, o.ct >> 0, transitionTime);
device.ct(channel, o.ct >> 0, transitionTime);
}
if (o['l'] !== undefined) {
device.brightness(channel, o.l >> 0, transitionTime);
device.bri(channel, o.l >> 0, transitionTime);
}

@@ -314,5 +328,8 @@ break;

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

@@ -376,3 +393,4 @@ }

self.runUpdateTimer();
if (cb) cb();
adapter.log.debug('self.client.connect: connected');
if (cb && typeof cb == 'function') cb();
});

@@ -477,3 +495,2 @@ };

this.reconnect(function() {
//this.USE_SOCKET_ONCE ? this._write(buf, cb) : this.client.write(buf, cb);
this._write(buf, cb);

@@ -483,3 +500,2 @@ }.bind(this), 0);

}
//this.USE_SOCKET_ONCE ? this._write(buf, cb) : this.client.write(buf, cb);
this._write(buf, cb);

@@ -616,45 +632,2 @@ };

//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) {

@@ -666,4 +639,3 @@ rgbw.w == undefined ?

wifiLight.prototype.temperature = function (channel, temp, transitionTime) {
wifiLight.prototype.ct = function (channel, temp, transitionTime) {
var co = ct2rgb(temp);

@@ -677,2 +649,3 @@ var hsv = rgb2hsv(co);

};
wifiLight.prototype.temperature = wifiLight.prototype.ct;

@@ -688,3 +661,3 @@ wifiLight.prototype.getRGBStates = function (channel) {

wifiLight.prototype.brightness = function (channel, bri, transitionTime) {
wifiLight.prototype.bri = function (channel, bri, transitionTime) {
var co = this.getRGBStates(channel);

@@ -696,2 +669,3 @@ var hsv = rgb2hsv(co);

};
wifiLight.prototype.brightness = wifiLight.prototype.bri;

@@ -701,8 +675,2 @@

var self = this;
function set(n, val) {
if (val != undefined) self.dev.set(n, val);
}
var self = this;
var newPos = this.dataBuffer.pos + data.length;

@@ -735,10 +703,11 @@ if (newPos > this.dataBuffer.length) {

if (this.states) {
set(usedStateNames.status.n, this.states.power);
set(usedStateNames.red.n, this.states.red);
set(usedStateNames.green.n, this.states.green);
set(usedStateNames.blue.n, this.states.blue);
set(usedStateNames.progNo.n, this.states.progNo);
set(usedStateNames.progOn.n, this.states.progOn);
set(usedStateNames.progSpeed.n, this.states.progSpeed);
set(usedStateNames.white.n, this.states.white);
//set(usedStateNames.status.n, this.states.power);
this.dev.set(usedStateNames.on.n, this.states.on);
this.dev.set(usedStateNames.red.n, this.states.red);
this.dev.set(usedStateNames.green.n, this.states.green);
this.dev.set(usedStateNames.blue.n, this.states.blue);
this.dev.set(usedStateNames.progNo.n, this.states.progNo);
this.dev.set(usedStateNames.progOn.n, this.states.progOn);
this.dev.set(usedStateNames.progSpeed.n, this.states.progSpeed);
this.dev.set(usedStateNames.white.n, this.states.white);
devices.update();

@@ -750,48 +719,2 @@ }

//wifiLight.prototype.xonData = function (data) {
//
// var self = this;
// function set(n, val) {
// if (val != undefined) self.dev.set(n, val);
// }
//
// var self = this;
//
// this.dataBuffer.concat(data.buffer);
// data.forEach(function(val) {
// self.dataBuffer.push(val);
// });
// //this.dataBuffer.splice(this.dataBuffer.length, 0, data);
//
// if (this.dataBuffer.length < this.cmds.responsLen) {
// return null;
// }
//
// //var len = this.cmds.responsLen ? this.cmds.responsLen : data.length;
// while (this.dataBuffer.length >= this.cmds.responseLen)
// //for (var i=0; i<data.length; i+=len)
// {
// var buf = this.dataBuffer.splice(0, this.cmds.responseLen);
// //var buf = data.slice(i, i + len);
// var states = this.cmds.decodeResponse(buf);
// if (!states) break;
// this.states = states;
// //var result = this.cmds.decodeResponse(data);
// adapter.log.debug('onData: raw:' + JSON.stringify(buf));
// adapter.log.debug('onData: ' + JSON.stringify(this.states));
// if (this.states) {
// set(usedStateNames.status.n, this.states.power);
// set(usedStateNames.red.n, this.states.red);
// set(usedStateNames.green.n, this.states.green);
// set(usedStateNames.blue.n, this.states.blue);
// set(usedStateNames.progNo.n, this.states.progNo);
// set(usedStateNames.progOn.n, this.states.progOn);
// set(usedStateNames.progSpeed.n, this.states.progSpeed);
// devices.update();
// }
// }
// return this.states;
//};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@@ -801,2 +724,3 @@

dev.pollIntervall = parseInt(dev.pollIntervall) | 0;
if (dev.pollIntervall && dev.pollIntervall < 5) dev.pollIntervall = 5;
dev.port = parseInt(dev.port) || 5577;

@@ -803,0 +727,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