node-red-contrib-huemagic 2.8.6 → 4.0.2

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 (170) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +807 -766
  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 -320
  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 -368
  65. package/huemagic/hue-light.html +133 -59
  66. package/huemagic/hue-light.js +551 -337
  67. package/huemagic/hue-magic.html +91 -240
  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-button.json → hue-buttons.json} +8 -8
  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-button.json → hue-buttons.json} +11 -5
  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 +11 -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-button.html +0 -119
  150. package/huemagic/hue-button.js +0 -94
  151. package/huemagic/hue-switch.html +0 -119
  152. package/huemagic/hue-switch.js +0 -113
  153. package/huemagic/hue-tap.html +0 -119
  154. package/huemagic/hue-tap.js +0 -74
  155. package/huemagic/icons/hue-button.png +0 -0
  156. package/huemagic/icons/hue-switch.png +0 -0
  157. package/huemagic/icons/hue-tap.png +0 -0
  158. package/huemagic/locales/de/hue-button.html +0 -50
  159. package/huemagic/locales/de/hue-switch.html +0 -50
  160. package/huemagic/locales/de/hue-switch.json +0 -31
  161. package/huemagic/locales/de/hue-tap.html +0 -41
  162. package/huemagic/locales/de/hue-tap.json +0 -23
  163. package/huemagic/locales/en-US/hue-button.html +0 -50
  164. package/huemagic/locales/en-US/hue-switch.html +0 -50
  165. package/huemagic/locales/en-US/hue-switch.json +0 -31
  166. package/huemagic/locales/en-US/hue-tap.html +0 -41
  167. package/huemagic/locales/en-US/hue-tap.json +0 -23
  168. package/utils/color.js +0 -9
  169. package/utils/messages.js +0 -658
  170. package/utils/rgb.js +0 -188
