node-red-contrib-huemagic 2.8.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +229 -0
- package/README.md +806 -729
- package/examples/Hue Bridge.json +189 -35
- package/examples/Hue Brightness.json +124 -14
- package/examples/Hue Buttons.json +88 -0
- package/examples/Hue Group.json +575 -63
- package/examples/Hue Light.json +805 -58
- package/examples/Hue Magic.json +69 -24
- package/examples/Hue Motion.json +110 -42
- package/examples/Hue Rules.json +105 -37
- package/examples/Hue Scene.json +145 -28
- package/examples/Hue Temperature.json +124 -14
- package/huemagic/animations/001-sunny.json +22 -22
- package/huemagic/animations/002-cloudy.json +46 -46
- package/huemagic/animations/003-nightsky.json +20 -20
- package/huemagic/animations/004-sunrise.json +54 -54
- package/huemagic/animations/005-sunset.json +46 -46
- package/huemagic/animations/006-fireplace.json +74 -74
- package/huemagic/animations/007-spring.json +31 -31
- package/huemagic/animations/008-autmn.json +23 -23
- package/huemagic/animations/009-winter.json +23 -23
- package/huemagic/animations/010-dirtyfog.json +23 -23
- package/huemagic/animations/011-lgbt.json +49 -50
- package/huemagic/animations/012-rasta.json +28 -29
- package/huemagic/animations/013-strobo.json +30 -31
- package/huemagic/animations/014-randomrainbow.json +30 -31
- package/huemagic/animations/015-sos.json +158 -159
- package/huemagic/animations/016-milkyway.json +83 -0
- package/huemagic/animations/017-beach.json +40 -0
- package/huemagic/animations/018-forest.json +43 -0
- package/huemagic/animations/019-christmas.json +30 -0
- package/huemagic/animations/020-superhero.json +56 -0
- package/huemagic/animations/021-neoncity.json +52 -0
- package/huemagic/animations/previews/001-sunny.gif +0 -0
- package/huemagic/animations/previews/002-cloudy.gif +0 -0
- package/huemagic/animations/previews/003-nightsky.gif +0 -0
- package/huemagic/animations/previews/004-sunrise.gif +0 -0
- package/huemagic/animations/previews/005-sunset.gif +0 -0
- package/huemagic/animations/previews/006-fireplace.gif +0 -0
- package/huemagic/animations/previews/007-spring.gif +0 -0
- package/huemagic/animations/previews/008-autmn.gif +0 -0
- package/huemagic/animations/previews/009-winter.gif +0 -0
- package/huemagic/animations/previews/010-dirtyfog.gif +0 -0
- package/huemagic/animations/previews/011-lgbt.gif +0 -0
- package/huemagic/animations/previews/012-rasta.gif +0 -0
- package/huemagic/animations/previews/013-strobo.gif +0 -0
- package/huemagic/animations/previews/014-randomrainbow.gif +0 -0
- package/huemagic/animations/previews/015-sos.gif +0 -0
- package/huemagic/animations/previews/016-milkyway.gif +0 -0
- package/huemagic/animations/previews/017-beach.gif +0 -0
- package/huemagic/animations/previews/018-forest.gif +0 -0
- package/huemagic/animations/previews/019-christmas.gif +0 -0
- package/huemagic/animations/previews/020-superhero.gif +0 -0
- package/huemagic/animations/previews/021-neoncity.gif +0 -0
- package/huemagic/hue-bridge-config.html +105 -61
- package/huemagic/hue-bridge-config.js +629 -319
- package/huemagic/hue-bridge.html +41 -21
- package/huemagic/hue-bridge.js +191 -398
- package/huemagic/hue-brightness.html +130 -49
- package/huemagic/hue-brightness.js +131 -35
- package/huemagic/hue-buttons.html +197 -0
- package/huemagic/hue-buttons.js +152 -0
- package/huemagic/hue-group.html +137 -60
- package/huemagic/hue-group.js +394 -367
- package/huemagic/hue-light.html +133 -59
- package/huemagic/hue-light.js +551 -336
- package/huemagic/hue-magic.html +91 -237
- package/huemagic/hue-magic.js +57 -27
- package/huemagic/hue-motion.html +128 -50
- package/huemagic/hue-motion.js +116 -87
- package/huemagic/hue-rules.html +121 -50
- package/huemagic/hue-rules.js +84 -64
- package/huemagic/hue-scene.html +96 -115
- package/huemagic/hue-scene.js +65 -96
- package/huemagic/hue-temperature.html +130 -49
- package/huemagic/hue-temperature.js +136 -32
- package/huemagic/icons/hue-bridge.png +0 -0
- package/huemagic/icons/hue-bridge.svg +3 -0
- package/huemagic/icons/hue-brightness.png +0 -0
- package/huemagic/icons/hue-brightness.svg +11 -0
- package/huemagic/icons/hue-buttons.png +0 -0
- package/huemagic/icons/hue-buttons.svg +4 -0
- package/huemagic/icons/hue-group.png +0 -0
- package/huemagic/icons/hue-group.svg +12 -0
- package/huemagic/icons/hue-light.png +0 -0
- package/huemagic/icons/hue-light.svg +3 -0
- package/huemagic/icons/hue-magic.png +0 -0
- package/huemagic/icons/hue-magic.svg +3 -0
- package/huemagic/icons/hue-motion.png +0 -0
- package/huemagic/icons/hue-motion.svg +9 -0
- package/huemagic/icons/hue-rules.png +0 -0
- package/huemagic/icons/hue-rules.svg +4 -0
- package/huemagic/icons/hue-scene.png +0 -0
- package/huemagic/icons/hue-scene.svg +5 -0
- package/huemagic/icons/hue-temperature.png +0 -0
- package/huemagic/icons/hue-temperature.svg +7 -0
- package/huemagic/locales/de/hue-bridge-config.html +17 -12
- package/huemagic/locales/de/hue-bridge-config.json +7 -5
- package/huemagic/locales/de/hue-bridge.html +64 -145
- package/huemagic/locales/de/hue-bridge.json +6 -17
- package/huemagic/locales/de/hue-brightness.html +52 -38
- package/huemagic/locales/de/hue-brightness.json +7 -2
- package/huemagic/locales/de/hue-buttons.html +58 -0
- package/huemagic/locales/de/hue-buttons.json +28 -0
- package/huemagic/locales/de/hue-group.html +46 -122
- package/huemagic/locales/de/hue-group.json +4 -2
- package/huemagic/locales/de/hue-light.html +68 -116
- package/huemagic/locales/de/hue-light.json +5 -2
- package/huemagic/locales/de/hue-magic.html +65 -57
- package/huemagic/locales/de/hue-magic.json +2 -1
- package/huemagic/locales/de/hue-motion.html +48 -44
- package/huemagic/locales/de/hue-motion.json +6 -3
- package/huemagic/locales/de/hue-rules.html +68 -73
- package/huemagic/locales/de/hue-rules.json +5 -2
- package/huemagic/locales/de/hue-scene.html +23 -32
- package/huemagic/locales/de/hue-scene.json +5 -2
- package/huemagic/locales/de/hue-temperature.html +53 -36
- package/huemagic/locales/de/hue-temperature.json +7 -2
- package/huemagic/locales/en-US/hue-bridge-config.html +17 -12
- package/huemagic/locales/en-US/hue-bridge-config.json +5 -3
- package/huemagic/locales/en-US/hue-bridge.html +64 -145
- package/huemagic/locales/en-US/hue-bridge.json +5 -16
- package/huemagic/locales/en-US/hue-brightness.html +52 -38
- package/huemagic/locales/en-US/hue-brightness.json +10 -3
- package/huemagic/locales/en-US/hue-buttons.html +58 -0
- package/huemagic/locales/en-US/hue-buttons.json +34 -0
- package/huemagic/locales/en-US/hue-group.html +46 -122
- package/huemagic/locales/en-US/hue-group.json +7 -3
- package/huemagic/locales/en-US/hue-light.html +68 -116
- package/huemagic/locales/en-US/hue-light.json +8 -3
- package/huemagic/locales/en-US/hue-magic.html +65 -57
- package/huemagic/locales/en-US/hue-magic.json +3 -1
- package/huemagic/locales/en-US/hue-motion.html +48 -44
- package/huemagic/locales/en-US/hue-motion.json +9 -4
- package/huemagic/locales/en-US/hue-rules.html +68 -73
- package/huemagic/locales/en-US/hue-rules.json +5 -2
- package/huemagic/locales/en-US/hue-scene.html +23 -32
- package/huemagic/locales/en-US/hue-scene.json +5 -2
- package/huemagic/locales/en-US/hue-temperature.html +53 -36
- package/huemagic/locales/en-US/hue-temperature.json +10 -3
- package/huemagic/utils/api.js +290 -0
- package/huemagic/utils/color.js +382 -0
- package/{utils → huemagic/utils}/merge.js +9 -6
- package/huemagic/utils/messages.js +447 -0
- package/package.json +12 -12
- package/examples/Hue Switch.json +0 -40
- package/examples/Hue Tap.json +0 -40
- package/huemagic/assets/anime.js +0 -8
- package/huemagic/hue-switch.html +0 -119
- package/huemagic/hue-switch.js +0 -113
- package/huemagic/hue-tap.html +0 -119
- package/huemagic/hue-tap.js +0 -74
- package/huemagic/icons/hue-button.png +0 -0
- package/huemagic/icons/hue-switch.png +0 -0
- package/huemagic/icons/hue-tap.png +0 -0
- package/huemagic/locales/de/hue-switch.html +0 -50
- package/huemagic/locales/de/hue-switch.json +0 -31
- package/huemagic/locales/de/hue-tap.html +0 -41
- package/huemagic/locales/de/hue-tap.json +0 -23
- package/huemagic/locales/en-US/hue-switch.html +0 -50
- package/huemagic/locales/en-US/hue-switch.json +0 -31
- package/huemagic/locales/en-US/hue-tap.html +0 -41
- package/huemagic/locales/en-US/hue-tap.json +0 -23
- package/utils/messages.js +0 -571
- package/utils/rgb.js +0 -188
package/huemagic/hue-scene.html
CHANGED
|
@@ -1,39 +1,23 @@
|
|
|
1
1
|
<script type="text/x-red" data-template-name="hue-scene">
|
|
2
2
|
<div class="form-row">
|
|
3
3
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="hue-scene.config.name"></span></label>
|
|
4
|
-
<input type="text" id="node-input-name" data-i18n="[placeholder]hue-scene.config.input-name">
|
|
4
|
+
<input type="text" id="node-input-name" data-i18n="[placeholder]hue-scene.config.input-name" style="width: calc(100% - 105px)">
|
|
5
5
|
</div>
|
|
6
6
|
<div class="form-row">
|
|
7
7
|
<label for="node-input-bridge"><i class="fa fa-server"></i> Bridge</label>
|
|
8
|
-
<input type="text" id="node-input-bridge">
|
|
8
|
+
<input type="text" id="node-input-bridge" style="width: calc(100% - 105px)">
|
|
9
9
|
</div>
|
|
10
10
|
<div class="form-row">
|
|
11
|
-
<label for="node-input-sceneid"><i class="fa fa-eye"></i>
|
|
12
|
-
<div style="display: inline-
|
|
13
|
-
<div style="
|
|
14
|
-
<input type="text" id="node-input-sceneid" placeholder="
|
|
11
|
+
<label for="node-input-sceneid"><i class="fa fa-eye"></i> <span data-i18n="hue-scene.config.scene"></span></label>
|
|
12
|
+
<div style="display: inline-flex; width: calc(100% - 105px)">
|
|
13
|
+
<div id="input-scene-select-toggle" style="flex-grow: 1;">
|
|
14
|
+
<input type="text" id="node-input-sceneid" placeholder="00000000-0000-0000-0000-000000000000" style="width: 100%"/>
|
|
15
15
|
</div>
|
|
16
|
-
<
|
|
16
|
+
<button id="node-config-input-scan-scenes" type="button" class="red-ui-button" style="margin-left: 10px;">
|
|
17
17
|
<i class="fa fa-search"></i>
|
|
18
|
-
</
|
|
18
|
+
</button>
|
|
19
19
|
</div>
|
|
20
20
|
</div>
|
|
21
|
-
<div class="form-row">
|
|
22
|
-
<label for="node-input-groupid"><i class="fa fa-lightbulb-o"></i> <span data-i18n="hue-scene.config.group"></span></label>
|
|
23
|
-
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
|
|
24
|
-
<div style="position: absolute; left: 0px; right: 40px;">
|
|
25
|
-
<input type="text" id="node-input-groupid" placeholder="1" style="width: 100%"/>
|
|
26
|
-
</div>
|
|
27
|
-
<a id="node-config-input-scan-groups" class="editor-button" style="position: absolute; right: 0px; top: 0px;">
|
|
28
|
-
<i class="fa fa-search"></i>
|
|
29
|
-
</a>
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
<div class="form-row">
|
|
33
|
-
<label for="node-input-skipevents"><i class="fa fa-sign-out"></i> <span data-i18n="hue-scene.config.skipevents"></span></label>
|
|
34
|
-
<input type="checkbox" id="node-input-skipevents" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="hue-scene.config.skipevents-node"></span>
|
|
35
|
-
</label>
|
|
36
|
-
</div>
|
|
37
21
|
</script>
|
|
38
22
|
|
|
39
23
|
<script type="text/javascript">
|
|
@@ -41,149 +25,146 @@
|
|
|
41
25
|
category: 'HueMagic',
|
|
42
26
|
color: '#ff823a',
|
|
43
27
|
defaults: {
|
|
44
|
-
name: {value:""},
|
|
45
|
-
bridge: {type: "hue-bridge", required: true},
|
|
46
|
-
sceneid: {value: null}
|
|
47
|
-
groupid: {value:"", required: false, validate: function(id) {
|
|
48
|
-
if(id.length < 1) { return true; }
|
|
49
|
-
else if(!isNaN(id)) { return true; }
|
|
50
|
-
else { return false; }
|
|
51
|
-
}},
|
|
52
|
-
skipevents: {value: false}
|
|
28
|
+
name: { value:"" },
|
|
29
|
+
bridge: { type: "hue-bridge", required: true },
|
|
30
|
+
sceneid: { value: null }
|
|
53
31
|
},
|
|
32
|
+
align: 'left',
|
|
33
|
+
icon: "hue-scene.png",
|
|
54
34
|
inputs: 1,
|
|
55
35
|
outputs: 1,
|
|
36
|
+
label: function() {
|
|
37
|
+
return this.name || this._("hue-scene.node.title");
|
|
38
|
+
},
|
|
39
|
+
paletteLabel: function() {
|
|
40
|
+
return this._("hue-scene.node.title");
|
|
41
|
+
},
|
|
56
42
|
inputLabels: function() {
|
|
57
43
|
return this._("hue-scene.node.input");
|
|
58
44
|
},
|
|
59
45
|
outputLabels: function() {
|
|
60
46
|
return this._("hue-scene.node.output");
|
|
61
47
|
},
|
|
62
|
-
align: 'right',
|
|
63
|
-
icon: "hue-scene.png",
|
|
64
|
-
paletteLabel: function() {
|
|
65
|
-
return this._("hue-scene.node.title");
|
|
66
|
-
},
|
|
67
|
-
label: function() {
|
|
68
|
-
return this.name || this._("hue-scene.node.title");
|
|
69
|
-
},
|
|
70
48
|
oneditprepare: function()
|
|
71
49
|
{
|
|
72
|
-
|
|
50
|
+
const scope = this;
|
|
51
|
+
let sceneOptions = [];
|
|
73
52
|
|
|
74
53
|
function manualSceneID()
|
|
75
54
|
{
|
|
55
|
+
// GET CURRENT SELECTED VALUE
|
|
76
56
|
var current = $('#node-input-sceneid').val();
|
|
77
|
-
$('#node-input-sceneid').replaceWith('<input type="text" id="node-input-sceneid" style="width: 100%"/>');
|
|
78
|
-
$('#node-input-sceneid').val(current);
|
|
79
|
-
}
|
|
80
57
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
$('#
|
|
58
|
+
// REMOVE SELECT FIELD
|
|
59
|
+
$('#input-scene-select-toggle').empty();
|
|
60
|
+
|
|
61
|
+
// CREATE NEW INPUT FIELD
|
|
62
|
+
$('#input-scene-select-toggle').append('<input type="text" id="node-input-sceneid" placeholder="00000000-0000-0000-0000-000000000000" style="width: 100%" value="'+current+'" />');
|
|
63
|
+
|
|
64
|
+
// CHANGE BUTTON ICON
|
|
65
|
+
var button = $("#node-config-input-scan-scenes");
|
|
66
|
+
var buttonIcon = button.find("i");
|
|
67
|
+
buttonIcon.removeClass("fa-pencil");
|
|
68
|
+
buttonIcon.addClass("fa-search");
|
|
86
69
|
}
|
|
87
70
|
|
|
88
71
|
function searchAndSelectScenes()
|
|
89
72
|
{
|
|
73
|
+
// GET CURRENT BRIDGE CONFIGURATION
|
|
74
|
+
var bridgeConfig = RED.nodes.node($('#node-input-bridge option:selected').val());
|
|
75
|
+
if(!bridgeConfig) { return false; }
|
|
76
|
+
|
|
77
|
+
// GET CURRENT SELECTED VALUE
|
|
90
78
|
var current = $('#node-input-sceneid').val();
|
|
91
|
-
$('#node-input-sceneid').replaceWith('<select id="node-input-sceneid" style="width: 100%"></select>');
|
|
92
|
-
$('#node-input-sceneid').append('<option selected="selected" value="null">'+scope._("hue-scene.config.searching")+'</option>');
|
|
93
79
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
.done(function(data) {
|
|
97
|
-
var scenes = JSON.parse(data);
|
|
80
|
+
// TRIGGER SEARCHING NOTIFICATION
|
|
81
|
+
var notification = RED.notify(scope._("hue-rules.config.searching"), { type: "compact", modal: true, fixed: true });
|
|
98
82
|
|
|
99
|
-
|
|
83
|
+
// GET THE SCENES
|
|
84
|
+
$.get('hue/ressources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "scene" })
|
|
85
|
+
.done( function(data) {
|
|
86
|
+
var allRessources = JSON.parse(data);
|
|
87
|
+
if(allRessources.length <= 0)
|
|
100
88
|
{
|
|
101
|
-
|
|
89
|
+
notification.close();
|
|
90
|
+
RED.notify(scope._("hue-scene.config.none-found"), { type: "error" });
|
|
91
|
+
return false;
|
|
102
92
|
}
|
|
103
93
|
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// SET MOTION SENSORS AS OPTIONS
|
|
108
|
-
scenes.forEach(function(scene)
|
|
94
|
+
// SET OPTIONS
|
|
95
|
+
allRessources.forEach(function(ressource)
|
|
109
96
|
{
|
|
110
|
-
|
|
97
|
+
sceneOptions[ressource.id] = { value: ressource.id, label: ressource.name + " ("+ressource.group+")" };
|
|
111
98
|
});
|
|
112
99
|
|
|
113
100
|
// SELECT CURRENT VALUE
|
|
114
|
-
$(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
function searchAndSelectGroupID()
|
|
123
|
-
{
|
|
124
|
-
var current = $('#node-input-groupid').val();
|
|
125
|
-
$('#node-input-groupid').replaceWith('<select id="node-input-groupid" style="width: 100%"></select>');
|
|
126
|
-
$('#node-input-groupid').append('<option selected="selected" value="null">'+scope._("hue-scene.config.group-searching")+'</option>');
|
|
127
|
-
|
|
128
|
-
var bridgeConfig = RED.nodes.node($('#node-input-bridge option:selected').val());
|
|
129
|
-
$.get('hue/groups', {bridge: bridgeConfig.bridge, key: bridgeConfig.key})
|
|
130
|
-
.done(function(data) {
|
|
131
|
-
var groups = JSON.parse(data);
|
|
132
|
-
|
|
133
|
-
if(groups.length <= 0)
|
|
134
|
-
{
|
|
135
|
-
RED.notify(scope._("hue-scene.config.group-none-found"), "error");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// RESET OPTIONS
|
|
139
|
-
$('#node-input-groupid').empty();
|
|
140
|
-
|
|
141
|
-
// SET GROUPS AS OPTIONS
|
|
142
|
-
$('#node-input-groupid').append('<option value="0">'+scope._("hue-scene.config.groups-all")+'</option>');
|
|
143
|
-
groups.forEach(function(group)
|
|
144
|
-
{
|
|
145
|
-
$('#node-input-groupid').append('<option value="' + group.id + '">' + group.name + '</option>');
|
|
101
|
+
$("#node-input-sceneid").typedInput({
|
|
102
|
+
types: [
|
|
103
|
+
{
|
|
104
|
+
value: current,
|
|
105
|
+
options: Object.values(sceneOptions)
|
|
106
|
+
}
|
|
107
|
+
]
|
|
146
108
|
});
|
|
147
109
|
|
|
148
|
-
//
|
|
149
|
-
$(
|
|
110
|
+
// CHANGE BUTTON ICON
|
|
111
|
+
var button = $("#node-config-input-scan-scenes");
|
|
112
|
+
var buttonIcon = button.find("i");
|
|
113
|
+
buttonIcon.removeClass("fa-search");
|
|
114
|
+
buttonIcon.addClass("fa-pencil");
|
|
115
|
+
|
|
116
|
+
// CLOSE SEARCH NOTIFICATION
|
|
117
|
+
notification.close();
|
|
150
118
|
})
|
|
151
119
|
.fail(function()
|
|
152
120
|
{
|
|
121
|
+
notification.close();
|
|
153
122
|
RED.notify(scope._("hue-scene.config.unknown-error"), "error");
|
|
154
123
|
});
|
|
155
124
|
}
|
|
156
125
|
|
|
157
|
-
|
|
158
|
-
$(document).on('change', '#node-input-sceneid', function()
|
|
126
|
+
// CHANGED SCENE ID? -> REPLACE NAME (IF POSSIBLE)
|
|
127
|
+
$(document).on('change', '#node-input-sceneid', function(e)
|
|
159
128
|
{
|
|
160
|
-
|
|
161
|
-
|
|
129
|
+
let currentSelectedOptionID = $(e.currentTarget).val();
|
|
130
|
+
let currentSelectedOptionValue = (currentSelectedOptionID.length > 0 && sceneOptions[currentSelectedOptionID]) ? sceneOptions[currentSelectedOptionID].label : false;
|
|
131
|
+
|
|
132
|
+
if(currentSelectedOptionValue !== false)
|
|
162
133
|
{
|
|
163
|
-
$('#node-input-name').val(
|
|
134
|
+
$('#node-input-name').val(currentSelectedOptionValue.split(" (")[0]);
|
|
164
135
|
}
|
|
165
136
|
});
|
|
166
137
|
|
|
167
|
-
//
|
|
138
|
+
// TOGGLE SELECT/INPUT FIELD
|
|
168
139
|
$('#node-config-input-scan-scenes').click(function()
|
|
169
140
|
{
|
|
170
|
-
if($('#
|
|
141
|
+
if($('#input-scene-select-toggle').find(".red-ui-typedInput-container").length > 0)
|
|
171
142
|
{
|
|
172
|
-
searchAndSelectScenes();
|
|
173
|
-
} else {
|
|
174
143
|
manualSceneID();
|
|
175
144
|
}
|
|
145
|
+
else
|
|
146
|
+
{
|
|
147
|
+
searchAndSelectScenes();
|
|
148
|
+
}
|
|
176
149
|
});
|
|
177
|
-
|
|
178
|
-
|
|
150
|
+
},
|
|
151
|
+
button: {
|
|
152
|
+
onclick: function()
|
|
179
153
|
{
|
|
180
|
-
|
|
154
|
+
const node = this;
|
|
155
|
+
if(node.bridge)
|
|
181
156
|
{
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
157
|
+
$.ajax({
|
|
158
|
+
url: "inject/" + node.id,
|
|
159
|
+
type: "POST",
|
|
160
|
+
data: JSON.stringify({ __user_inject_props__: "status"}),
|
|
161
|
+
contentType: "application/json; charset=utf-8",
|
|
162
|
+
success: function (resp) {
|
|
163
|
+
RED.notify(node.name + ": " + node._("hue-scene.node.statusmsg"), { type: "success", id: "status", timeout: 2000 });
|
|
164
|
+
}
|
|
165
|
+
});
|
|
185
166
|
}
|
|
186
|
-
}
|
|
167
|
+
}
|
|
187
168
|
}
|
|
188
169
|
});
|
|
189
|
-
</script>
|
|
170
|
+
</script>
|
package/huemagic/hue-scene.js
CHANGED
|
@@ -6,9 +6,19 @@ module.exports = function(RED)
|
|
|
6
6
|
{
|
|
7
7
|
RED.nodes.createNode(this, config);
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const scope = this;
|
|
10
|
+
const bridge = RED.nodes.getNode(config.bridge);
|
|
11
|
+
|
|
12
|
+
// GET TARGET WIRED GROUPS
|
|
13
|
+
this.targetGroups = {};
|
|
14
|
+
for (var w = scope.wires[0].length - 1; w >= 0; w--)
|
|
15
|
+
{
|
|
16
|
+
let oneWiredNode = RED.nodes.getNode(scope.wires[0][w]);
|
|
17
|
+
if(oneWiredNode && oneWiredNode.type == "hue-group" && oneWiredNode.exportedConfig && oneWiredNode.exportedConfig.groupid && oneWiredNode.exportedConfig.groupid.length > 1)
|
|
18
|
+
{
|
|
19
|
+
this.targetGroups[oneWiredNode.exportedConfig.groupid] = true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
12
22
|
|
|
13
23
|
//
|
|
14
24
|
// CHECK CONFIG
|
|
@@ -22,123 +32,82 @@ module.exports = function(RED)
|
|
|
22
32
|
// ENABLE SCENE
|
|
23
33
|
this.on('input', function(msg, send, done)
|
|
24
34
|
{
|
|
25
|
-
//
|
|
26
|
-
|
|
35
|
+
// REDEFINE SEND AND DONE IF NOT AVAILABLE
|
|
36
|
+
done = done || function() { scope.done.apply(scope,arguments); }
|
|
27
37
|
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
// TARGET GROUP & SCENE
|
|
39
|
+
const groupIDS = (typeof msg.payload != 'undefined' && typeof msg.payload.group != 'undefined') ? msg.payload.group : [];
|
|
40
|
+
const sceneDef = (typeof msg.payload != 'undefined' && typeof msg.payload.scene != 'undefined') ? msg.payload.scene : config.sceneid;
|
|
30
41
|
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
else
|
|
37
|
-
{
|
|
38
|
-
groupID = (typeof msg.payload != 'undefined' && typeof msg.payload.group != 'undefined') ? msg.payload.group : groupID;
|
|
39
|
-
sceneDef = (typeof msg.payload != 'undefined' && typeof msg.payload.scene != 'undefined') ? msg.payload.scene : sceneDef;
|
|
40
|
-
}
|
|
42
|
+
// PREPARE TARGET GROUPS
|
|
43
|
+
let copyOfTargetGroups = Object.keys(scope.targetGroups);
|
|
44
|
+
if(typeof groupIDS == 'string') { copyOfTargetGroups.push(groupIDS); }
|
|
45
|
+
else if(typeof groupIDS == 'object') { copyOfTargetGroups.concat(groupIDS); }
|
|
46
|
+
else { return false; }
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
else if(sceneDef)
|
|
50
|
-
{
|
|
51
|
-
bridge.client.scenes.getAll()
|
|
52
|
-
.then(scenes => {
|
|
53
|
-
for (var scene of scenes)
|
|
54
|
-
{
|
|
55
|
-
if(scene.id == sceneDef)
|
|
56
|
-
{
|
|
57
|
-
scope.proceedSceneAction(scene, groupID, send, done);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
else if(scene.name == sceneDef)
|
|
61
|
-
{
|
|
62
|
-
scope.proceedSceneAction(scene, groupID, send, done);
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
else
|
|
48
|
+
// CREATE PATCH
|
|
49
|
+
let patchObject = {};
|
|
50
|
+
|
|
51
|
+
// NO SCENE?
|
|
52
|
+
if(!sceneDef)
|
|
69
53
|
{
|
|
70
54
|
// ERROR
|
|
71
55
|
this.status({fill: "red", shape: "ring", text: "hue-scene.node.no-id"});
|
|
56
|
+
scope.error("Scene ID not found");
|
|
57
|
+
return false;
|
|
72
58
|
}
|
|
73
|
-
});
|
|
74
59
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// PROCEED SCENE ACTION
|
|
78
|
-
this.proceedSceneAction = function(scene, applyOnGroup = false, send, done)
|
|
79
|
-
{
|
|
80
|
-
// CHECK IF SCENE SHOULD BE APPLIED TO A GROUP
|
|
81
|
-
if(applyOnGroup)
|
|
60
|
+
// RECALL ON GROUP? -> USE API v1
|
|
61
|
+
if(copyOfTargetGroups.length > 0)
|
|
82
62
|
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
91
|
-
.then(groupInfo =>
|
|
63
|
+
let targetSceneID = bridge.ressources[sceneDef].id_v1.replace("/scenes/", "");
|
|
64
|
+
|
|
65
|
+
// SEND STATUS
|
|
66
|
+
scope.status({fill: "blue", shape: "dot", text: "hue-scene.node.recalled-on-group"})
|
|
67
|
+
|
|
68
|
+
// FIND GROUP AND RECALL SCENE
|
|
69
|
+
for (var g = copyOfTargetGroups.length - 1; g >= 0; g--)
|
|
92
70
|
{
|
|
93
|
-
|
|
94
|
-
scope.status({fill: "blue", shape: "dot", text: "hue-scene.node.recalled-on-group"});
|
|
71
|
+
let targetGroup = bridge.get("group", copyOfTargetGroups[g]);
|
|
95
72
|
|
|
96
|
-
|
|
97
|
-
if(!config.skipevents)
|
|
73
|
+
if(targetGroup)
|
|
98
74
|
{
|
|
99
|
-
|
|
100
|
-
|
|
75
|
+
bridge.patch("group", targetGroup.info.idV1 + "/action", { "scene": targetSceneID }, 1)
|
|
76
|
+
.catch(function(errors) {
|
|
77
|
+
scope.error(errors);
|
|
78
|
+
});
|
|
101
79
|
}
|
|
102
|
-
|
|
80
|
+
}
|
|
103
81
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
109
|
-
.catch(error => {
|
|
110
|
-
scope.error(error, msg);
|
|
111
|
-
if(done) { done(error); }
|
|
112
|
-
});
|
|
82
|
+
// RESET STATUS AFTER 2 SECONDS
|
|
83
|
+
setTimeout(function() {
|
|
84
|
+
scope.status({});
|
|
85
|
+
}, 2000);
|
|
113
86
|
}
|
|
114
87
|
else
|
|
115
88
|
{
|
|
116
|
-
// RECALL
|
|
117
|
-
|
|
118
|
-
.then(recalledScene => {
|
|
119
|
-
// SEND STATUS
|
|
120
|
-
scope.status({fill: "blue", shape: "dot", text: "hue-scene.node.recalled"});
|
|
89
|
+
// RECALL SCENE
|
|
90
|
+
patchObject["recall"] = { status: "active" };
|
|
121
91
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
92
|
+
// CHANGE NODE UI STATE
|
|
93
|
+
scope.status({fill: "grey", shape: "ring", text: "hue-scene.node.command"});
|
|
94
|
+
|
|
95
|
+
// PATCH!
|
|
96
|
+
bridge.patch("scene", sceneDef, patchObject)
|
|
97
|
+
.then(function()
|
|
98
|
+
{
|
|
99
|
+
scope.status({fill: "blue", shape: "dot", text: "hue-scene.node.recalled"});
|
|
128
100
|
if(done) { done(); }
|
|
129
101
|
|
|
130
|
-
// RESET STATUS AFTER
|
|
102
|
+
// RESET STATUS AFTER 1 SECOND
|
|
131
103
|
setTimeout(function() {
|
|
132
104
|
scope.status({});
|
|
133
|
-
},
|
|
105
|
+
}, 1000);
|
|
134
106
|
})
|
|
135
|
-
.catch(
|
|
136
|
-
scope.error(error, msg);
|
|
137
|
-
if(done) { done(error); }
|
|
138
|
-
});
|
|
107
|
+
.catch(function(errors) { scope.error(errors); });
|
|
139
108
|
}
|
|
140
|
-
}
|
|
109
|
+
});
|
|
141
110
|
}
|
|
142
111
|
|
|
143
112
|
RED.nodes.registerType("hue-scene", HueScene);
|
|
144
|
-
}
|
|
113
|
+
}
|