Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
TuyaColorLight.prototype.setToCurrentColor = function(callback) {
if(this.deviceEnabled === false) {
this.log.warn('Device is disabled... Bailing out...');
callback('Disabled');
return;
}
var color = this.color;
var color2 = this.color2;
var lightness = Math.round(this.brightness / 2);
var brightness = this.brightness;
var apiBrightness = this._convertPercentageToVal(brightness);
var alphaBrightness = this._getAlphaHex(brightness);
var hexColorOriginal1 = convert.hsl.hex(color.H, color.S, color.L);
var rgbColorOriginal1 = convert.hsl.rgb(color.H, color.S, color.L);
var hexColorOriginal2 = convert.hsl.hex(0, 0, 50);
var rgbColorOriginal2 = convert.hsl.rgb(0, 0, 50);
var hexColor1 = convert.hsl.hex(color.H, color.S, lightness);
var rgbColor1 = convert.hsl.rgb(color.H, color.S, lightness);
var hexColor2 = convert.hsl.hex(0, 0, lightness);
var rgbColor2 = convert.hsl.rgb(0, 0, lightness);
var colorTemperature = this.colorTemperature;
// var ww = Math.round((this.brightness * 255) / 100);
var lightColor = (hexColor1 + hexColor2 + alphaBrightness).toLowerCase();
TuyaColorLight.prototype.getDps = function () {
var color = this.color;
var lightness = Math.round(this.brightness / 2);
var brightness = this.brightness;
var apiBrightness = this._convertPercentageToVal(brightness);
var alphaBrightness = this._getAlphaHex(brightness);
var hexColor1 = convert.hsl.hex(color.H, color.S, lightness);
var hexColor2 = convert.hsl.hex(0, 0, lightness);
var colorTemperature = this.colorTemperature;
var lightColor = (hexColor1 + hexColor2 + alphaBrightness).toLowerCase();
var temperature = (this.colorMode === 'colour') ? 255 : this._convertColorTemperature(colorTemperature);
dpsTmp = {
'1': true,
'2': this.colorMode,
'3': apiBrightness,
'4': temperature,
'5': lightColor
// '6' : hexColor + hexColor + 'ff'
};
debug("dps", dpsTmp);
resp.writeHead(200, {"Content-Type": "application/json"});
resp.write(JSON.stringify({"uniqueName": smartDevice.uniqueName, "method": "pingresponse"}));
resp.end();
} else if (url.pathname.includes("/pair")) {
retObj = {"uniqueName": smartDevice.uniqueName, "method":"pair", "params": {"value": null}}
console.log("smartserver:httpRequestHandler: pair url - req.url=" + req.url +
" pathname=" + url.pathname + " queryObj=" + JSON.stringify(url.query) );
} else if (url.pathname.includes("/rgb")) {
var rgb, hex, hsl
if (url.query.mode=="hex") {
hex = url.query.value
rgb = COLORS.hex.rgb(hex)
hsl = COLORS.hex.hsl.raw(hex)
} else if (url.query.mode=="hsl") {
hsl = [url.query.hue,url.query.saturation,100]
rgb = COLORS.hsl.rgb(hsl)
hex = COLORS.hsl.hex(hsl)
} else if (url.query.mode=="decimal") {
rgb = DecToRGB(url.query.value)
hsl = COLORS.rgb.hsl.raw(rgb)
hex = COLORS.rgb.hex(rgb)
} else {
rgb = COLORS.hex.rgb("FFFAF0")
hsl = COLORS.hex.hsl.raw("FFFAF0")
hex = "FFFAF0"
}
retObj.method = "set_rgb";
retObj.colors = {red: rgb[0], green: rgb[1], blue: rgb[2],
hue: hsl[0], saturation: hsl[1],
hex:hex };
retObj.params = {value: retObj.colors.hex, effect: effect, duration: duration};
} else if (url.pathname.includes("/trigger")) {
}
case 'HEXHEX':
case '#HEXHEX':
return {
name: source.input,
rgb: converter.hex.rgb(this.name)
}
case 'RGB':
return {
name: converter.rgb.hex(source.input),
rgb: converter.hex.rgb(this.name)
}
case 'HSL':
return {
name: converter.hsl.hex(source.input),
rgb: converter.hsl.rgb(source.input)
}
case 'HSV':
return {
name: converter.hsv.hex(source.input),
rgb: converter.hsv.rgb(source.input)
}
case 'HWB':
return {
name: converter.hwb.hex(source.input),
rgb: converter.hwb.rgb(source.input)
}
case 'SGR':
return {
name: source.input,
rgb: source.input
}
public createColorOutput(hue: number, saturation: number, lightness: number): ColorOutput {
const [red, green, blue] = convert.hsl.rgb([hue, saturation, lightness]);
const rgb: Rgb = {
red,
green,
blue,
};
const hex = convert.rgb.hex([red, green, blue]);
return {
rgb: rgb,
hexString: `#${hex}`,
hex: parseInt(`0x${hex}`, 16),
hsl: {
hue,
saturation,
public toHex(): string {
return `#${convert.hsl.hex([this.h, this.s, this.l])}`
}
input
}
case 'HEXHEX':
case '#HEXHEX':
return {
name: source.input,
rgb: converter.hex.rgb(this.name)
}
case 'RGB':
return {
name: converter.rgb.hex(source.input),
rgb: converter.hex.rgb(this.name)
}
case 'HSL':
return {
name: converter.hsl.hex(source.input),
rgb: converter.hsl.rgb(source.input)
}
case 'HSV':
return {
name: converter.hsv.hex(source.input),
rgb: converter.hsv.rgb(source.input)
}
case 'HWB':
return {
name: converter.hwb.hex(source.input),
rgb: converter.hwb.rgb(source.input)
}
case 'SGR':
return {
name: source.input,
rgb: source.input
function setColor(r, g, b) {
var hex;
if (r != null) {
hex = '#' + convert.rgb.hex(r, g, b);
current = convert.rgb.hsl(r, g, b);
} else {
var h = x / window.innerWidth * 360;
var s = 100 - (y / window.innerHeight * 100);
var l = z;
current = [h, s, l];
hex = '#' + convert.hsl.hex(h, s, l);
}
currentHex = hex;
ctx.fillStyle = hex;
ctx.fillRect(0, 0, 16, 16);
link.href = canvas.toDataURL("image/x-icon");
document.title = hex;
if (dark && current[2] >= 40) {
dark = false;
div.className = 'xhair dark';
} else if (!dark && current[2] < 40) {
dark = true;
div.className = 'xhair light';
}
document.body.style.backgroundColor = hex;
input.value = hex;
hue (value) {
const hsl = convert.rgb.hsl(this.array.map(channel => ratioToNum(channel)));
hsl[0] = (value % 1) * 360;
return this.set(...convert.hsl.rgb(hsl).map(channel => channel / 0xff));
}
private createColorOutput(hue: number, saturation: number, lightness: number): ColorOutput {
const rgbArray = convert.hsl.rgb([hue, saturation, lightness]);
const rgb: RGB = {
red: rgbArray[0],
green: rgbArray[1],
blue: rgbArray[2],
}
const hex = convert.rgb.hex(rgbArray);
return {
rgb: rgb,
hexString: `#${hex}`,
hex: parseInt(`0x${hex}`, 16),
}
}
}