node-red-contrib-huemagic 3.0.0 → 4.0.3

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 (138) hide show
  1. package/README.md +764 -603
  2. package/examples/Hue Bridge.json +189 -35
  3. package/examples/Hue Brightness.json +124 -14
  4. package/examples/Hue Buttons.json +88 -0
  5. package/examples/Hue Group.json +575 -63
  6. package/examples/Hue Light.json +805 -58
  7. package/examples/Hue Magic.json +69 -24
  8. package/examples/Hue Motion.json +110 -42
  9. package/examples/Hue Rules.json +105 -37
  10. package/examples/Hue Scene.json +145 -28
  11. package/examples/Hue Temperature.json +124 -14
  12. package/huemagic/animations/019-christmas.json +30 -0
  13. package/huemagic/animations/020-superhero.json +56 -0
  14. package/huemagic/animations/021-neoncity.json +52 -0
  15. package/huemagic/animations/previews/006-fireplace.gif +0 -0
  16. package/huemagic/animations/previews/013-strobo.gif +0 -0
  17. package/huemagic/animations/previews/014-randomrainbow.gif +0 -0
  18. package/huemagic/animations/previews/016-milkyway.gif +0 -0
  19. package/huemagic/animations/previews/018-forest.gif +0 -0
  20. package/huemagic/animations/previews/019-christmas.gif +0 -0
  21. package/huemagic/animations/previews/020-superhero.gif +0 -0
  22. package/huemagic/animations/previews/021-neoncity.gif +0 -0
  23. package/huemagic/hue-bridge-config.html +105 -61
  24. package/huemagic/hue-bridge-config.js +631 -319
  25. package/huemagic/hue-bridge.html +41 -21
  26. package/huemagic/hue-bridge.js +190 -396
  27. package/huemagic/hue-brightness.html +127 -59
  28. package/huemagic/hue-brightness.js +111 -55
  29. package/huemagic/hue-buttons.html +197 -0
  30. package/huemagic/hue-buttons.js +158 -0
  31. package/huemagic/hue-group.html +137 -66
  32. package/huemagic/hue-group.js +387 -403
  33. package/huemagic/hue-light.html +132 -64
  34. package/huemagic/hue-light.js +544 -378
  35. package/huemagic/hue-magic.html +36 -20
  36. package/huemagic/hue-magic.js +49 -27
  37. package/huemagic/hue-motion.html +127 -59
  38. package/huemagic/hue-motion.js +105 -101
  39. package/huemagic/hue-rules.html +121 -50
  40. package/huemagic/hue-rules.js +89 -63
  41. package/huemagic/hue-scene.html +95 -114
  42. package/huemagic/hue-scene.js +64 -95
  43. package/huemagic/hue-temperature.html +127 -59
  44. package/huemagic/hue-temperature.js +120 -56
  45. package/huemagic/icons/hue-bridge.png +0 -0
  46. package/huemagic/icons/hue-bridge.svg +3 -0
  47. package/huemagic/icons/hue-brightness.png +0 -0
  48. package/huemagic/icons/hue-brightness.svg +11 -0
  49. package/huemagic/icons/hue-buttons.png +0 -0
  50. package/huemagic/icons/hue-buttons.svg +4 -0
  51. package/huemagic/icons/hue-group.png +0 -0
  52. package/huemagic/icons/hue-group.svg +12 -0
  53. package/huemagic/icons/hue-light.png +0 -0
  54. package/huemagic/icons/hue-light.svg +3 -0
  55. package/huemagic/icons/hue-magic.png +0 -0
  56. package/huemagic/icons/hue-magic.svg +3 -0
  57. package/huemagic/icons/hue-motion.png +0 -0
  58. package/huemagic/icons/hue-motion.svg +9 -0
  59. package/huemagic/icons/hue-rules.png +0 -0
  60. package/huemagic/icons/hue-rules.svg +4 -0
  61. package/huemagic/icons/hue-scene.png +0 -0
  62. package/huemagic/icons/hue-scene.svg +5 -0
  63. package/huemagic/icons/hue-temperature.png +0 -0
  64. package/huemagic/icons/hue-temperature.svg +7 -0
  65. package/huemagic/locales/de/hue-bridge-config.html +17 -12
  66. package/huemagic/locales/de/hue-bridge-config.json +7 -5
  67. package/huemagic/locales/de/hue-bridge.html +64 -145
  68. package/huemagic/locales/de/hue-bridge.json +6 -17
  69. package/huemagic/locales/de/hue-brightness.html +50 -50
  70. package/huemagic/locales/de/hue-brightness.json +6 -5
  71. package/huemagic/locales/de/hue-buttons.html +58 -0
  72. package/huemagic/locales/de/{hue-button.json → hue-buttons.json} +7 -11
  73. package/huemagic/locales/de/hue-group.html +46 -122
  74. package/huemagic/locales/de/hue-group.json +5 -5
  75. package/huemagic/locales/de/hue-light.html +68 -116
  76. package/huemagic/locales/de/hue-light.json +5 -5
  77. package/huemagic/locales/de/hue-magic.html +65 -57
  78. package/huemagic/locales/de/hue-magic.json +2 -1
  79. package/huemagic/locales/de/hue-motion.html +47 -50
  80. package/huemagic/locales/de/hue-motion.json +5 -5
  81. package/huemagic/locales/de/hue-rules.html +68 -73
  82. package/huemagic/locales/de/hue-rules.json +5 -2
  83. package/huemagic/locales/de/hue-scene.html +23 -32
  84. package/huemagic/locales/de/hue-scene.json +5 -2
  85. package/huemagic/locales/de/hue-temperature.html +51 -48
  86. package/huemagic/locales/de/hue-temperature.json +6 -5
  87. package/huemagic/locales/en-US/hue-bridge-config.html +17 -12
  88. package/huemagic/locales/en-US/hue-bridge-config.json +5 -3
  89. package/huemagic/locales/en-US/hue-bridge.html +64 -145
  90. package/huemagic/locales/en-US/hue-bridge.json +5 -16
  91. package/huemagic/locales/en-US/hue-brightness.html +50 -50
  92. package/huemagic/locales/en-US/hue-brightness.json +5 -2
  93. package/huemagic/locales/en-US/hue-buttons.html +58 -0
  94. package/huemagic/locales/en-US/{hue-button.json → hue-buttons.json} +6 -4
  95. package/huemagic/locales/en-US/hue-group.html +46 -122
  96. package/huemagic/locales/en-US/hue-group.json +4 -2
  97. package/huemagic/locales/en-US/hue-light.html +68 -116
  98. package/huemagic/locales/en-US/hue-light.json +4 -2
  99. package/huemagic/locales/en-US/hue-magic.html +65 -57
  100. package/huemagic/locales/en-US/hue-magic.json +3 -1
  101. package/huemagic/locales/en-US/hue-motion.html +47 -50
  102. package/huemagic/locales/en-US/hue-motion.json +4 -2
  103. package/huemagic/locales/en-US/hue-rules.html +68 -73
  104. package/huemagic/locales/en-US/hue-rules.json +5 -2
  105. package/huemagic/locales/en-US/hue-scene.html +23 -32
  106. package/huemagic/locales/en-US/hue-scene.json +5 -2
  107. package/huemagic/locales/en-US/hue-temperature.html +51 -48
  108. package/huemagic/locales/en-US/hue-temperature.json +5 -2
  109. package/huemagic/utils/api.js +290 -0
  110. package/huemagic/utils/color.js +382 -0
  111. package/{utils → huemagic/utils}/merge.js +4 -6
  112. package/huemagic/utils/messages.js +447 -0
  113. package/package.json +9 -15
  114. package/examples/Hue Button.json +0 -40
  115. package/examples/Hue Switch.json +0 -40
  116. package/examples/Hue Tap.json +0 -40
  117. package/huemagic/hue-button.html +0 -132
  118. package/huemagic/hue-button.js +0 -143
  119. package/huemagic/hue-switch.html +0 -132
  120. package/huemagic/hue-switch.js +0 -163
  121. package/huemagic/hue-tap.html +0 -132
  122. package/huemagic/hue-tap.js +0 -123
  123. package/huemagic/icons/hue-button.png +0 -0
  124. package/huemagic/icons/hue-switch.png +0 -0
  125. package/huemagic/icons/hue-tap.png +0 -0
  126. package/huemagic/locales/de/hue-button.html +0 -64
  127. package/huemagic/locales/de/hue-switch.html +0 -64
  128. package/huemagic/locales/de/hue-switch.json +0 -35
  129. package/huemagic/locales/de/hue-tap.html +0 -55
  130. package/huemagic/locales/de/hue-tap.json +0 -27
  131. package/huemagic/locales/en-US/hue-button.html +0 -64
  132. package/huemagic/locales/en-US/hue-switch.html +0 -64
  133. package/huemagic/locales/en-US/hue-switch.json +0 -35
  134. package/huemagic/locales/en-US/hue-tap.html +0 -55
  135. package/huemagic/locales/en-US/hue-tap.json +0 -27
  136. package/utils/color.js +0 -9
  137. package/utils/messages.js +0 -658
  138. package/utils/rgb.js +0 -188
