forked from unityfire/alexa-ha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.js
93 lines (82 loc) · 2.54 KB
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var config = require('./config');
/************** CONFIG HELPER *********************/
// Get itemName from itemType & location
function getItem(itemType, location) {
//Handle variances of itemType for config value lookup
if (itemType === 'lighting' || itemType === 'lights') {
itemType = 'light';
}
//Strip dangling ' room' in utterance for config value lookup
var suffix = ' room';
if (location.substr(-suffix.length) === suffix) {
location = location.replace(' room','');
}
for(var key in config.item) {
if(config.item.hasOwnProperty(itemType)) {
return config.item[itemType][location];
}
}
return false;
}
// Get itemName from metricName & location
function getMetric(metricName, location) {
//Strip dangling ' room' suffix for for config value lookup
var suffix = ' room';
if (location.substr(-suffix.length) === suffix) {
location = location.replace(' room','');
}
for(var key in config.metric) {
if(config.metric.hasOwnProperty(metricName)) {
return config.metric[metricName][location];
}
}
return false;
}
// Get unit from metricName
function getUnit(metricName) {
for(var key in config.unit) {
if(config.unit.hasOwnProperty(metricName)) {
return config.unit[metricName];
}
}
return false;
}
// Get HSB value from colorName
function getColor(colorName) {
for(var key in config.color) {
if(config.color.hasOwnProperty(colorName)) {
return config.color[colorName];
}
}
return false;
}
// Get itemName from modeType & modeName
function getMode(modeType,modeName) {
for(var key in config.mode) {
if(config.mode.hasOwnProperty(modeType)) {
return config.mode[modeType][modeName];
}
}
return false;
}
// Get modeName from modeType & modeId
function getModeName(modeType,modeId) {
for(var key in config.mode[modeType]) {
if (config.mode[modeType][key] === modeId) {
return key;
}
}
return false;
}
function checkLocation(location) {
//console.log('result of checkLocation for ' + location + ' is: ' + config.HA_locations.indexOf(location) > -1);
return config.HA_locations.indexOf(location) > -1;
}
// Exports
module.exports.getItem = getItem;
module.exports.getMetric = getMetric;
module.exports.getUnit = getUnit;
module.exports.getColor = getColor;
module.exports.getMode = getMode;
module.exports.getModeName = getModeName;
module.exports.checkLocation = checkLocation;