@@ -1,119 +0,0 @@
1
- <script type="text/x-red" data-template-name="hue-button">
2
- <div class="form-row">
3
- <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="hue-button.config.name"></span></label>
4
- <input type="text" id="node-input-name" data-i18n="[placeholder]hue-button.config.input-name">
5
- </div>
6
- <div class="form-row">
7
- <label for="node-input-bridge"><i class="fa fa-server"></i> Bridge</label>
8
- <input type="text" id="node-input-bridge">
9
- </div>
10
- <div class="form-row">
11
- <label for="node-input-sensorid"><i class="fa fa-hand-pointer-o"></i> <span data-i18n="hue-button.config.button"></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-sensorid" placeholder="1" style="width: 100%"/>
15
- </div>
16
- <a id="node-config-input-scan-buttons-sensors" class="editor-button" style="position: absolute; right: 0px; top: 0px;">
17
- <i class="fa fa-search"></i>
18
- </a>
19
- </div>
20
- </div>
21
- <div class="form-row">
22
- <label for="node-input-skipevents"><i class="fa fa-sign-out"></i> <span data-i18n="hue-button.config.skipevents"></span></label>
23
- <input type="checkbox" id="node-input-skipevents" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="hue-button.config.skipevents-node"></span>
24
- </label>
25
- </div>
26
- </script>
27
-
28
- <script type="text/javascript">
29
- RED.nodes.registerType('hue-button',{
30
- category: 'HueMagic',
31
- color: '#347aeb',
32
- defaults: {
33
- name: {value:""},
34
- bridge: {type: "hue-bridge", required: true},
35
- sensorid: {value:"", required: true, validate: RED.validators.number()},
36
- skipevents: {value: false}
37
- },
38
- inputs: 0,
39
- outputs: 1,
40
- outputLabels: function() {
41
- return this._("hue-button.node.output");
42
- },
43
- align: 'right',
44
- icon: "hue-button.png",
45
- paletteLabel: function() {
46
- return this._("hue-button.node.title");
47
- },
48
- label: function() {
49
- return this.name || this._("hue-button.node.title");
50
- },
51
- oneditprepare: function()
52
- {
53
- var scope = this;
54
-
55
- function manualButtonID()
56
- {
57
- var current = $('#node-input-sensorid').val();
58
- $('#node-input-sensorid').replaceWith('<input type="text" id="node-input-sensorid" style="width: 100%"/>');
59
- $('#node-input-sensorid').val(current);
60
- }
61
-
62
- function searchAndSelectHueButtonID()
63
- {
64
- var current = $('#node-input-sensorid').val();
65
- $('#node-input-sensorid').replaceWith('<select id="node-input-sensorid" style="width: 100%"></select>');
66
- $('#node-input-sensorid').append('<option selected="selected" value="null">'+scope._("hue-button.config.searching")+'</option>');
67
-
68
- var bridgeConfig = RED.nodes.node($('#node-input-bridge option:selected').val());
69
- $.get('hue/sensors', {bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "ZLLSwitch"})
70
- .done( function(data) {
71
- var hueButtons = JSON.parse(data);
72
-
73
- if(hueButtons.length <= 0)
74
- {
75
- RED.notify(scope._("hue-button.config.none-found"), "error");
76
- }
77
-
78
- // RESET OPTIONS
79
- $('#node-input-sensorid').empty();
80
-
81
- // SET BUTTONS AS OPTIONS
82
- hueButtons.forEach(function(sensor)
83
- {
84
- if(sensor.model_id == "ROM001") //to make sure it is a Smart Button
85
- {
86
- $('#node-input-sensorid').append('<option value="' + sensor.id + '">' + sensor.name + '</option>');
87
- }
88
- });
89
-
90
- // SELECT CURRENT VALUE
91
- $('#node-input-sensorid').val(current);
92
- })
93
- .fail(function()
94
- {
95
- RED.notify("Something went wrong. Please retry.", "error");
96
- });
97
- }
98
-
99
- $(document).on('change', '#node-input-sensorid', function()
100
- {
101
- var sensorName = $('#node-input-sensorid option:selected').text();
102
- if(sensorName.length > 0)
103
- {
104
- $('#node-input-name').val(sensorName);
105
- }
106
- });
107
-
108
- $('#node-config-input-scan-buttons-sensors').click(function()
109
- {
110
- if($('#node-input-sensorid').prop("tagName") === "INPUT")
111
- {
112
- searchAndSelectHueButtonID();
113
- } else {
114
- manualButtonID();
115
- }
116
- });
117
- }
118
- });
119
- </script>
@@ -1,94 +0,0 @@
1
- module.exports = function(RED)
2
- {
3
- "use strict";
4
-
5
- function HueButton(config)
6
- {
7
- RED.nodes.createNode(this, config);
8
-
9
- var scope = this;
10
- let bridge = RED.nodes.getNode(config.bridge);
11
- let { HueButtonMessage } = require('../utils/messages');
12
-
13
- // SAVE LAST STATE
14
- var lastState = false;
15
-
16
- //
17
- // MEMORY
18
- this.lastUpdated = false;
19
-
20
- //
21
- // CHECK CONFIG
22
- if(!config.sensorid || bridge == null)
23
- {
24
- this.status({fill: "red", shape: "ring", text: "hue-button.node.not-configured"});
25
- return false;
26
- }
27
-
28
- //
29
- // UPDATE STATE
30
- scope.status({fill: "grey", shape: "dot", text: "hue-button.node.waiting"});
31
-
32
- //
33
- // ON UPDATE
34
- bridge.events.on('sensor' + config.sensorid, function(sensor)
35
- {
36
- var lastUpdated = scope.lastUpdated || false;
37
- if(sensor.state.lastUpdated != lastUpdated)
38
- {
39
- scope.lastUpdated = sensor.state.lastUpdated;
40
-
41
- // RETURN ON FIRST DEPLOY
42
- if (lastUpdated === false) {
43
- return;
44
- }
45
-
46
- // DEFINE HUMAN READABLE BUTTON ACTION
47
- var buttonActionLocalized = "";
48
- var buttonActionRaw = parseInt(sensor.state.buttonEvent.toString().substring(3));
49
- if(buttonActionRaw == 0)
50
- {
51
- buttonActionLocalized = RED._("hue-button.node.action-pressed");
52
- }
53
- else if(buttonActionRaw == 1)
54
- {
55
- buttonActionLocalized = RED._("hue-button.node.action-holded");
56
- }
57
- else if(buttonActionRaw == 2)
58
- {
59
- buttonActionLocalized = RED._("hue-button.node.action-shortreleased");
60
- }
61
- else
62
- {
63
- buttonActionLocalized = RED._("hue-button.node.action-longreleased");
64
- }
65
-
66
- // SEND STATUS
67
- scope.status({fill: "green", shape: "dot", text: buttonActionLocalized});
68
-
69
- // SEND MESSAGE
70
- if(!config.skipevents)
71
- {
72
- var hueButton = new HueButtonMessage(sensor, lastState);
73
- scope.send(hueButton.msg);
74
- }
75
-
76
- // SAVE LAST STATE
77
- lastState = sensor;
78
- }
79
- else
80
- {
81
- scope.status({fill: "grey", shape: "dot", text: "hue-button.node.waiting"});
82
- }
83
- });
84
-
85
- //
86
- // CLOSE NODE / REMOVE EVENT LISTENER
87
- this.on('close', function()
88
- {
89
- bridge.events.removeAllListeners('sensor' + config.sensorid);
90
- });
91
- }
92
-
93
- RED.nodes.registerType("hue-button", HueButton);
94
- }
@@ -1,119 +0,0 @@
1
- <script type="text/x-red" data-template-name="hue-switch">
2
- <div class="form-row">
3
- <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="hue-switch.config.name"></span></label>
4
- <input type="text" id="node-input-name" data-i18n="[placeholder]hue-switch.config.input-name">
5
- </div>
6
- <div class="form-row">
7
- <label for="node-input-bridge"><i class="fa fa-server"></i> Bridge</label>
8
- <input type="text" id="node-input-bridge">
9
- </div>
10
- <div class="form-row">
11
- <label for="node-input-sensorid"><i class="fa fa-hand-pointer-o"></i> <span data-i18n="hue-switch.config.switch"></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-sensorid" placeholder="1" style="width: 100%"/>
15
- </div>
16
- <a id="node-config-input-scan-switches-sensors" class="editor-button" style="position: absolute; right: 0px; top: 0px;">
17
- <i class="fa fa-search"></i>
18
- </a>
19
- </div>
20
- </div>
21
- <div class="form-row">
22
- <label for="node-input-skipevents"><i class="fa fa-sign-out"></i> <span data-i18n="hue-switch.config.skipevents"></span></label>
23
- <input type="checkbox" id="node-input-skipevents" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="hue-switch.config.skipevents-node"></span>
24
- </label>
25
- </div>
26
- </script>
27
-
28
- <script type="text/javascript">
29
- RED.nodes.registerType('hue-switch',{
30
- category: 'HueMagic',
31
- color: '#65bff7',
32
- defaults: {
33
- name: {value:""},
34
- bridge: {type: "hue-bridge", required: true},
35
- sensorid: {value:"", required: true, validate: RED.validators.number()},
36
- skipevents: {value: false}
37
- },
38
- inputs: 0,
39
- outputs: 1,
40
- outputLabels: function() {
41
- return this._("hue-switch.node.output");
42
- },
43
- align: 'right',
44
- icon: "hue-switch.png",
45
- paletteLabel: function() {
46
- return this._("hue-switch.node.title");
47
- },
48
- label: function() {
49
- return this.name || this._("hue-switch.node.title");
50
- },
51
- oneditprepare: function()
52
- {
53
- var scope = this;
54
-
55
- function manualSwitchID()
56
- {
57
- var current = $('#node-input-sensorid').val();
58
- $('#node-input-sensorid').replaceWith('<input type="text" id="node-input-sensorid" style="width: 100%"/>');
59
- $('#node-input-sensorid').val(current);
60
- }
61
-
62
- function searchAndSelectHueSwitchID()
63
- {
64
- var current = $('#node-input-sensorid').val();
65
- $('#node-input-sensorid').replaceWith('<select id="node-input-sensorid" style="width: 100%"></select>');
66
- $('#node-input-sensorid').append('<option selected="selected" value="null">'+scope._("hue-switch.config.searching")+'</option>');
67
-
68
- var bridgeConfig = RED.nodes.node($('#node-input-bridge option:selected').val());
69
- $.get('hue/sensors', {bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "ZLLSwitch"})
70
- .done( function(data) {
71
- var hueSwitches = JSON.parse(data);
72
-
73
- if(hueSwitches.length <= 0)
74
- {
75
- RED.notify(scope._("hue-switch.config.none-found"), "error");
76
- }
77
-
78
- // RESET OPTIONS
79
- $('#node-input-sensorid').empty();
80
-
81
- // SET SWITCHES AS OPTIONS
82
- hueSwitches.forEach(function(sensor)
83
- {
84
- if(sensor.model == "Hue Wireless Dimmer Switch")
85
- {
86
- $('#node-input-sensorid').append('<option value="' + sensor.id + '">' + sensor.name + '</option>');
87
- }
88
- });
89
-
90
- // SELECT CURRENT VALUE
91
- $('#node-input-sensorid').val(current);
92
- })
93
- .fail(function()
94
- {
95
- RED.notify("Something went wrong. Please retry.", "error");
96
- });
97
- }
98
-
99
- $(document).on('change', '#node-input-sensorid', function()
100
- {
101
- var sensorName = $('#node-input-sensorid option:selected').text();
102
- if(sensorName.length > 0)
103
- {
104
- $('#node-input-name').val(sensorName);
105
- }
106
- });
107
-
108
- $('#node-config-input-scan-switches-sensors').click(function()
109
- {
110
- if($('#node-input-sensorid').prop("tagName") === "INPUT")
111
- {
112
- searchAndSelectHueSwitchID();
113
- } else {
114
- manualSwitchID();
115
- }
116
- });
117
- }
118
- });
119
- </script>
@@ -1,113 +0,0 @@
1
- module.exports = function(RED)
2
- {
3
- "use strict";
4
-
5
- function HueSwitch(config)
6
- {
7
- RED.nodes.createNode(this, config);
8
-
9
- var scope = this;
10
- let bridge = RED.nodes.getNode(config.bridge);
11
- let { HueSwitchMessage } = require('../utils/messages');
12
-
13
- // SAVE LAST STATE
14
- var lastState = false;
15
-
16
- //
17
- // MEMORY
18
- this.lastUpdated = false;
19
-
20
- //
21
- // CHECK CONFIG
22
- if(!config.sensorid || bridge == null)
23
- {
24
- this.status({fill: "red", shape: "ring", text: "hue-switch.node.not-configured"});
25
- return false;
26
- }
27
-
28
- //
29
- // UPDATE STATE
30
- scope.status({fill: "grey", shape: "dot", text: "hue-switch.node.waiting"});
31
-
32
- //
33
- // ON UPDATE
34
- bridge.events.on('sensor' + config.sensorid, function(sensor)
35
- {
36
- var lastUpdated = scope.lastUpdated || false;
37
- if(sensor.state.lastUpdated != lastUpdated)
38
- {
39
- scope.lastUpdated = sensor.state.lastUpdated;
40
-
41
- // RETURN ON FIRST DEPLOY
42
- if (lastUpdated === false) {
43
- return;
44
- }
45
-
46
- // DEFINE HUMAN READABLE BUTTON NAME
47
- var buttonNameLocalized = "";
48
- if(sensor.state.buttonEvent < 2000)
49
- {
50
- buttonNameLocalized = RED._("hue-switch.node.button-on");
51
- }
52
- else if(sensor.state.buttonEvent < 3000)
53
- {
54
- buttonNameLocalized = RED._("hue-switch.node.button-dimup");
55
- }
56
- else if(sensor.state.buttonEvent < 4000)
57
- {
58
- buttonNameLocalized = RED._("hue-switch.node.button-dimdown");
59
- }
60
- else
61
- {
62
- buttonNameLocalized = RED._("hue-switch.node.button-off");
63
- }
64
-
65
- // DEFINE HUMAN READABLE BUTTON ACTION
66
- var buttonActionLocalized = "";
67
- var buttonActionRaw = parseInt(sensor.state.buttonEvent.toString().substring(3));
68
- if(buttonActionRaw == 0)
69
- {
70
- buttonActionLocalized = RED._("hue-switch.node.action-pressed");
71
- }
72
- else if(buttonActionRaw == 1)
73
- {
74
- buttonActionLocalized = RED._("hue-switch.node.action-holded");
75
- }
76
- else if(buttonActionRaw == 2)
77
- {
78
- buttonActionLocalized = RED._("hue-switch.node.action-shortreleased");
79
- }
80
- else
81
- {
82
- buttonActionLocalized = RED._("hue-switch.node.action-longreleased");
83
- }
84
-
85
- // SEND STATUS
86
- scope.status({fill: "green", shape: "dot", text: buttonNameLocalized + " " + buttonActionLocalized});
87
-
88
- // SEND MESSAGE
89
- if(!config.skipevents)
90
- {
91
- var hueSwitch = new HueSwitchMessage(sensor, lastState);
92
- scope.send(hueSwitch.msg);
93
- }
94
-
95
- // SAVE LAST STATE
96
- lastState = sensor;
97
- }
98
- else
99
- {
100
- scope.status({fill: "grey", shape: "dot", text: "hue-switch.node.waiting"});
101
- }
102
- });
103
-
104
- //
105
- // CLOSE NODE / REMOVE EVENT LISTENER
106
- this.on('close', function()
107
- {
108
- bridge.events.removeAllListeners('sensor' + config.sensorid);
109
- });
110
- }
111
-
112
- RED.nodes.registerType("hue-switch", HueSwitch);
113
- }
@@ -1,119 +0,0 @@
1
- <script type="text/x-red" data-template-name="hue-tap">
2
- <div class="form-row">
3
- <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="hue-tap.config.name"></span></label>
4
- <input type="text" id="node-input-name" data-i18n="[placeholder]hue-tap.config.input-name">
5
- </div>
6
- <div class="form-row">
7
- <label for="node-input-bridge"><i class="fa fa-server"></i> Bridge</label>
8
- <input type="text" id="node-input-bridge">
9
- </div>
10
- <div class="form-row">
11
- <label for="node-input-sensorid"><i class="fa fa-hand-pointer-o"></i> Tap</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-sensorid" placeholder="1" style="width: 100%"/>
15
- </div>
16
- <a id="node-config-input-scan-tap-sensors" class="editor-button" style="position: absolute; right: 0px; top: 0px;">
17
- <i class="fa fa-search"></i>
18
- </a>
19
- </div>
20
- </div>
21
- <div class="form-row">
22
- <label for="node-input-skipevents"><i class="fa fa-sign-out"></i> <span data-i18n="hue-tap.config.skipevents"></span></label>
23
- <input type="checkbox" id="node-input-skipevents" style="display:inline-block; width:22px; vertical-align:baseline;"><span data-i18n="hue-tap.config.skipevents-node"></span>
24
- </label>
25
- </div>
26
- </script>
27
-
28
- <script type="text/javascript">
29
- RED.nodes.registerType('hue-tap',{
30
- category: 'HueMagic',
31
- color: '#46d6ca',
32
- defaults: {
33
- name: {value:""},
34
- bridge: {type: "hue-bridge", required: true},
35
- sensorid: {value:"", required: true, validate: RED.validators.number()},
36
- skipevents: {value: false}
37
- },
38
- inputs: 0,
39
- outputs: 1,
40
- outputLabels: function() {
41
- return this._("hue-tap.node.output");
42
- },
43
- align: 'right',
44
- icon: "hue-tap.png",
45
- paletteLabel: function() {
46
- return this._("hue-tap.node.title");
47
- },
48
- label: function() {
49
- return this.name || this._("hue-tap.node.title");
50
- },
51
- oneditprepare: function()
52
- {
53
- var scope = this;
54
-
55
- function manualTapID()
56
- {
57
- var current = $('#node-input-sensorid').val();
58
- $('#node-input-sensorid').replaceWith('<input type="text" id="node-input-sensorid" style="width: 100%"/>');
59
- $('#node-input-sensorid').val(current);
60
- }
61
-
62
- function searchAndSelectHueTap()
63
- {
64
- var current = $('#node-input-sensorid').val();
65
- $('#node-input-sensorid').replaceWith('<select id="node-input-sensorid" style="width: 100%"></select>');
66
- $('#node-input-sensorid').append('<option selected="selected" value="null">'+scope._("hue-tap.config.searching")+'</option>');
67
-
68
- var bridgeConfig = RED.nodes.node($('#node-input-bridge option:selected').val());
69
- $.get('hue/sensors', {bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "ZGPSwitch"})
70
- .done( function(data) {
71
- var hueTaps = JSON.parse(data);
72
-
73
- if(hueTaps.length <= 0)
74
- {
75
- RED.notify(scope._("hue-tap.config.none-found"), "error");
76
- }
77
-
78
- // RESET OPTIONS
79
- $('#node-input-sensorid').empty();
80
-
81
- // SET TAPS AS OPTIONS
82
- hueTaps.forEach(function(sensor)
83
- {
84
- if(sensor.model == "Hue Tap")
85
- {
86
- $('#node-input-sensorid').append('<option value="' + sensor.id + '">' + sensor.name + '</option>');
87
- }
88
- });
89
-
90
- // SELECT CURRENT VALUE
91
- $('#node-input-sensorid').val(current);
92
- })
93
- .fail(function()
94
- {
95
- RED.notify(scope._("hue-tap.config.unknown-error"), "error");
96
- });
97
- }
98
-
99
- $(document).on('change', '#node-input-sensorid', function()
100
- {
101
- var sensorName = $('#node-input-sensorid option:selected').text();
102
- if(sensorName.length > 0)
103
- {
104
- $('#node-input-name').val(sensorName);
105
- }
106
- });
107
-
108
- $('#node-config-input-scan-tap-sensors').click(function()
109
- {
110
- if($('#node-input-sensorid').prop("tagName") === "INPUT")
111
- {
112
- searchAndSelectHueTap();
113
- } else {
114
- manualTapID();
115
- }
116
- });
117
- }
118
- });
119
- </script>
@@ -1,74 +0,0 @@
1
- module.exports = function(RED)
2
- {
3
- "use strict";
4
-
5
- function HueTap(config)
6
- {
7
- RED.nodes.createNode(this, config);
8
-
9
- var scope = this;
10
- var bridge = RED.nodes.getNode(config.bridge);
11
- let { HueTapMessage } = require('../utils/messages');
12
-
13
- // SAVE LAST STATE
14
- var lastState = false;
15
-
16
- //
17
- // MEMORY
18
- this.lastUpdated = false;
19
-
20
- //
21
- // CHECK CONFIG
22
- if(!config.sensorid || bridge == null)
23
- {
24
- this.status({fill: "red", shape: "ring", text: "hue-tap.node.not-configured"});
25
- return false;
26
- }
27
-
28
- //
29
- // UPDATE STATE
30
- scope.status({fill: "grey", shape: "dot", text: "hue-tap.node.waiting"});
31
-
32
- //
33
- // ON UPDATE
34
- bridge.events.on('sensor' + config.sensorid, function(sensor)
35
- {
36
- var lastUpdated = scope.lastUpdated || false;
37
-
38
- if(sensor.state.lastUpdated != lastUpdated)
39
- {
40
- scope.lastUpdated = sensor.state.lastUpdated;
41
-
42
- // RETURN ON FIRST DEPLOY
43
- if (lastUpdated === false)
44
- {
45
- return;
46
- }
47
-
48
- // SEND MESSAGE
49
- var hueTap = new HueTapMessage(sensor, lastState);
50
- if(!config.skipevents) { scope.send(hueTap.msg); }
51
-
52
- // SAVE LAST STATE
53
- lastState = sensor;
54
-
55
- // SEND STATUS
56
- scope.status({fill: "green", shape: "dot", text: RED._("hue-tap.node.pressed-button",{button: hueTap.msg.payload.button}) });
57
- }
58
- else
59
- {
60
- scope.status({fill: "grey", shape: "dot", text: "hue-tap.node.waiting"});
61
- }
62
- });
63
-
64
-
65
- //
66
- // CLOSE NODE / REMOVE EVENT LISTENER
67
- this.on('close', function()
68
- {
69
- bridge.events.removeAllListeners('sensor' + config.sensorid);
70
- });
71
- }
72
-
73
- RED.nodes.registerType("hue-tap", HueTap);
74
- }
Binary file
Binary file
Binary file