@@ -1,38 +1,40 @@
1
1
  <script type="text/x-red" data-template-name="hue-light">
2
2
  <div class="form-row">
3
3
  <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="hue-light.config.name"></span></label>
4
- <input type="text" id="node-input-name" data-i18n="[placeholder]hue-light.config.input-name">
4
+ <input type="text" id="node-input-name" data-i18n="[placeholder]hue-light.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
11
  <label for="node-input-lightid"><i class="fa fa-lightbulb-o"></i> <span data-i18n="hue-light.config.light"></span></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-lightid" placeholder="1" style="width: 100%"/>
12
+ <div style="display: inline-flex; width: calc(100% - 105px)">
13
+ <div id="input-select-toggle" style="flex-grow: 1;">
14
+ <input type="text" id="node-input-lightid" placeholder="00000000-0000-0000-0000-000000000000" style="width: 100%"/>
15
15
  </div>
16
- <a id="node-config-input-scan-lights" class="editor-button" style="position: absolute; right: 0px; top: 0px;">
16
+ <button id="node-config-input-scan-lights" 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-colornamer"><i class="fa fa-check-circle"></i> <span data-i18n="hue-light.config.colornamer"></span></label>
23
- <label for="node-input-colornamer" style="width:70%">
24
- <input type="checkbox" id="node-input-colornamer" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="hue-light.config.colornamer-info"></span>
25
- </label>
21
+ <div class="form-row" style="margin-top: 30px">
22
+ <div style="display: inline-flex; width: calc(100% - 105px)">
23
+ <input type="checkbox" id="node-input-colornamer" style="flex: 15px;">
24
+ <span data-i18n="hue-light.config.colornamer-info" style="width: 100%; margin-left: 10px;"></span>
25
+ </div>
26
26
  </div>
