iobroker.wifilight
Advanced tools
Comparing version 0.0.18 to 0.0.19
347
devices.js
@@ -10,5 +10,9 @@ "use strict"; | ||
white: -6, | ||
bright: -7 | ||
bright: -7, | ||
separator: -8, | ||
sepNoDelay: -9 | ||
}; | ||
exports.VARS = VARS; | ||
const programNames = { | ||
@@ -40,3 +44,4 @@ 97: "none", | ||
'HF-LPB100-ZJ200': { type: 'LD382A' /*, port: 5577*/ }, | ||
'HF-A11-ZJ002': { type: 'LW12' } | ||
'HF-A11-ZJ002': { type: 'LW12' }, | ||
'Mi-Light': { type: 'MiLight', port: 8899 } | ||
}; | ||
@@ -147,1 +152,339 @@ | ||
//LimitlessLED | ||
exports.MiLight = { | ||
//http://www.limitlessled.com/dev/ | ||
port: 8899, | ||
udp: true, | ||
onlyConnectOnWrite: true, | ||
broadcastIP: '255.255.255.255', | ||
g: 2, | ||
//onlyConnectOnWrite: true, | ||
dimSteps: 25, // RGBW | ||
//dimSteps: 11, // white | ||
//dimSteps: 9, // RGB | ||
colorSteps: 255, // RGBW | ||
//colorSteps: 11, // white | ||
//colorSteps: 255, // RGB | ||
delay: 100, | ||
setZone: function(zone) { | ||
var self = this; | ||
if (zone > 4) zone = 0; | ||
self.on[0] = [0x42,0x45,0x47,0x49,0x4B][zone]; | ||
self.off[0] = [0x41,0x46,0x48,0x4A,0x4C][zone]; | ||
self.whiteMode[0] = [0xC2,0xC5,0xC7,0xC9,0xCB][zone]; | ||
self.nightMode[0] = [0xC1,0xC6,0xC8,0xCA,0xCC][zone]; | ||
self.maxBright[0] = [0xB5,0xB8,0xBD,0xB7,0xB2][zone]; | ||
self.wtOn[0] = [0x35,0x38,0x3D,0x37,0x32][zone]; | ||
self.wtOff[0] = [0x39,0x3B,0x33,0x3A,0x36][zone]; | ||
self.wtNightMode[0] = [0xB9,0xBB,0xB3,0xBA,0xB6][zone]; | ||
self.wtmaxBright[0] = [0xB5,0xB8,0xBD,0xB7,0xB2][zone]; | ||
function _cc (self, sep) { | ||
return function (varArgArray) { | ||
var varArgs = arguments; | ||
var isarr = true; | ||
var ret = self; | ||
for (var i = 0; i < varArgs.length; i++) { | ||
var _isarr = (varArgs[i] instanceof Array); | ||
if (_isarr || _isarr !== isarr) { | ||
ret = ret.concat(sep); | ||
} | ||
isarr = _isarr; | ||
ret = ret.concat(varArgs[i]) | ||
} | ||
return ret; | ||
} | ||
} | ||
var noSuffix = false; | ||
for (var p in self) { | ||
if ((self[p] instanceof Array) && self[p].length === 3) { | ||
if (self[p][1] < 0) self[p].f = function(val) { | ||
var ret = this.slice(); | ||
ret[1] = val; | ||
return ret; | ||
}; | ||
if (noSuffix && self[p][2] === 0x55) { | ||
self[p].length -= 1; | ||
} | ||
self[p].cc = _cc(self[p], VARS.separator); | ||
self[p].ccn = _cc(self[p], VARS.sepNoDelay); | ||
} | ||
} | ||
}, | ||
on: [0x42,0x00,0x55], | ||
off: [0x41,0x00,0x55], | ||
whiteMode: [0xc2,0x00,0x55], | ||
nightMode: [0xC1,0x00,0x55], | ||
maxBright: [0xB5,0x00,0x55], | ||
discoMode: [0x4D,0x00,0x55], | ||
discoSpeedSlower: [0x43,0x00,0x55], | ||
discoSpeedFaster: [0x44,0x00,0x55], | ||
wtOn: [0x35,0x00,0x55], | ||
wtOff:[0x39,0x00,0x55], | ||
wtNightMode:[0xB9,0x00,0x55], | ||
wtmaxBright:[0xB5,0x00,0x55], | ||
wtBrightUp: [0x3C,0x00,0x55], | ||
wtBrightDown: [0x34,0x00,0x55], | ||
wtWarmer: [0x3E,0x00,0x55], | ||
wtCooler: [0x3F,0x00,0x55], | ||
progNo: [0x4D,0x00,0x55], | ||
bri: [0x4E, VARS.bright, 0x55], | ||
hue: [0x40, VARS.red, 0x55], | ||
pair: [0x25, 0x00, 0x55], // send 3 x with 1 sec delay | ||
unPair: [0x25, 0x00, 0x55], // send 15 x with 200 ms delay | ||
////////////////////////////////////////////////////////////////////////////// | ||
rgb: [0x00], | ||
rgbw: [0x00], | ||
//progOn: [0x71, 0x21, 0x0f], | ||
//progOff: [0x71, 0x20, 0x0f], | ||
//statusRequest: [0x81, 0x8A, 0x8B], | ||
programNames: { | ||
1: 'Regenbogen', | ||
2: 'Weiß Blinken', | ||
3: 'Farbverlauf', | ||
4: 'Farbwechsel', | ||
5: 'Flash (alle Farben)', | ||
6: 'Disco', | ||
7: '7', | ||
8: '8', | ||
9: 'Fade - Blinken (rot)', | ||
10: 'Fade - Blinken (grün)', | ||
11: 'Fade - Blinken (blau)', | ||
12: '12', | ||
13: '13', | ||
14: '14', | ||
15: '15', | ||
16: '16', | ||
17: '17', | ||
18: '18', | ||
19: '19', | ||
20: '20' | ||
}, | ||
__bri: function __bri (percent) { | ||
return this.bri.f(Math.floor(2 + (((percent||0) / 100) * 25))); | ||
}, | ||
_white: function(percent) { | ||
if (percent === 0) return this.off; | ||
return this.whiteMode.cc(this.__bri(percent)); | ||
}, | ||
_color: function(hue) { | ||
return this.on.cc(this.hue.f(hue)); | ||
}, | ||
_bri: function(percent) { | ||
return this.on.cc(this.__bri(percent)); | ||
}, | ||
_setProgNo: function (zone, no) { | ||
//var cmd = [this.on[0], 0x00, 0x40, 0x40, this.on[0], 0x00, /*0x4e, 0x02*/]; | ||
var cmd; | ||
if (no === 2) cmd = this.off.concat(VARS.seperator, this.on, VARS.sepNoDelay, 0x40, 0x40, VARS.sepNoDelay, this.bri[0], 0x02, 0x55, VARS.sepNoDelay); | ||
//else cmd = this.off.cc(this.on, this.__bri(100)); | ||
else cmd = this.off.concat(VARS.seperator, this.on, VARS.sepNoDelay, 0x40, 0x40, VARS.sepNoDelay, this.bri[0], 0x02, 0x55, VARS.sepNoDelay); | ||
while (no--) { | ||
cmd.push(0x4d); | ||
cmd.push(0x00); | ||
cmd.push(VARS.separator); | ||
//cmd.push(VARS.sepNoDelay); | ||
} | ||
return cmd; | ||
if (no === 2) cmd = this.off.concat(VARS.seperator, this.on, VARS.sepNoDelay, 0x40, 0x40, VARS.sepNoDelay, this.bri[0], 0x02, 0x55, VARS.sepNoDelay); | ||
else cmd = this.off.concat(VARS.separator, this.on, VARS.sepNoDelay, this.bri[0], /*0x02,*/0x1b, 0x55, VARS.sepNoDelay); | ||
//nokcmd = this.off.concat(this.on, this.bri[0], 0x02, VARS.separator); | ||
while (no--) { | ||
cmd.push(0x4d); | ||
cmd.push(0x00); | ||
//cmd.push(VARS.separator); | ||
cmd.push(VARS.sepNoDelay); | ||
} | ||
return cmd; | ||
if (no === 2) cmd = this.on.concat(VARS.separator, 0x40, 0x40, VARS.separator, /*this.on, VARS.separator,*/ this.bri[0], 0x02, VARS.separator); | ||
else cmd = this.off.concat(this.on, VARS.separator, /*0x40, 0x40, VARS.separator, this.on, VARS.separator,*/ this.bri[0], 0x02, VARS.separator); | ||
if (no === 2) cmd = this.off.concat(VARS.separator, this.on, VARS.separator, 0x40, 0x40, VARS.separator, this.bri[0], 0x02, 0x55, VARS.separator); | ||
else cmd = this.off.concat(VARS.separator, this.on, VARS.separator, this.bri[0], 0x02, 0x55, VARS.separator); | ||
//nokcmd = this.off.concat(this.on, this.bri[0], 0x02, VARS.separator); | ||
while (no--) { | ||
cmd.push(0x4d); | ||
cmd.push(0x00); | ||
//cmd.push(VARS.separator); | ||
} | ||
return cmd; | ||
var cmd = [0x45, 0x00, VARS.separator, 0x40, 0x40, VARS.separator, 0x45, 0x00, VARS.separator, 0x4d, 0x00, VARS.separator, 0x4d, 0x00]; | ||
return cmd; | ||
var no1 = no; | ||
var cmd = [this.on[0], 0x00, VARS.separator/*0x4e, 0x02*/]; | ||
while (no--) { | ||
cmd.push(0x4d); | ||
cmd.push(0x00); | ||
cmd.push(VARS.separator); | ||
} | ||
// var cmd = this.on.slice(); | ||
// while (no--) { | ||
// cmd = cmd.concat(this.discoMode); | ||
// } | ||
// //var cmd = this.on.slice(); | ||
// var cmd = [this.on[0], 0x00]; | ||
// while (no--) { | ||
// cmd = cmd.concat(this.discoMode[0], 0x00); | ||
// } | ||
var cmd1 = [this.on[0], 0x00]; | ||
while (no1--) { | ||
cmd1 = cmd1.concat(this.discoMode[0], 0x00); | ||
} | ||
return cmd1; | ||
return cmd; | ||
} | ||
}; | ||
exports.MiLightRGB = { | ||
//http://www.limitlessled.com/dev/ | ||
port: 8899, | ||
udp: true, | ||
onlyConnectOnWrite: true, | ||
broadcastIP: '255.255.255.255', | ||
g: 2, | ||
//onlyConnectOnWrite: true, | ||
dimSteps: 9, // GBW | ||
//dimSteps: 11, // white | ||
colorSteps: 255, // RGBW | ||
//colorSteps: 11, // white | ||
//colorSteps: 255, // RGB | ||
delay: 100, | ||
responseLen: 14, | ||
setZone: function(zone) { | ||
var self = this; | ||
if (zone > 4) zone = 0; | ||
self.on[0] = [0x42,0x45,0x47,0x49,0x4B][zone]; | ||
self.off[0] = [0x41,0x46,0x48,0x4A,0x4C][zone]; | ||
self.whiteMode[0] = [0xC2,0xC5,0xC7,0xC9,0xCB][zone]; | ||
self.nightMode[0] = [0xC1,0xC6,0xC8,0xCA,0xCC][zone]; | ||
self.maxBright[0] = [0xB5,0xB8,0xBD,0xB7,0xB2][zone]; | ||
self.wtOn[0] = [0x35,0x38,0x3D,0x37,0x32][zone]; | ||
self.wtOff[0] = [0x39,0x3B,0x33,0x3A,0x36][zone]; | ||
self.wtNightMode[0] = [0xB9,0xBB,0xB3,0xBA,0xB6][zone]; | ||
self.wtmaxBright[0] = [0xB5,0xB8,0xBD,0xB7,0xB2][zone]; | ||
// for (var p in self) { | ||
// if (typeof self[p] === 'function') { | ||
// self[p].bind(self); | ||
// } | ||
// } | ||
self.pair = self.on; // send 3 x with 1 sec delay | ||
self.unPair = self.on; // send 15 x with 200 ms delay | ||
}, | ||
on: [0x22,0x00,0x55], | ||
off: [0x21,0x00,0x55], | ||
//off: [0x41,0x00], | ||
// whiteMode: [0xc2,0x00,0x55], | ||
// nightMode: [0xC1,0x00,0x55], | ||
// maxBright: [0xB5,0x00,0x55], | ||
// | ||
// discoMode: [0x4D,0x00,0x55], | ||
discoModeUp: [0x27, 0x00, 0x55], | ||
discoModeDown: [0x28, 0x00, 0x55], | ||
discoSpeedSlower: [0x26,0x00,0x55], | ||
discoSpeedFaster: [0x25,0x00,0x55], | ||
// | ||
// | ||
// wtOn: [0x35,0x00,0x55], | ||
// wtOff:[0x39,0x00,0x55], | ||
// wtNightMode:[0xB9,0x00,0x55], | ||
// wtmaxBright:[0xB5,0x00,0x55], | ||
// wtBrightUp: [0x3C,0x00,0x55], | ||
// wtBrightDown: [0x34,0x00,0x55], | ||
// wtWarmer: [0x3E,0x00,0x55], | ||
// wtCooler: [0x3F,0x00,0x55], | ||
// | ||
// progNo: [0x4D,0x00,0x55], | ||
////////////////////////////////////////////////////////////////////////////// | ||
rgb: [0x31, VARS.red, VARS.green, VARS.blue, 0xff /*VARS.white*/, 0x00, 0x0f], | ||
rgbw: [0x31, VARS.red, VARS.green, VARS.blue, VARS.white, 0x00, 0x0f], | ||
progOn: [0x71, 0x21, 0x0f], | ||
progOff: [0x71, 0x20, 0x0f], | ||
//statusRequest: [0x81, 0x8A, 0x8B], | ||
programNames: { | ||
1: 'Regenbogen', | ||
2: 'Weiß Blinken', | ||
3: 'Farbverlauf', | ||
4: 'Farbwechsel', | ||
5: 'Flash (alle Farben)', | ||
6: 'Disco', | ||
7: '7', | ||
8: '8', | ||
9: 'Fade - Blinken (rot)', | ||
10: 'Fade - Blinken (grün)', | ||
11: 'Fade - Blinken (blau)', | ||
12: '12', | ||
13: '13', | ||
14: '14', | ||
15: '15', | ||
16: '16', | ||
17: '17', | ||
18: '18', | ||
19: '19', | ||
20: '20' | ||
}, | ||
_color: function(hue) { | ||
//return this.on.concat(VARS.separator, [0x40, hue, 0x55]); | ||
return [].concat(this.on, 0x20, hue, 0x55); | ||
}, | ||
briDown: [0x24, 0x00, 0x55], | ||
briUp: [0x23, 0x00, 0x55], | ||
_bri: function(percent) { | ||
//if (percent >= 100) return this.on.concat(VARS.separator, this.maxBright); | ||
var bri = Math.floor(2 + (((percent||0) / 100) * this.dimSteps)); | ||
var cmd = [].concat(this.on); | ||
for (i=0; i<bri; i++) { | ||
cmd.push(this.briUp); | ||
} | ||
}, | ||
_setProgNo: function (zone, no) { | ||
var cmd = [this.on[0], 0x00, 0x40, 0x40, this.on[0], 0x00, /*0x4e, 0x02*/]; | ||
while (no--) { | ||
cmd.push(0x4d); | ||
cmd.push(0x00); | ||
} | ||
// var cmd = [this.on[0], 0x00, 0x55, | ||
// //0x40, 0x40, | ||
// this.on[0], 0x00, 0x55/*0x4e, 0x02*/]; | ||
// | ||
// while (no--) { | ||
// cmd.push(0x4d); | ||
// cmd.push(0x00); | ||
// cmd.push(0x55); | ||
// } | ||
return cmd; | ||
} | ||
}; |
{ | ||
"common": { | ||
"name": "wifilight", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"title": "WiFi Light", | ||
@@ -6,0 +6,0 @@ "desc": { |
{ | ||
"name": "iobroker.wifilight", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"description": "WiFi Light Adapter", | ||
@@ -5,0 +5,0 @@ "author": { |
606
wifilight.js
@@ -33,2 +33,3 @@ "use strict"; | ||
Array.prototype.eq = function (arr) { | ||
if(arr == undefined) return false; | ||
return this.length==arr.length && this.every(function(v,i) { return v === arr[i]}); | ||
@@ -62,3 +63,4 @@ }; | ||
case 'discovery': | ||
discovery.scanForDevices( | ||
//discovery.scanForDevices( | ||
discovery.scanForAllDevices( | ||
function(entry) { | ||
@@ -71,3 +73,3 @@ var ret = !adapter.config.devices.some(function(e,i) { | ||
entry.type = dev ? dev.type : ''; | ||
entry.port = 5577; | ||
entry.port = dev && dev.port ? dev.port : 5577; | ||
entry.pollIntervall = 30; | ||
@@ -96,23 +98,24 @@ } | ||
var _g = { | ||
}; | ||
var usedStateNames = { | ||
online: { n: 'reachable', val: 0, common: { write: false, min: false, max: true }}, | ||
//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)' }}, | ||
green: { n: 'g', val: 0, common: { min: 0, max: 255, desc: '0..255 or #rrggbb[ww] (hex)' }}, | ||
blue: { n: 'b', val: 0, common: { min: 0, max: 255, desc: '0..255 or #rrggbb[ww] (hex)' }}, | ||
white: { n: 'w', val: 0, common: { min: 0, max: 255, desc: '0..255 or #rrggbb[ww] (hex)' }}, | ||
progNo: { n: 'progNo', val: 38, common: { min: 35, max: 56, desc: '37..56, 97=none' }}, | ||
progOn: { n: 'progOn', val: false, common: { min: false, max: true, desc: 'program on/off' }}, | ||
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' }}, | ||
//alpha: { n: 'sat', val: 0, common: { min: 0, max: 255 }}, | ||
transition: { n: 'trans', val: 30, common: { unit: '\u2152 s', desc: 'in 10th seconds'} }, | ||
command: { n: 'command', 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', val: '', common: { desc: '000000..ffffff' }} | ||
online: { n: 'reachable', g:1, val: 0, common: { write: false, min: false, max: true }}, | ||
on: { n: 'on', g:3, val: false, common: { min: false, max: true }}, | ||
bri: { n: 'bri', g:3, val: 0, common: { min: 0, max: 100, unit: '%', desc: '0..100%' }}, | ||
ct: { n: 'ct', g:1, val: 0, common: { min: 0, max: 5000, unit: '°K', desc: 'temperature in °Kelvin 0..5000' }}, | ||
red: { n: 'r', g:3, val: 0, common: { min: 0, max: 255, desc: '0..255 or #rrggbb[ww] (hex)' }}, | ||
green: { n: 'g', g:3, val: 0, common: { min: 0, max: 255, desc: '0..255 or #rrggbb[ww] (hex)' }}, | ||
blue: { n: 'b', g:3, val: 0, common: { min: 0, max: 255, desc: '0..255 or #rrggbb[ww] (hex)' }}, | ||
white: { n: 'w', g:3, val: 0, common: { min: 0, max: 255, desc: '0..255 or #rrggbb[ww] (hex)' }}, | ||
disco: { n: 'disco', g:2, val: 1, common: { min: 1, max: 9, desc: '1..9' }}, | ||
progNo: { n: 'progNo', g:1, val: 38, common: { min: 35, max: 56, desc: '37..56, 97=none' }}, | ||
progOn: { n: 'progOn', g:1, val: false, common: { min: false, max: true, desc: 'program on/off' }}, | ||
progSpeed: { n: 'progSpeed', g:3, val: 10, common: { min: 0, max: 255 }, desc: 'speed for preogram'}, | ||
refresh: { n: 'refresh', g:1, val: false, common: { min: false, max: true, desc: 'read states from device' }}, | ||
transition: { n: 'trans', g:1, val: 30, common: { 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: { desc: '000000..ffffff' }}, | ||
onTime: { n: 'onTime', g:3, val: '', common: {}} | ||
}; | ||
@@ -145,20 +148,144 @@ | ||
function onStateChange(id, state) { | ||
var ar = id.split('.'); | ||
//var dcs = adapter.idToDCS(id); | ||
var deviceName = ar[2], stateName = ar[3]; | ||
var deviceName = ar[2], channelName = ''; | ||
if (ar.length > 4) { | ||
channelName = ar.splice(3, 1)[0]; | ||
deviceName += '.' + channelName; | ||
} | ||
var stateName = ar[3]; | ||
var device = wifi[deviceName]; | ||
if (device == undefined) return; | ||
var channel = ""; | ||
var transitionTime = device.get(channel, usedStateNames.transition.n).val || 3; | ||
device.clearQueue(); | ||
devices.invalidate(id); | ||
if (device.cmds.decodeResponse) devices.invalidate(id); | ||
device.onStateChange(channelName, stateName, state.val); | ||
} | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// function wifiLight(config, zone, cb) { | ||
// if (!(this instanceof wifiLight)) { | ||
// return new wifiLight(config, zone, cb); | ||
// } | ||
// if (cb) cb.bind(this); | ||
// this.USE_SOCKET_ONCE = false; //true; | ||
// this.config = config; | ||
// this.isOnline = false; | ||
// this.zone = zone; | ||
// | ||
// this.cmds = cmds[config.type]; | ||
// if (!this.cmds) { | ||
// adapter.log.error('wrong device type. ' + config.type + ' not yet supported!'); | ||
// if (cb) cb(-1); | ||
// return null; | ||
// } | ||
// if(this.cmds.vmax == undefined) this.cmds.vmax = 255; | ||
// if (zone !== undefined) { | ||
// //this.cmds = Object.assign({}, tmp, {v:1}); | ||
// //this.cmds = fullExtend({}, this.cmds); | ||
// this.cmds = clone(this.cmds); | ||
// //var i = this.cmds._bri(); | ||
// //this.cmds = Object.create(this.cmds); | ||
// //this.cmds.off[0] = 12; | ||
// this.cmds.setZone(this.cmds, zone); | ||
// } | ||
// | ||
// 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') }; | ||
// this.start(cb); | ||
// }.bind(this)); | ||
// return this; | ||
// } | ||
var WifiLight = function (config, zone, cb) { | ||
if (!(this instanceof WifiLight)) { | ||
return new WifiLight(config, zone, cb); | ||
} | ||
if (!config) return this; | ||
this.USE_SOCKET_ONCE = false; //true; | ||
this.config = config; | ||
this.isOnline = false; | ||
this.cmds = cmds[config.type]; | ||
}; | ||
WifiLight.prototype.run = function (cb) { | ||
if (!this.cmds) { | ||
adapter.log.error('wrong device type. ' + this.config.type + ' not yet supported!'); | ||
if (cb) cb(-1); | ||
return null; | ||
} | ||
if (this.cmds.vmax == undefined) this.cmds.vmax = 255; | ||
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.states = { red: this.get('r'), green: this.get('g'), blue: this.get('b') }; | ||
this.start(cb); | ||
}.bind(this)); | ||
return this; | ||
}; | ||
WifiLight.prototype.log = function (msg) { | ||
adapter.log.debug('[' + this.config.ip + '] ' + msg); | ||
}; | ||
WifiLight.prototype.createDevice = function (cb) { | ||
this.dev = new devices.CDevice(0, ''); | ||
this.dev.setDevice(this.config.ip, {common: {name: this.config.name, role: 'device'}, native: { type: this.config.type, intervall: this.config.pollIntervall } }); | ||
if (this.zone !== undefined) { | ||
this.dev.setChannel(this.zone.toString(), ['All Zones', 'Zone 1', 'Zone 2', 'Zone 3', 'Zone 4'][this.zone]); | ||
} | ||
var _g = this.cmds.g || 1; | ||
for (var j in usedStateNames) { | ||
if (j == 'white' && this.cmds.rgbw == undefined) continue; | ||
var st = Object.assign({}, usedStateNames[j]); | ||
if ((j === 'progNo' || j==='disco') && this.cmds.programNames) st.common.states = this.cmds.programNames; | ||
if (st.g & _g) { | ||
this.dev.createNew(st.n, st); | ||
} | ||
} | ||
devices.update(cb); | ||
}; | ||
WifiLight.prototype.onStateChange = function (channel, stateName, val) { | ||
var transitionTime = this.get(channel, usedStateNames.transition.n) || {val:0}.val || 0; | ||
this.clearQueue(); | ||
switch (stateName) { | ||
case usedStateNames.transition.n: | ||
//this.dev.setAndUpdate(usedStateNames.transition.n, val); | ||
this.dev.updateVal(usedStateNames.transition.n, val); | ||
break; | ||
case 'onTime': | ||
this.onTime(channel, val); | ||
break; | ||
case 'on': | ||
device.on_off(channel, state.val >> 0 ? true : false); | ||
this.on_off(channel, val >> 0 ? true : false); | ||
break; | ||
case 'rgbw': | ||
case 'rgb': | ||
var co = parseHexColors(state.val); | ||
device.color(channel, co); | ||
var co = parseHexColors(val); | ||
this.color(channel, co); | ||
break; | ||
@@ -171,43 +298,47 @@ case 'r': | ||
var co; | ||
if (typeof state.val == 'string' && state.val[0] == '#') { | ||
co = parseHexColors(state.val); | ||
if (typeof val == 'string' && val[0] == '#') { | ||
co = parseHexColors(val); | ||
} else { | ||
co = device.getRGBStates(channel); | ||
co[stateName] = state.val >> 0; | ||
co = this.getRGBStates(channel); | ||
co[stateName] = val >> 0; | ||
} | ||
device.color(channel, co); | ||
this.color(channel, co); | ||
break; | ||
case usedStateNames.refresh.n: | ||
device.refresh(); | ||
device.dev.set(usedStateNames.refresh.n, false); | ||
device.dev.update(); | ||
this.refresh(); | ||
this.dev.set(usedStateNames.refresh.n, false); | ||
this.dev.update(); | ||
break; | ||
case usedStateNames.bri.n: | ||
device.bri(channel, state.val >> 0, transitionTime); | ||
this.bri(channel, val >> 0, transitionTime); | ||
break; | ||
case usedStateNames.ct.n: | ||
device.ct(channel, state.val >> 0, transitionTime); | ||
this.ct(channel, val >> 0, transitionTime); | ||
break; | ||
case usedStateNames.progSpeed.n: | ||
var progNo = device.get(channel, usedStateNames.progNo.n).val; | ||
device.addToQueue(channel, device.cmds.progNo, progNo, state.val); | ||
var progNo = this.get(channel, usedStateNames.progNo.n).val; | ||
this.addToQueue(channel, this.cmds.progNo, progNo, val); | ||
break; | ||
case usedStateNames.progNo.n: | ||
if (typeof state.val == 'string') { | ||
var ar = state.val.split(' '); | ||
if (!ar || ar.lengt < 2) ar = state.val.split(','); | ||
if (typeof val == 'string') { | ||
var ar = val.split(' '); | ||
if (!ar || ar.lengt < 2) ar = val.split(','); | ||
if (ar && ar.length >= 2) { | ||
var speed = parseInt(ar[1]); | ||
state.val = parseInt(ar[0]); | ||
val = parseInt(ar[0]); | ||
} | ||
} else { | ||
var speed = device.get(channel, usedStateNames.progSpeed.n).val | 30; | ||
var speed = this.getval(channel, usedStateNames.progSpeed.n, 30); | ||
} | ||
device.addToQueue(channel, device.cmds.progNo, state.val >> 0, speed); | ||
//if (this.cmds._setProgNo) _setProgNo(this, channel, val >> 0); else | ||
this.addToQueue(channel, this.cmds.progNo, val >> 0, speed); | ||
break; | ||
// case 'disco': | ||
// if (this.cmds._setProgNo) this.addToQueue(channel, this.cmds._setProgNo(channel, val >> 0)); | ||
// break; | ||
case usedStateNames.progOn.n: | ||
device.addToQueue(channel, state.val ? device.cmds.progOn : device.cmds.progOff); | ||
this.addToQueue(channel, val ? this.cmds.progOn : this.cmds.progOff); | ||
break; | ||
case usedStateNames.command.n: | ||
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] }); | ||
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}'); | ||
@@ -218,11 +349,8 @@ 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}'); | ||
} catch (e) { | ||
adapter.log.error("on Command: " + e.message + ': state.val="' + state.val + '"'); | ||
adapter.log.error("on Command: " + e.message + ': state.val="' + val + '"'); | ||
return; | ||
} | ||
if (colors.h) { | ||
var co = parseHexColors('#'+colors.h); | ||
//colors = Object.assign(colors, co); | ||
for (var i in co) { | ||
colors[i] = co[i]; | ||
} | ||
//var co = parseHexColors('#'+colors.h); | ||
Object.assign(colors, parseHexColors(colors.h)); | ||
delete colors.h; | ||
@@ -232,6 +360,6 @@ } | ||
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; | ||
this.color(channel, {r:0, g:0, b:0, w: colors.w != undefined ? 0 : undefined}); | ||
this.states.red = 0; this.states.green = 0; this.states.blue = 0; if (this.states.white != undefined) this.states.white = 0; | ||
} | ||
var o = fullExtend(device.getRGBStates(channel), colors); | ||
var o = fullExtend(this.getRGBStates(channel), colors); | ||
adapter.log.debug(JSON.stringify(o)); | ||
@@ -242,12 +370,12 @@ if (o.x !== undefined) { | ||
if (o['on'] !== undefined) { | ||
device.on_off(channel, o.on >> 0 ? true : false); | ||
this.on_off(channel, o.on >> 0 ? true : false); | ||
} | ||
if (colors.r!==undefined || colors.g!==undefined || colors.b!==undefined || colors.w!==undefined || colors.sat!==undefined) { | ||
device.fade(channel, o, transitionTime); | ||
this.fade(channel, o, transitionTime); | ||
} | ||
if (o['ct'] !== undefined) { | ||
device.ct(channel, o.ct >> 0, transitionTime); | ||
this.ct(channel, o.ct >> 0, transitionTime); | ||
} | ||
if (o['l'] !== undefined) { | ||
device.bri(channel, o.l >> 0, transitionTime); | ||
this.bri(channel, o.l >> 0, transitionTime); | ||
} | ||
@@ -258,55 +386,5 @@ break; | ||
} | ||
} | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
function wifiLight(config, cb) { | ||
this.USE_SOCKET_ONCE = false; //true; | ||
this.config = config; | ||
this.isOnline = false; | ||
this.cmds = cmds[config.type]; | ||
if (!this.cmds) { | ||
adapter.log.error('wrong device type. ' + config.type + ' not yet supported!'); | ||
if (cb) cb(-1); | ||
return null; | ||
} | ||
if(this.cmds.vmax == undefined) this.cmds.vmax = 255; | ||
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') }; | ||
this.start(cb); | ||
}.bind(this)); | ||
return this; | ||
} | ||
wifiLight.prototype.log = function (msg) { | ||
adapter.log.debug('[' + this.config.ip + '] ' + msg); | ||
}; | ||
wifiLight.prototype.createDevice = function (cb) { | ||
this.dev = new devices.CDevice(0, ''); | ||
this.dev.setDevice(this.config.ip, {common: {name: this.config.name, role: 'device'}, native: { type: this.config.type, intervall: this.config.pollIntervall } }); | ||
for (var j in usedStateNames) { | ||
if (j == 'white' && this.cmds.rgbw == undefined) continue; | ||
var st = Object.assign({}, usedStateNames[j]); | ||
if (j == 'progNo' && this.cmds.programNames) st.common.states = this.cmds.programNames; | ||
this.dev.createNew(st.n, st); | ||
} | ||
devices.update(cb); | ||
}; | ||
wifiLight.prototype.reconnect = function (cb, timeout) { | ||
WifiLight.prototype.reconnect = function (cb, timeout) { | ||
if (cb && typeof cb != 'function') { | ||
@@ -322,7 +400,15 @@ timeout = cb; | ||
wifiLight.prototype.start = function (cb) { | ||
WifiLight.prototype._write = function(data, cb) { | ||
this.client.write(data, cb); | ||
}; | ||
WifiLight.prototype.start = function (cb) { | ||
if (this.USE_SOCKET_ONCE) { | ||
wifi[this.dev.getFullId()] = this; | ||
cb(0); | ||
return; | ||
//this._write = this.cmds.udp ? this.writeUdp : this.writeOnce; | ||
if (this.__proto__._write === WifiLight.prototype._write) { | ||
WifiLight.prototype._write = this.writeOnce; | ||
} | ||
return cb && cb(0); | ||
} | ||
@@ -336,10 +422,2 @@ | ||
self.client = new net.Socket(); | ||
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 () { | ||
//self.log('self.client.setTimeout for ' + self.config.ip); | ||
}); | ||
self.client.on('data', function(data) { | ||
@@ -365,5 +443,2 @@ self.onData(data); | ||
}); | ||
//self.client.on('connect', function(error) { | ||
//}); | ||
self.client.connect(self.config.port, self.config.ip, function() { | ||
@@ -379,3 +454,3 @@ wifi[self.dev.getFullId()] = self; | ||
wifiLight.prototype.destroyClient = function () { | ||
WifiLight.prototype.destroyClient = function () { | ||
if (this.updateTimer) { | ||
@@ -391,3 +466,3 @@ clearTimeout(this.updateTimer); | ||
wifiLight.prototype.writeOnce = function(data, cb) { | ||
WifiLight.prototype.writeOnce = function(data, cb) { | ||
@@ -418,14 +493,19 @@ if (this.client) { | ||
wifiLight.prototype.get = function (channel, state) { | ||
WifiLight.prototype.get = function (channel, state) { | ||
return this.dev.get(channel, state); | ||
}; | ||
WifiLight.prototype.getval = function (channel, state, def) { | ||
var o = this.dev.get(channel, state); | ||
if (o && o.val !== undefined) return o.val; | ||
return def; | ||
}; | ||
wifiLight.prototype.unlock = function () { | ||
WifiLight.prototype.unlock = function () { | ||
this.addToQueue({unlock: true}); | ||
}; | ||
wifiLight.prototype.lock = function () { | ||
WifiLight.prototype.lock = function () { | ||
this.locked += 1; | ||
}; | ||
wifiLight.prototype.close = function() { | ||
WifiLight.prototype.close = function() { | ||
if (this.client) { | ||
@@ -437,3 +517,4 @@ this.client.destroy(); | ||
wifiLight.prototype.runUpdateTimer = function () { | ||
WifiLight.prototype.runUpdateTimer = function () { | ||
if (!this.cmds.decodeResponse) return; | ||
this.refresh(); | ||
@@ -445,3 +526,3 @@ if (this.config.pollIntervall > 0) { | ||
wifiLight.prototype.setOnline = function (val) { | ||
WifiLight.prototype.setOnline = function (val) { | ||
this.dev.set(usedStateNames.online.n, val); | ||
@@ -453,3 +534,4 @@ //this.dev.update(); | ||
wifiLight.prototype.directRefresh = function(channel) { | ||
WifiLight.prototype.directRefresh = function(channel) { | ||
if (!this.cmds.statusRequest) return; | ||
this.log('sending refresh...'); | ||
@@ -459,7 +541,8 @@ this.write(channel, this.cmds.statusRequest); | ||
wifiLight.prototype.refresh = function(channel, ctrl) { | ||
WifiLight.prototype.refresh = function(channel, ctrl) { | ||
if (!this.cmds.statusRequest) return; | ||
this.addToQueue(channel, this.cmds.statusRequest, { ctrl: ctrl|true }); | ||
}; | ||
wifiLight.prototype.write = function(channel, cmd, cb) { | ||
WifiLight.prototype.write = function(channel, cmd, cb) { | ||
var varArgs = arguments, buf; | ||
@@ -489,7 +572,7 @@ if (this.cmds.useCheckSum) { | ||
wifiLight.prototype.clearQueue = function() { | ||
WifiLight.prototype.clearQueue = function() { | ||
this.queue.length = 0; | ||
}; | ||
wifiLight.prototype.addToQueue = function (varArgArray) { | ||
WifiLight.prototype.addToQueue = function (varArgArray) { | ||
var varArgs = arguments, | ||
@@ -506,5 +589,8 @@ channel = "", | ||
} | ||
if (varArgs.length > idx+1) { | ||
for (var i = 0, j=idx+1; i < varArgs[idx].length; i++) { | ||
cmd[i] = varArgs[idx][i] < 0 ? varArgs[j++] : varArgs[idx][i]; | ||
//cmd[i] = varArgs[idx][i] < 0 ? varArgs[j++] : varArgs[idx][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]; | ||
} | ||
@@ -518,12 +604,36 @@ } else { | ||
} | ||
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 | ||
}); | ||
var _cmd = []; | ||
var last = cmd.length - 1; | ||
cmd.forEach(function(c, i) { | ||
var sep = 0; | ||
switch(c) { | ||
case cmds.VARS.separator: sep = 1; break; | ||
case cmds.VARS.sepNoDelay: sep = 2; break; | ||
default: _cmd.push(c); | ||
} | ||
//var sep = (c === cmds.VARS.separator || (c === cmds.VARS.sepNoDelay)); | ||
//if (!sep) _cmd.push(c); | ||
if (sep || i === last) { | ||
this.queue.push({ | ||
cmd: _cmd, | ||
ctrl: opt && opt.ctrl ? true : false, | ||
channel: channel, | ||
delay: sep & 2 ? 0 : opt && opt.delay !== undefined ? opt.delay : this.cmds.delay != undefined ? this.cmds.delay : 10, | ||
ts: 0, | ||
inProcess: 0, | ||
unlock: 0 | ||
}); | ||
_cmd = []; | ||
} | ||
}.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) { | ||
@@ -533,7 +643,6 @@ //this.log('addToQueue: return without calling exec'); | ||
} | ||
//this.log('addToQueue: calling exec'); | ||
this.exec(); | ||
}; | ||
wifiLight.prototype.exec = function () { | ||
WifiLight.prototype.exec = function () { | ||
//this.log('exec: queue.length=' + this.queue.length + (this.queue.length ? ' inProcess=' + this.queue[0].inProcess : "")); | ||
@@ -569,7 +678,8 @@ var akt; | ||
wifiLight.prototype.on_off = function (channel, state) { | ||
WifiLight.prototype.on_off = function (channel, state) { | ||
this.addToQueue(channel, state ? this.cmds.on : this.cmds.off); | ||
//if (!state && this.cmds.udp) this.addToQueue(channel, [0x4E,0x19,0x55]); | ||
}; | ||
wifiLight.prototype.fade = function (channel, rgbw, transitionTime) { | ||
WifiLight.prototype.fade = function (channel, rgbw, transitionTime) { | ||
if (!transitionTime) { | ||
@@ -600,3 +710,3 @@ this.color(channel, rgbw); | ||
wifiLight.prototype.color = function (channel, rgbw, opt) { | ||
WifiLight.prototype.color = function (channel, rgbw, opt) { | ||
rgbw.w == undefined ? | ||
@@ -607,3 +717,3 @@ this.addToQueue(channel, this.cmds.rgb, rgbw.r, rgbw.g, rgbw.b, opt) : | ||
wifiLight.prototype.ct = function (channel, temp, transitionTime) { | ||
WifiLight.prototype.ct = function (channel, temp, transitionTime) { | ||
var co = ct2rgb(temp); | ||
@@ -617,5 +727,5 @@ var hsv = rgb2hsv(co); | ||
}; | ||
wifiLight.prototype.temperature = wifiLight.prototype.ct; | ||
WifiLight.prototype.temperature = WifiLight.prototype.ct; | ||
wifiLight.prototype.getRGBStates = function (channel) { | ||
WifiLight.prototype.getRGBStates = function (channel) { | ||
return { | ||
@@ -629,3 +739,3 @@ r: this.states.red, | ||
wifiLight.prototype.bri = function (channel, bri, transitionTime) { | ||
WifiLight.prototype.bri = function (channel, bri, transitionTime) { | ||
var co = this.getRGBStates(channel); | ||
@@ -637,7 +747,24 @@ var hsv = rgb2hsv(co); | ||
}; | ||
wifiLight.prototype.brightness = wifiLight.prototype.bri; | ||
//WifiLight.prototype.brightness = WifiLight.prototype.bri; | ||
wifiLight.prototype.onData = function (data) { | ||
WifiLight.prototype.onTime = function (channel, val) { | ||
if (this.onTimerObject) { | ||
clearTimeout(this.onTimerObject); | ||
this.onTimerObject = null; | ||
} | ||
var timeout = val >> 0, | ||
cmd = '#00000000;x10'; | ||
if (typeof val == 'string') { | ||
var ar = val.split(';'); | ||
timeout = parseInt(ar.shift()); | ||
cmd = ar.join(';'); | ||
} | ||
if (timeout && timeout > 0) { | ||
this.onTimerObject = setTimeout(this.onStateChange.bind(this), timeout*100, channel, 'command', cmd); | ||
} | ||
}; | ||
WifiLight.prototype.onData = function (data) { | ||
var newPos = this.dataBuffer.pos + data.length; | ||
@@ -650,2 +777,3 @@ if (newPos > this.dataBuffer.length) { | ||
} | ||
//this.dataBuffer.copy(b, 0, 0, this.dataBuffer.pos); | ||
b.pos = this.dataBuffer.pos; | ||
@@ -688,2 +816,120 @@ 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); | ||
//this.cmds.off[0] = 12; | ||
this.cmds.setZone(this.zone); | ||
this.states = { on: 0, red: 0, green: 0, blue: 0, white: 0 }; | ||
this.writeTimer = soef.Timer(); | ||
}; | ||
// function extend(destination , source) { | ||
// for (var k in source) { | ||
// destination[k] = source[k]; | ||
// } | ||
// } | ||
//extend(MiLight.prototype, WifiLight.prototype); | ||
//MiLight.prototype = WifiLight.prototype; | ||
MiLight.prototype = new WifiLight; | ||
MiLight.prototype.construcor = WifiLight; | ||
MiLight.prototype._write = function writeUdp (data, cb) { | ||
var self = this; | ||
//??this.writeTimer.clear(); | ||
if (!this.client) { | ||
var dgram = require('dgram'); | ||
//self.config.ip = '255.255.255.255'; | ||
self.client = dgram.createSocket('udp4'); | ||
//self.client = dgram.createSocket({ type: 'udp4', reuseAddr: true }); | ||
self.client.on("listening", function (error) { | ||
if (error) return cb && cb(error); | ||
if (self.config.ip === '255.255.255.255') { | ||
self.client.setBroadcast(true); | ||
} | ||
}); | ||
self.client.on('message', function (data, rinfo) { | ||
}); | ||
this.client.on('data', function (data) { | ||
}); | ||
this.client.on('error', function (error) { | ||
}); | ||
this.client.on('close', function (error) { | ||
self.client = null; | ||
adapter.log.debug('udp socked closed'); | ||
}); | ||
} | ||
self.client.send(data, 0, data.length, self.config.port, self.config.ip, function(error, bytes) { | ||
self.writeTimer.set(function() { | ||
if (self && self.client) self.client.close(); | ||
}, 2000); | ||
cb && cb(); | ||
}); | ||
}; | ||
MiLight.prototype.bri = function (channel, bri, transitionTime) { | ||
this.addToQueue(channel, this.cmds._bri(bri)); | ||
}; | ||
MiLight.prototype.color = function (channel, rgbw, opt) { | ||
if (rgbw.w !== undefined) { | ||
this.addToQueue(channel, this.cmds._white((rgbw.w * 100 / 255) >> 0)); | ||
return; | ||
} | ||
var hsv = rgb2hsv(rgbw); | ||
if (hsv.h === 0 && hsv.v === 0) { | ||
this.on_off(channel, false); | ||
return; | ||
} | ||
var color = (256 + 176 - Math.floor(Number(hsv.h) / 360.0 * 255.0)) % 256; | ||
this.addToQueue(channel, this.cmds.on); | ||
this.addToQueue(channel, this.cmds._color(color)); | ||
this.addToQueue(channel, this.cmds._bri(hsv.v)); | ||
}; | ||
// WifiLight.prototype.ct = function (channel, temp, transitionTime) { | ||
// var co = ct2rgb(temp); | ||
// var hsv = rgb2hsv(co); | ||
// //hsv.v = this.get(channel, 'bri').val; | ||
// var v = this.get(channel, 'bri').val; | ||
// if (v) hsv.v = v; | ||
// co = hsv2rgb(hsv); | ||
// this.fade(channel, co, transitionTime); | ||
// }; | ||
MiLight.prototype.pair = function pair() { | ||
for (var i=0; i<3; i++) { | ||
this.addToQueue(channel, this.pair, { delay: 1000 }); | ||
} | ||
}; | ||
MiLight.prototype.unPair = function pair() { | ||
for (var i=0; i<15; i++) { | ||
this.addToQueue(channel, this.unPair, { delay: 200 }); | ||
} | ||
}; | ||
MiLight.prototype.onStateChange = function (channel, stateName, val) { | ||
switch (stateName) { | ||
case 'disco': | ||
if (this.cmds._setProgNo) this.addToQueue(channel, this.cmds._setProgNo(channel, val >> 0)); | ||
break; | ||
default: | ||
WifiLight.prototype.onStateChange.call(this, channel, stateName, val); | ||
} | ||
}; | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
function normalizeConfigDevice(dev) { | ||
@@ -701,4 +947,15 @@ dev.pollIntervall = parseInt(dev.pollIntervall) | 0; | ||
new wifiLight(adapter.config.devices[i], function() { | ||
if (adapter.config.devices[i].type === 'MiLight') { | ||
for (var z=0; z<=4; z++) { | ||
//new WifiLight(adapter.config.devices[i], z, function() { | ||
new MiLight(adapter.config.devices[i], z).run(function() { | ||
}); | ||
} | ||
} | ||
else | ||
// new WifiLight(adapter.config.devices[i], undefined, function() { | ||
// }); | ||
new WifiLight(adapter.config.devices[i]).run(function() { | ||
}); | ||
} | ||
@@ -710,1 +967,22 @@ devices.update(); | ||
//_id.replace(/[^.]+$/, 'command'); | ||
//debug = process.env.hasOwnProperty('WifiLight_DEBUG') ? consoleDebug : function () { | ||
// function extend(destination , source) { | ||
// for (var k in source) { | ||
// destination[k] = source[k]; | ||
// } | ||
// } | ||
// extend(xyz.prototype, abc.prototype); | ||
// module.exports.bind = function(obj, fn){ | ||
// if ('string' == typeof fn) fn = obj[fn]; | ||
// if ('function' != typeof fn) throw new Error('bind() requires a function'); | ||
// var args = slice.call(arguments, 2); | ||
// return function(){ | ||
// return fn.apply(obj, args.concat(slice.call(arguments))); | ||
// } | ||
// }; | ||
//util.inherits |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78243
1550
4