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.
Files changed (165) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +806 -729
  3. package/examples/Hue Bridge.json +189 -35
  4. package/examples/Hue Brightness.json +124 -14
  5. package/examples/Hue Buttons.json +88 -0
  6. package/examples/Hue Group.json +575 -63
  7. package/examples/Hue Light.json +805 -58
  8. package/examples/Hue Magic.json +69 -24
  9. package/examples/Hue Motion.json +110 -42
  10. package/examples/Hue Rules.json +105 -37
  11. package/examples/Hue Scene.json +145 -28
  12. package/examples/Hue Temperature.json +124 -14
  13. package/huemagic/animations/001-sunny.json +22 -22
  14. package/huemagic/animations/002-cloudy.json +46 -46
  15. package/huemagic/animations/003-nightsky.json +20 -20
  16. package/huemagic/animations/004-sunrise.json +54 -54
  17. package/huemagic/animations/005-sunset.json +46 -46
  18. package/huemagic/animations/006-fireplace.json +74 -74
  19. package/huemagic/animations/007-spring.json +31 -31
  20. package/huemagic/animations/008-autmn.json +23 -23
  21. package/huemagic/animations/009-winter.json +23 -23
  22. package/huemagic/animations/010-dirtyfog.json +23 -23
  23. package/huemagic/animations/011-lgbt.json +49 -50
  24. package/huemagic/animations/012-rasta.json +28 -29
  25. package/huemagic/animations/013-strobo.json +30 -31
  26. package/huemagic/animations/014-randomrainbow.json +30 -31
  27. package/huemagic/animations/015-sos.json +158 -159
  28. package/huemagic/animations/016-milkyway.json +83 -0
  29. package/huemagic/animations/017-beach.json +40 -0
  30. package/huemagic/animations/018-forest.json +43 -0
  31. package/huemagic/animations/019-christmas.json +30 -0
  32. package/huemagic/animations/020-superhero.json +56 -0
  33. package/huemagic/animations/021-neoncity.json +52 -0
  34. package/huemagic/animations/previews/001-sunny.gif +0 -0
  35. package/huemagic/animations/previews/002-cloudy.gif +0 -0
  36. package/huemagic/animations/previews/003-nightsky.gif +0 -0
  37. package/huemagic/animations/previews/004-sunrise.gif +0 -0
  38. package/huemagic/animations/previews/005-sunset.gif +0 -0
  39. package/huemagic/animations/previews/006-fireplace.gif +0 -0
  40. package/huemagic/animations/previews/007-spring.gif +0 -0
  41. package/huemagic/animations/previews/008-autmn.gif +0 -0
  42. package/huemagic/animations/previews/009-winter.gif +0 -0
  43. package/huemagic/animations/previews/010-dirtyfog.gif +0 -0
  44. package/huemagic/animations/previews/011-lgbt.gif +0 -0
  45. package/huemagic/animations/previews/012-rasta.gif +0 -0
  46. package/huemagic/animations/previews/013-strobo.gif +0 -0
  47. package/huemagic/animations/previews/014-randomrainbow.gif +0 -0
  48. package/huemagic/animations/previews/015-sos.gif +0 -0
  49. package/huemagic/animations/previews/016-milkyway.gif +0 -0
  50. package/huemagic/animations/previews/017-beach.gif +0 -0
  51. package/huemagic/animations/previews/018-forest.gif +0 -0
  52. package/huemagic/animations/previews/019-christmas.gif +0 -0
  53. package/huemagic/animations/previews/020-superhero.gif +0 -0
  54. package/huemagic/animations/previews/021-neoncity.gif +0 -0
  55. package/huemagic/hue-bridge-config.html +105 -61
  56. package/huemagic/hue-bridge-config.js +629 -319
  57. package/huemagic/hue-bridge.html +41 -21
  58. package/huemagic/hue-bridge.js +191 -398
  59. package/huemagic/hue-brightness.html +130 -49
  60. package/huemagic/hue-brightness.js +131 -35
  61. package/huemagic/hue-buttons.html +197 -0
  62. package/huemagic/hue-buttons.js +152 -0
  63. package/huemagic/hue-group.html +137 -60
  64. package/huemagic/hue-group.js +394 -367
  65. package/huemagic/hue-light.html +133 -59
  66. package/huemagic/hue-light.js +551 -336
  67. package/huemagic/hue-magic.html +91 -237
  68. package/huemagic/hue-magic.js +57 -27
  69. package/huemagic/hue-motion.html +128 -50
  70. package/huemagic/hue-motion.js +116 -87
  71. package/huemagic/hue-rules.html +121 -50
  72. package/huemagic/hue-rules.js +84 -64
  73. package/huemagic/hue-scene.html +96 -115
  74. package/huemagic/hue-scene.js +65 -96
  75. package/huemagic/hue-temperature.html +130 -49
  76. package/huemagic/hue-temperature.js +136 -32
  77. package/huemagic/icons/hue-bridge.png +0 -0
  78. package/huemagic/icons/hue-bridge.svg +3 -0
  79. package/huemagic/icons/hue-brightness.png +0 -0
  80. package/huemagic/icons/hue-brightness.svg +11 -0
  81. package/huemagic/icons/hue-buttons.png +0 -0
  82. package/huemagic/icons/hue-buttons.svg +4 -0
  83. package/huemagic/icons/hue-group.png +0 -0
  84. package/huemagic/icons/hue-group.svg +12 -0
  85. package/huemagic/icons/hue-light.png +0 -0
  86. package/huemagic/icons/hue-light.svg +3 -0
  87. package/huemagic/icons/hue-magic.png +0 -0
  88. package/huemagic/icons/hue-magic.svg +3 -0
  89. package/huemagic/icons/hue-motion.png +0 -0
  90. package/huemagic/icons/hue-motion.svg +9 -0
  91. package/huemagic/icons/hue-rules.png +0 -0
  92. package/huemagic/icons/hue-rules.svg +4 -0
  93. package/huemagic/icons/hue-scene.png +0 -0
  94. package/huemagic/icons/hue-scene.svg +5 -0
  95. package/huemagic/icons/hue-temperature.png +0 -0
  96. package/huemagic/icons/hue-temperature.svg +7 -0
  97. package/huemagic/locales/de/hue-bridge-config.html +17 -12
  98. package/huemagic/locales/de/hue-bridge-config.json +7 -5
  99. package/huemagic/locales/de/hue-bridge.html +64 -145
  100. package/huemagic/locales/de/hue-bridge.json +6 -17
  101. package/huemagic/locales/de/hue-brightness.html +52 -38
  102. package/huemagic/locales/de/hue-brightness.json +7 -2
  103. package/huemagic/locales/de/hue-buttons.html +58 -0
  104. package/huemagic/locales/de/hue-buttons.json +28 -0
  105. package/huemagic/locales/de/hue-group.html +46 -122
  106. package/huemagic/locales/de/hue-group.json +4 -2
  107. package/huemagic/locales/de/hue-light.html +68 -116
  108. package/huemagic/locales/de/hue-light.json +5 -2
  109. package/huemagic/locales/de/hue-magic.html +65 -57
  110. package/huemagic/locales/de/hue-magic.json +2 -1
  111. package/huemagic/locales/de/hue-motion.html +48 -44
  112. package/huemagic/locales/de/hue-motion.json +6 -3
  113. package/huemagic/locales/de/hue-rules.html +68 -73
  114. package/huemagic/locales/de/hue-rules.json +5 -2
  115. package/huemagic/locales/de/hue-scene.html +23 -32
  116. package/huemagic/locales/de/hue-scene.json +5 -2
  117. package/huemagic/locales/de/hue-temperature.html +53 -36
  118. package/huemagic/locales/de/hue-temperature.json +7 -2
  119. package/huemagic/locales/en-US/hue-bridge-config.html +17 -12
  120. package/huemagic/locales/en-US/hue-bridge-config.json +5 -3
  121. package/huemagic/locales/en-US/hue-bridge.html +64 -145
  122. package/huemagic/locales/en-US/hue-bridge.json +5 -16
  123. package/huemagic/locales/en-US/hue-brightness.html +52 -38
  124. package/huemagic/locales/en-US/hue-brightness.json +10 -3
  125. package/huemagic/locales/en-US/hue-buttons.html +58 -0
  126. package/huemagic/locales/en-US/hue-buttons.json +34 -0
  127. package/huemagic/locales/en-US/hue-group.html +46 -122
  128. package/huemagic/locales/en-US/hue-group.json +7 -3
  129. package/huemagic/locales/en-US/hue-light.html +68 -116
  130. package/huemagic/locales/en-US/hue-light.json +8 -3
  131. package/huemagic/locales/en-US/hue-magic.html +65 -57
  132. package/huemagic/locales/en-US/hue-magic.json +3 -1
  133. package/huemagic/locales/en-US/hue-motion.html +48 -44
  134. package/huemagic/locales/en-US/hue-motion.json +9 -4
  135. package/huemagic/locales/en-US/hue-rules.html +68 -73
  136. package/huemagic/locales/en-US/hue-rules.json +5 -2
  137. package/huemagic/locales/en-US/hue-scene.html +23 -32
  138. package/huemagic/locales/en-US/hue-scene.json +5 -2
  139. package/huemagic/locales/en-US/hue-temperature.html +53 -36
  140. package/huemagic/locales/en-US/hue-temperature.json +10 -3
  141. package/huemagic/utils/api.js +290 -0
  142. package/huemagic/utils/color.js +382 -0
  143. package/{utils → huemagic/utils}/merge.js +9 -6
  144. package/huemagic/utils/messages.js +447 -0
  145. package/package.json +12 -12
  146. package/examples/Hue Switch.json +0 -40
  147. package/examples/Hue Tap.json +0 -40
  148. package/huemagic/assets/anime.js +0 -8
  149. package/huemagic/hue-switch.html +0 -119
  150. package/huemagic/hue-switch.js +0 -113
  151. package/huemagic/hue-tap.html +0 -119
  152. package/huemagic/hue-tap.js +0 -74
  153. package/huemagic/icons/hue-button.png +0 -0
  154. package/huemagic/icons/hue-switch.png +0 -0
  155. package/huemagic/icons/hue-tap.png +0 -0
  156. package/huemagic/locales/de/hue-switch.html +0 -50
  157. package/huemagic/locales/de/hue-switch.json +0 -31
  158. package/huemagic/locales/de/hue-tap.html +0 -41
  159. package/huemagic/locales/de/hue-tap.json +0 -23
  160. package/huemagic/locales/en-US/hue-switch.html +0 -50
  161. package/huemagic/locales/en-US/hue-switch.json +0 -31
  162. package/huemagic/locales/en-US/hue-tap.html +0 -41
  163. package/huemagic/locales/en-US/hue-tap.json +0 -23
  164. package/utils/messages.js +0 -571
  165. package/utils/rgb.js +0 -188