27
27
  <div class="form-row">
28
- <label for="node-input-skipevents"><i class="fa fa-sign-out"></i> <span data-i18n="hue-light.config.skipevents"></span></label>
29
- <input type="checkbox" id="node-input-skipevents" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="hue-light.config.skipevents-node"></span>
30
- </label>
28
+ <div style="display: inline-flex; width: calc(100% - 105px)">
29
+ <input type="checkbox" id="node-input-skipevents" style="flex: 15px;">
30
+ <span data-i18n="hue-light.config.skipevents-node" style="width: 100%; margin-left: 10px;"></span>
31
+ </div>
31
32
  </div>
32
33
  <div class="form-row">
33
- <label for="node-input-universalevents"><i class="fa fa-bullhorn"></i> <span data-i18n="hue-light.config.universalevents"></span></label>
34
- <input type="checkbox" id="node-input-universalevents" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="hue-light.config.universalevents-node"></span>
35
- </label>
34
+ <div style="display: inline-flex; width: calc(100% - 105px)">
35
+ <input type="checkbox" id="node-input-initevents" style="flex: 15px;">
36
+ <span data-i18n="hue-light.config.sendinitevents-node" style="width: 100%; margin-left: 10px;"></span>
37
+ </div>
36
38
  </div>
37
39
  </script>
38
40
 
