forked from cakebake/node-red-contrib-alexa-remote-cakebaked
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
2,461 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const Base = require('alexa-remote2'); | ||
const util = require('util'); | ||
|
||
function requireUncached(mod) { | ||
delete require.cache[require.resolve(mod)]; | ||
return require(mod); | ||
} | ||
|
||
// my own implementation to keep track of the value on errors, for debugging and patching false positives | ||
function promisify(fun) { | ||
return (function() { | ||
return new Promise((resolve, reject) => { | ||
fun.bind(this)(...arguments, (err, val) => { | ||
if(err) { | ||
if(typeof err === 'object') { | ||
err.value = val; | ||
} | ||
reject(err); | ||
} | ||
else { | ||
resolve(val); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
class AlexaRemote extends Base | ||
{ | ||
constructor() { | ||
super(arguments); | ||
|
||
// blacklist: ^(?:\t|[ ]{4})(?![A-z]*constructor)[A-z]*\((?![^\)]*callback)[^\)]*\) | ||
const names = [ | ||
'getSmarthomeDevices', | ||
'getSmarthomeEntities', | ||
'getSmarthomeGroups', | ||
'getSmarthomeBehaviourActionDefinitions', | ||
'httpsGet' | ||
]; | ||
|
||
for(const name of names) { | ||
this[name + 'Promise'] = promisify(this[name]); | ||
} | ||
} | ||
|
||
generateCookie(email, password, callback) { | ||
if (!this.alexaCookie) this.alexaCookie = requireUncached('alexa-cookie2'); | ||
this.alexaCookie.generateAlexaCookie(email, password, this._options, callback); | ||
} | ||
|
||
refreshCookie(callback) { | ||
if (!this.alexaCookie) this.alexaCookie = requireUncached('alexa-cookie2'); | ||
this.alexaCookie.refreshAlexaCookie(this._options, callback); | ||
} | ||
} | ||
|
||
module.exports = AlexaRemote; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// ranges 0..1 | ||
function rgb2hex(rgb) { | ||
[r,g,b] = rgb.map(x => Math.round(x*255)); | ||
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1) | ||
} | ||
|
||
// ranges 0..1 | ||
function hex2rgb(hex) { | ||
if(hex[0] === '#') hex.slice(1); | ||
const num = parseInt(hex, 16); | ||
const r = (num >> 16 & 255) / 255; | ||
const g = (num >> 8 & 255) / 255; | ||
const b = (num & 255) / 255; | ||
return [r,g,b]; | ||
} | ||
|
||
// ranges 0..1 | ||
function rgb2hsv([r,g,b]) { | ||
let K = 0.0; | ||
|
||
if(g < b) { | ||
[b, g] = [g, b]; | ||
K = -1.0; | ||
} | ||
|
||
if(r < g) { | ||
[g, r] = [r, g]; | ||
K = -1.0/3.0 - K; | ||
} | ||
|
||
chroma = r - Math.min(g,b); | ||
return [ | ||
Math.abs(K + (g-b) / (6.0 * chroma)), | ||
chroma / r, | ||
r | ||
] | ||
} | ||
|
||
// ranges 0..1 | ||
function hsv2rgb([h,s,v]) { | ||
let x = (h%1) * 6.0; | ||
let i = Math.floor(x); | ||
let f = x - i; | ||
let p = v * (1.0 - s); | ||
let q = v * (1.0 - s * f); | ||
let t = v * (1.0 - s * (1.0 - f)); | ||
|
||
switch(i) { | ||
case 0: return [v, t, p]; | ||
case 1: return [q, v, p]; | ||
case 2: return [p, v, t]; | ||
case 3: return [p, q, v]; | ||
case 4: return [t, p, v]; | ||
case 5: return [v, p, q]; | ||
} | ||
} | ||
|
||
module.exports = { | ||
rgb2hex: rgb2hex, | ||
hex2rgb: hex2rgb, | ||
rgb2hsv: rgb2hsv, | ||
hsv2rgb: hsv2rgb | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
const knownColorValues = { | ||
colorTemperatureNames: { | ||
cool_white: 7000, | ||
soft_white: 2700, | ||
incandescent: 2700, | ||
daytime: 5500, | ||
soft: 2700, | ||
daylight_white: 5500, | ||
daytime_white: 5500, | ||
white: 4000, | ||
daylight: 5500, | ||
sunset: 2200, | ||
warm: 2200, | ||
evening: 2200, | ||
cool: 7000, | ||
warm_white: 2200, | ||
candlelight: 2200, | ||
relax: 2200, | ||
reading_white: 2700, | ||
reading: 2700, | ||
bright_white: 7000 | ||
}, | ||
// these differ on a device basis... | ||
colorNames: { | ||
blanched_almond: "#ffeacc", | ||
pale_goldenrod: "#ede9aa", | ||
deep_pink: "#ff1491", | ||
cyan: "#00ffff", | ||
light_goldenrod: "#f9f9d1", | ||
pale_green: "#99f999", | ||
medium_blue: "#0000cc", | ||
dark_turquoise: "#00ced1", | ||
hot_pink: "#ff68b6", | ||
dark_olive_green: "#546b2d", | ||
dodger_blue: "#1e8eff", | ||
red: "#ff0000", | ||
goldenrod: "#d8a421", | ||
blue: "#0000ff", | ||
fuchsia: "#ff00ff", | ||
medium_turquoise: "#47d1cc", | ||
light_steel_blue: "#afc4dd", | ||
navajo_white: "#ffddad", | ||
antique_white: "#f9ead6", | ||
cornsilk: "#fff7db", | ||
dark_slate_blue: "#483d8c", | ||
light_pink: "#ffb5c1", | ||
gainsboro: "#dbdbdb", | ||
slate_blue: "#6a59cc", | ||
light_slate_gray: "#778799", | ||
wheat: "#f4ddb2", | ||
plum: "#dda0dd", | ||
dark_magenta: "#8c008c", | ||
peach_puff: "#ffd8ba", | ||
sea_green: "#2d8c56", | ||
blue_violet: "#8a2be2", | ||
burlywood: "#ddb687", | ||
dark_cyan: "#008c8c", | ||
dark_green: "#006300", | ||
rebecca_purple: "#663399", | ||
web_purple: "#7f007f", | ||
pale_turquoise: "#afeded", | ||
olive_drab: "#6a8e23", | ||
dark_red: "#8c0000", | ||
alice_blue: "#eff7ff", | ||
medium_aquamarine: "#66ccaa", | ||
orchid: "#d870d6", | ||
old_lace: "#fcf4e5", | ||
seashell: "#fff4ed", | ||
brown: "#a52828", | ||
dark_gray: "#a8a8a8", | ||
dark_orange: "#ff8c00", | ||
sandy_brown: "#f4a360", | ||
dim_gray: "#686868", | ||
turquoise: "#3fe0d0", | ||
purple: "#a021ef", | ||
tan: "#d1b58c", | ||
pink: "#ffbfcc", | ||
dark_goldenrod: "#b7860a", | ||
misty_rose: "#ffe2e0", | ||
aqua: "#00ffff", | ||
yellow: "#ffff00", | ||
light_gray: "#d3d3d3", | ||
pale_violet_red: "#db7094", | ||
medium_spring_green: "#00f99a", | ||
light_sea_green: "#21b2ab", | ||
forest_green: "#218c21", | ||
moccasin: "#ffe1b5", | ||
web_gray: "#7f7f7f", | ||
deep_sky_blue: "#00bfff", | ||
white_smoke: "#f4f4f4", | ||
gold: "#ffd500", | ||
lime: "#c7ff1f", | ||
olive: "#7f7f00", | ||
web_green: "#007f00", | ||
light_coral: "#ef7f7f", | ||
royal_blue: "#3f67e0", | ||
floral_white: "#fff9ef", | ||
navy_blue: "#00007f", | ||
bisque: "#ffe2c4", | ||
coral: "#ff7e4f", | ||
yellow_green: "#99cc33", | ||
salmon: "#ffa07a", | ||
papaya_whip: "#ffefd6", | ||
light_yellow: "#ffffe0", | ||
medium_sea_green: "#3db270", | ||
steel_blue: "#4482b5", | ||
light_green: "#8eed8e", | ||
firebrick: "#b22121", | ||
midnight_blue: "#191970", | ||
linen: "#f9efe5", | ||
violet: "#ed82ed", | ||
cadet_blue: "#5e9ea0", | ||
light_salmon: "#ffa07a", | ||
spring_green: "#00ff80", | ||
mint_cream: "#f4fff9", | ||
dark_khaki: "#bcb76b", | ||
maroon: "#af3061", | ||
web_maroon: "#7f0000", | ||
dark_sea_green: "#8ebc8e", | ||
crimson: "#db143c", | ||
tomato: "#ff6347", | ||
lawn_green: "#7efc00", | ||
white: "#ffffff", | ||
lavender: "#9f80ff", | ||
green_yellow: "#afff2d", | ||
chocolate: "#d1691e", | ||
lavender_blush: "#ffeff4", | ||
dark_orchid: "#9933cc", | ||
sky_blue: "#87ceea", | ||
magenta: "#ff00ff", | ||
medium_violet_red: "#c61485", | ||
gray: "#bfbfbf", | ||
orange_red: "#ff4400", | ||
silver: "#bfbfbf", | ||
green: "#00ff00", | ||
light_cyan: "#e0ffff", | ||
chartreuse: "#80ff00", | ||
dark_salmon: "#e8967a", | ||
sienna: "#a0512d", | ||
saddle_brown: "#8c4411", | ||
thistle: "#d8bfd8", | ||
lemon_chiffon: "#fff9cc", | ||
light_blue: "#add8e5", | ||
indigo: "#4a0082", | ||
indian_red: "#cc5b5b", | ||
medium_orchid: "#ba54d3", | ||
dark_violet: "#9400d3", | ||
ghost_white: "#f7f7ff", | ||
lime_green: "#33cc33", | ||
medium_purple: "#9470db", | ||
teal: "#007f7f", | ||
beige: "#f4f4db", | ||
peru: "#cc833f", | ||
dark_blue: "#00008c", | ||
light_sky_blue: "#87cdf9", | ||
ivory: "#ffffef", | ||
honeydew: "#efffef", | ||
dark_slate_gray: "#2d4f4f", | ||
orange: "#ffa600", | ||
cornflower: "#6393ed", | ||
slate_gray: "#707f8e", | ||
medium_slate_blue: "#7a68ed", | ||
azure: "#efffff", | ||
powder_blue: "#afe0e5", | ||
snow: "#fff9f9", | ||
aquamarine: "#7fffd2", | ||
khaki: "#efe58c", | ||
black: "#000000", | ||
rosy_brown: "#bc8e8e" | ||
} | ||
}; | ||
|
||
module.exports = knownColorValues; |
Oops, something went wrong.