@@ -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> Scene</label>
12
- <div style="display: inline-block; position: relative; width: 70%; height: 20px;">
13
- <div style="position: absolute; left: 0px; right: 40px;">
14
- <input type="text" id="node-input-sceneid" placeholder="1" style="width: 100%"/>
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
- <a id="node-config-input-scan-scenes" class="editor-button" style="position: absolute; right: 0px; top: 0px;">
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
- </a>
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
- var scope = this;
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
- function manualGroupID()
82
- {
83
- var current = $('#node-input-groupid').val();
84
- $('#node-input-groupid').replaceWith('<input type="text" id="node-input-groupid" style="width: 100%"/>');
85
- $('#node-input-groupid').val(current);
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
- var bridgeConfig = RED.nodes.node($('#node-input-bridge option:selected').val());
95
- $.get('hue/scenes', {bridge: bridgeConfig.bridge, key: bridgeConfig.key})
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
- if(scenes.length <= 0)
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
- RED.notify(scope._("hue-scene.config.none-found"), "error");
89
+ notification.close();
90
+ RED.notify(scope._("hue-scene.config.none-found"), { type: "error" });
91
+ return false;
102
92
  }
103
93
 
104
- // RESET OPTIONS
105
- $('#node-input-sceneid').empty();
106
-
107
- // SET MOTION SENSORS AS OPTIONS
108
- scenes.forEach(function(scene)
94
+ // SET OPTIONS
95
+ allRessources.forEach(function(ressource)
109
96
  {
110
- $('#node-input-sceneid').append('<option value="' + scene.id + '">' + scene.name + '</option>');
97
+ sceneOptions[ressource.id] = { value: ressource.id, label: ressource.name + " ("+ressource.group+")" };
111
98
  });
112
99
 
113
100
  // SELECT CURRENT VALUE
114
- $('#node-input-sceneid').val(current);
115
- })
116
- .fail(function()
117
- {
118
- RED.notify(scope._("hue-scene.config.unknown-error"), "error");
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
- // SELECT CURRENT VALUE
149
- $('#node-input-groupid').val(current);
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
- var sceneName = $('#node-input-sceneid option:selected').text();
161
- if(sceneName.length > 0)
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(sceneName);
134
+ $('#node-input-name').val(currentSelectedOptionValue.split(" (")[0]);
164
135
  }
165
136
  });