@@ -41,96 +43,162 @@
41
43
  category: 'HueMagic',
42
44
  color: '#47c0e8',
43
45
  defaults: {
44
- name: {value:""},
45
- bridge: {type: "hue-bridge", required: true},
46
- lightid: {value:"", required: false, validate: function(id) {
47
- if(id.length < 1) { return true; }
48
- else if(!isNaN(id)) { return true; }
49
- else { return false; }
50
- }},
51
- colornamer: {value: true},
52
- skipevents: {value: false},
53
- universalevents: {value: false}
46
+ name: { value:"" },
47
+ bridge: { type: "hue-bridge", required: true },
48
+ lightid: { value:"", required: false },
49
+ colornamer: { value: true },
50
+ skipevents: { value: false },
51
+ initevents: { value: false }
54
52
  },
53
+ align: 'left',
54
+ icon: "hue-light.png",
55
55
  inputs: 1,
56
56
  outputs: 1,
57
+ label: function() {
58
+ return this.name || this._("hue-light.node.title");
59
+ },
60
+ paletteLabel: function() {
61
+ return this._("hue-light.node.title");
62
+ },
57
63
  inputLabels: function() {
58
64
  return this._("hue-light.node.input");
59
65
  },
60
66
  outputLabels: function() {
61
67
  return this._("hue-light.node.output");
62
68
  },
63
- align: 'right',
64
- icon: "hue-light.png",
65
- paletteLabel: function() {
66
- return this._("hue-light.node.title");
67
- },
68
- label: function() {
69
- return this.name || this._("hue-light.node.title");
70
- },
71
69
  oneditprepare: function()