166
137
 
167
- // SCAN
138
+ // TOGGLE SELECT/INPUT FIELD
168
139
  $('#node-config-input-scan-scenes').click(function()
169
140
  {
170
- if($('#node-input-sceneid').prop("tagName") === "INPUT")
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
- $('#node-config-input-scan-groups').click(function()
150
+ },
151
+ button: {
152
+ onclick: function()
179
153
  {
180
- if($('#node-input-groupid').prop("tagName") === "INPUT")
154
+ const node = this;
155
+ if(node.bridge)
181
156
  {
182
- searchAndSelectGroupID();
183
- } else {
184
- manualGroupID();
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>
@@ -6,9 +6,19 @@ module.exports = function(RED)
6
6
  {
7
7
  RED.nodes.createNode(this, config);
8
8
 
9
- var scope = this;
10
- let bridge = RED.nodes.getNode(config.bridge);
11
- let { HueSceneMessage } = require('../utils/messages');
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
- // Node-RED < 1.0
26
- send = send || function() { scope.send.apply(scope,arguments); }
35
+ // REDEFINE SEND AND DONE IF NOT AVAILABLE
36
+ done = done || function() { scope.done.apply(scope,arguments); }
27
37
 
28
- var groupID = config.groupid;
29
- var sceneDef = config.sceneid;
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
- // PASSED SCENE NAME?
32
- if(typeof msg.payload === 'string' || msg.payload instanceof String)
33
- {
34
- sceneDef = msg.payload;
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
- if(config.sceneid)
43
- {
44
- bridge.client.scenes.getById(config.sceneid)
45
- .then(scene => {
46
- scope.proceedSceneAction(scene, groupID, send, done);
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
- var groupID = parseInt(applyOnGroup);
84
- bridge.client.groups.getById(groupID)
85
- .then(group =>
86
- {
87
- group.on = true;
88
- group.scene = scene;
89
- return bridge.client.groups.save(group);
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
- // SEND STATUS
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
- // SEND MESSAGE
97
- if(!config.skipevents)
73
+ if(targetGroup)
98
74
  {
99
- var hueScene = new HueSceneMessage(scene);
100
- send(hueScene.msg);
75
+ bridge.patch("group", targetGroup.info.idV1 + "/action", { "scene": targetSceneID }, 1)
76
+ .catch(function(errors) {
77
+ scope.error(errors);
78
+ });
101
79
  }
102
- if(done) { done(); }
80
+ }
103
81
 
104
- // RESET STATUS AFTER 3 SEC
105
- setTimeout(function() {
106
- scope.status({});
107
- }, 3000);
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 A SCENE
117
- bridge.client.scenes.recall(scene)
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
- // SEND MESSAGE
123
- if(!config.skipevents)
124
- {
125
- var hueScene = new HueSceneMessage(scene);
126
- send(hueScene.msg);
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 3 SEC
102
+ // RESET STATUS AFTER 1 SECOND
131
103
  setTimeout(function() {
132
104
  scope.status({});
133
- }, 3000);
105
+ }, 1000);
134
106
  })
135
- .catch(error => {
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
+ }