72
70
  {
73
- var scope = this;
71
+ const scope = this;
72
+ let options = [];
74
73
 
75
- function manualLightID()
74
+ function manualInput()
76
75
  {
76
+ // GET CURRENT SELECTED VALUE
77
77
  var current = $('#node-input-lightid').val();
78
- $('#node-input-lightid').replaceWith('<input type="text" id="node-input-lightid" style="width: 100%"/>');
79
- $('#node-input-lightid').val(current);
78
+
79
+ // REMOVE SELECT FIELD
80
+ $('#input-select-toggle').empty();
81
+
82
+ // CREATE NEW INPUT FIELD
83
+ $('#input-select-toggle').append('<input type="text" id="node-input-lightid" placeholder="00000000-0000-0000-0000-000000000000" style="width: 100%" value="'+current+'" />');
84
+
85
+ // CHANGE BUTTON ICON
86
+ var button = $("#node-config-input-scan-lights");
87
+ var buttonIcon = button.find("i");
88
+ buttonIcon.removeClass("fa-pencil");
89
+ buttonIcon.addClass("fa-search");
80
90
  }
81
91
 
82
- function searchAndSelectLightID()
92
+ function searchAndSelect()
83
93
  {
94
+ // GET CURRENT BRIDGE CONFIGURATION
95
+ var bridgeConfig = RED.nodes.node($('#node-input-bridge option:selected').val());
96
+ if(!bridgeConfig) { return false; }
97
+
98
+ // GET CURRENT SELECTED VALUE
84
99
  var current = $('#node-input-lightid').val();
85
- $('#node-input-lightid').replaceWith('<select id="node-input-lightid" style="width: 100%"></select>');
86
- $('#node-input-lightid').append('<option selected="selected" value="null">'+scope._("hue-light.config.searching")+'</option>');
87
100
 
88
- var bridgeConfig = RED.nodes.node($('#node-input-bridge option:selected').val());
89
- $.get('hue/lights', {bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "ZLLPresence"})
90
- .done(function(data) {
91
- var lightBulbs = JSON.parse(data);
101
+ // TRIGGER SEARCHING NOTIFICATION
102
+ var notification = RED.notify(scope._("hue-light.config.searching"), { type: "compact", modal: true, fixed: true });
92
103
 
93
- if(lightBulbs.length <= 0)
104
+ // GET THE LIGHTS
105
+ $.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "light" })
106
+ .done( function(data) {
107
+ var allResources = JSON.parse(data);
108
+ if(allResources.length <= 0)
94
109
  {
95
- RED.notify(scope._("hue-light.config.none-found"), "error");
110
+ notification.close();
111
+ RED.notify(scope._("hue-light.config.none-found"), { type: "error" });
112
+ return false;
96
113
  }
97
114
 
98
- // RESET OPTIONS
99
- $('#node-input-lightid').empty();
100
-
101
- // SET LIGHTS AS OPTIONS
102
- lightBulbs.forEach(function(light)
115
+ // SET OPTIONS
116
+ allResources.forEach(function(resource)
103
117
  {
104
- $('#node-input-lightid').append('<option value="' + light.id + '">' + light.name + '</option>');
118
+ if(resource.model)
119
+ {
120
+ options[resource.id] = { value: resource.id, label: resource.name + " ("+resource.model+")" };
121
+ }
122
+ else
123
+ {
124
+ options[resource.id] = { value: resource.id, label: resource.name };
125
+ }
105
126
  });
106
127
 
107
128
  // SELECT CURRENT VALUE
108
- $('#node-input-lightid').val(current);
129
+ $("#node-input-lightid").typedInput({
130
+ types: [
131
+ {
132
+ value: current,
133
+ options: Object.values(options)
134
+ }
135
+ ]
136
+ });
137
+
138
+ // CHANGE BUTTON ICON
139
+ var button = $("#node-config-input-scan-lights");
140
+ var buttonIcon = button.find("i");
141
+ buttonIcon.removeClass("fa-search");
142
+ buttonIcon.addClass("fa-pencil");
143
+
144
+ // CLOSE SEARCH NOTIFICATION
145
+ notification.close();
109
146
  })
110
147
  .fail(function()
111
148
  {
149
+ notification.close();
112
150
  RED.notify(scope._("hue-light.config.unknown-error"), "error");
113
151
  });
114
152
  }
115
153
 
116
- $(document).on('change', '#node-input-lightid', function()
154
+ // CHANGED LIGHT ID? -> REPLACE NAME (IF POSSIBLE)
155
+ $(document).on('change', '#node-input-lightid', function(e)
117
156
  {
118
- var lightName = $('#node-input-lightid option:selected').text();
119
- if(lightName.length > 0)
157
+ let currentSelectedOptionID = $(e.currentTarget).val();
158
+ let currentSelectedOptionValue = (currentSelectedOptionID.length > 0 && options[currentSelectedOptionID]) ? options[currentSelectedOptionID].label : false;
159
+
160
+ if(currentSelectedOptionValue !== false)
120
161
  {
121
- $('#node-input-name').val(lightName);
162
+ $('#node-input-name').val(currentSelectedOptionValue.split(" (")[0]);
122
163
  }
123
164
  });
124
165
 
166
+ // TOGGLE SELECT/INPUT FIELD
125
167
  $('#node-config-input-scan-lights').click(function()
126
168
  {
127
- if($('#node-input-lightid').prop("tagName") === "INPUT")
169
+ if($('#input-select-toggle').find(".red-ui-typedInput-container").length > 0)
170
+ {
171
+ manualInput();
172
+ }
173
+ else
128
174
  {
129
- searchAndSelectLightID();
130
- } else {
131
- manualLightID();
175
+ searchAndSelect();
132
176
  }
133
177
  });
178
+ },
179
+ button: {
180
+ enabled: function() {
181
+ return (this.lightid && this.lightid.length > 1)
182
+ },
183
+ visible: function() {
184
+ return (this.lightid && this.lightid.length > 1)
185
+ },
186
+ onclick: function()
187
+ {
188
+ const node = this;
189
+ if(node.bridge)
190
+ {
191
+ $.ajax({
192
+ url: "inject/" + node.id,
193
+ type: "POST",
194
+ data: JSON.stringify({ __user_inject_props__: "status"}),
195
+ contentType: "application/json; charset=utf-8",
196
+ success: function (resp) {
197
+ RED.notify(node.name + ": " + node._("hue-light.node.statusmsg"), { type: "success", id: "status", timeout: 2000 });
198
+ }
199
+ });
200
+ }
201
+ }
134
202
  }
135
203
  });
136
204
  </script>