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.
- package/README.md +764 -603
- 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/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/006-fireplace.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/016-milkyway.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 +631 -319
- package/huemagic/hue-bridge.html +41 -21
- package/huemagic/hue-bridge.js +190 -396
- package/huemagic/hue-brightness.html +127 -59
- package/huemagic/hue-brightness.js +111 -55
- package/huemagic/hue-buttons.html +197 -0
- package/huemagic/hue-buttons.js +158 -0
- package/huemagic/hue-group.html +137 -66
- package/huemagic/hue-group.js +387 -403
- package/huemagic/hue-light.html +132 -64
- package/huemagic/hue-light.js +544 -378
- package/huemagic/hue-magic.html +36 -20
- package/huemagic/hue-magic.js +49 -27
- package/huemagic/hue-motion.html +127 -59
- package/huemagic/hue-motion.js +105 -101
- package/huemagic/hue-rules.html +121 -50
- package/huemagic/hue-rules.js +89 -63
- package/huemagic/hue-scene.html +95 -114
- package/huemagic/hue-scene.js +64 -95
- package/huemagic/hue-temperature.html +127 -59
- package/huemagic/hue-temperature.js +120 -56
- 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 +50 -50
- package/huemagic/locales/de/hue-brightness.json +6 -5
- package/huemagic/locales/de/hue-buttons.html +58 -0
- package/huemagic/locales/de/{hue-button.json → hue-buttons.json} +7 -11
- package/huemagic/locales/de/hue-group.html +46 -122
- package/huemagic/locales/de/hue-group.json +5 -5
- package/huemagic/locales/de/hue-light.html +68 -116
- package/huemagic/locales/de/hue-light.json +5 -5
- 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 +47 -50
- package/huemagic/locales/de/hue-motion.json +5 -5
- 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 +51 -48
- package/huemagic/locales/de/hue-temperature.json +6 -5
- 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 +50 -50
- package/huemagic/locales/en-US/hue-brightness.json +5 -2
- package/huemagic/locales/en-US/hue-buttons.html +58 -0
- package/huemagic/locales/en-US/{hue-button.json → hue-buttons.json} +6 -4
- package/huemagic/locales/en-US/hue-group.html +46 -122
- package/huemagic/locales/en-US/hue-group.json +4 -2
- package/huemagic/locales/en-US/hue-light.html +68 -116
- package/huemagic/locales/en-US/hue-light.json +4 -2
- 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 +47 -50
- package/huemagic/locales/en-US/hue-motion.json +4 -2
- 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 +51 -48
- package/huemagic/locales/en-US/hue-temperature.json +5 -2
- package/huemagic/utils/api.js +290 -0
- package/huemagic/utils/color.js +382 -0
- package/{utils → huemagic/utils}/merge.js +4 -6
- package/huemagic/utils/messages.js +447 -0
- package/package.json +9 -15
- package/examples/Hue Button.json +0 -40
- package/examples/Hue Switch.json +0 -40
- package/examples/Hue Tap.json +0 -40
- package/huemagic/hue-button.html +0 -132
- package/huemagic/hue-button.js +0 -143
- package/huemagic/hue-switch.html +0 -132
- package/huemagic/hue-switch.js +0 -163
- package/huemagic/hue-tap.html +0 -132
- package/huemagic/hue-tap.js +0 -123
- 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-button.html +0 -64
- package/huemagic/locales/de/hue-switch.html +0 -64
- package/huemagic/locales/de/hue-switch.json +0 -35
- package/huemagic/locales/de/hue-tap.html +0 -55
- package/huemagic/locales/de/hue-tap.json +0 -27
- package/huemagic/locales/en-US/hue-button.html +0 -64
- package/huemagic/locales/en-US/hue-switch.html +0 -64
- package/huemagic/locales/en-US/hue-switch.json +0 -35
- package/huemagic/locales/en-US/hue-tap.html +0 -55
- package/huemagic/locales/en-US/hue-tap.json +0 -27
- package/utils/color.js +0 -9
- package/utils/messages.js +0 -658
- package/utils/rgb.js +0 -188
package/huemagic/hue-bridge.js
CHANGED
|
@@ -6,23 +6,25 @@ module.exports = function(RED)
|
|
|
6
6
|
{
|
|
7
7
|
RED.nodes.createNode(this, config);
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let { HueBridgeMessage, HueBrightnessMessage, HueGroupMessage, HueLightMessage, HueMotionMessage, HueRulesMessage, HueSwitchMessage, HueTapMessage, HueTemperatureMessage } = require('../utils/messages');
|
|
9
|
+
const scope = this;
|
|
10
|
+
const bridge = RED.nodes.getNode(config.bridge);
|
|
12
11
|
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
// IS CONNECTED?
|
|
13
|
+
this.connected = false;
|
|
14
|
+
|
|
15
|
+
// GET BRIDGE INFORMATION INITIALLY
|
|
16
|
+
this.lastBridgeInformation = null;
|
|
17
|
+
|
|
18
|
+
// SAVE LAST COMMAND
|
|
19
|
+
this.lastCommand = null;
|
|
20
|
+
|
|
21
|
+
// NODE UI STATUS TIMEOUT
|
|
22
|
+
this.timeout = null;
|
|
17
23
|
|
|
18
24
|
//
|
|
19
25
|
// ACTIVE STATE
|
|
20
26
|
this.nodeActive = true;
|
|
21
27
|
|
|
22
|
-
//
|
|
23
|
-
// BRIDGE INFORMATION
|
|
24
|
-
this.bridgeInformation = {};
|
|
25
|
-
|
|
26
28
|
//
|
|
27
29
|
// CHECK CONFIG
|
|
28
30
|
if(bridge == null)
|
|
@@ -33,476 +35,268 @@ module.exports = function(RED)
|
|
|
33
35
|
|
|
34
36
|
//
|
|
35
37
|
// UPDATE STATE
|
|
36
|
-
|
|
38
|
+
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connecting"});
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
// GET INFORMATION
|
|
40
|
-
this.getBridgeInformation = function()
|
|
40
|
+
this.setInitialState = function()
|
|
41
41
|
{
|
|
42
|
-
bridge.
|
|
43
|
-
.then(bridgeInformation => {
|
|
44
|
-
var hueBridge = new HueBridgeMessage(bridgeInformation, config);
|
|
45
|
-
scope.send(hueBridge.msg);
|
|
46
|
-
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" });
|
|
47
|
-
|
|
48
|
-
// SAVE BRIDGE INFORMATION
|
|
49
|
-
scope.bridgeInformation = hueBridge.msg.payload;
|
|
50
|
-
})
|
|
51
|
-
.catch(error => {
|
|
52
|
-
scope.error(error);
|
|
53
|
-
if(scope.nodeActive == true)
|
|
54
|
-
{
|
|
55
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 3000);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
42
|
+
scope.status({fill: "green", shape: "dot", text: "hue-bridge.node.connected"});
|
|
58
43
|
}
|
|
59
44
|
|
|
60
|
-
//
|
|
61
|
-
// INITIAL START
|
|
62
|
-
this.getBridgeInformation();
|
|
63
45
|
|
|
64
46
|
//
|
|
65
|
-
//
|
|
66
|
-
this.
|
|
47
|
+
// GET BRIDGE INFORMATION
|
|
48
|
+
this.getBridgeInformation = async function(forceReload = false)
|
|
67
49
|
{
|
|
68
|
-
|
|
50
|
+
return new Promise(function(resolve, reject)
|
|
69
51
|
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return bridge.client.softwareUpdate.install();
|
|
76
|
-
})
|
|
77
|
-
.then(() => {
|
|
78
|
-
// UPDATING // CHECK STATUS IN 5 MINUTES
|
|
79
|
-
if(scope.nodeActive == true)
|
|
52
|
+
if(forceReload === true)
|
|
53
|
+
{
|
|
54
|
+
// REFRESH INFORMATION
|
|
55
|
+
bridge.getBridgeInformation(true)
|
|
56
|
+
.then(function(updated)
|
|
80
57
|
{
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.catch(error => {
|
|
85
|
-
// NO UPDATES AVAILABLE // TRY AGAIN IN 3H
|
|
86
|
-
if(scope.nodeActive == true)
|
|
58
|
+
return scope.getBridgeInformation();
|
|
59
|
+
})
|
|
60
|
+
.then(function(bridgeInformation)
|
|
87
61
|
{
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
this.autoUpdateHueBridge();
|
|
95
|
-
|
|
96
|
-
//
|
|
97
|
-
// DEVICE UPDATES
|
|
98
|
-
if(!config.skipglobalevents)
|
|
99
|
-
{
|
|
100
|
-
bridge.events.on('globalDeviceUpdates', function(message)
|
|
101
|
-
{
|
|
102
|
-
if(scope.deviceUpdates == false) { return; }
|
|
103
|
-
|
|
104
|
-
let type = message.type;
|
|
105
|
-
let payload = message.payload;
|
|
106
|
-
var detType = type;
|
|
107
|
-
|
|
108
|
-
// CONSTRUCT MESSAGE
|
|
109
|
-
var message = {};
|
|
110
|
-
message.updated = {};
|
|
111
|
-
|
|
112
|
-
// ADD PAYLOAD
|
|
113
|
-
if(type == "light")
|
|
114
|
-
{
|
|
115
|
-
let hueLight = new HueLightMessage(payload, {colornamer: true});
|
|
116
|
-
message.updated = hueLight.msg;
|
|
117
|
-
}
|
|
118
|
-
else if(type == "group")
|
|
119
|
-
{
|
|
120
|
-
let hueGroup = new HueGroupMessage(payload, {colornamer: true});
|
|
121
|
-
message.updated = hueGroup.msg;
|
|
62
|
+
resolve(bridgeInformation);
|
|
63
|
+
});
|
|
122
64
|
}
|
|
123
|
-
else if(
|
|
65
|
+
else if(scope.lastBridgeInformation !== null)
|
|
124
66
|
{
|
|
125
|
-
let
|
|
126
|
-
|
|
67
|
+
let bridgeInformationCopy = Object.assign({}, scope.lastBridgeInformation);
|
|
68
|
+
resolve(bridgeInformationCopy);
|
|
127
69
|
}
|
|
128
|
-
else
|
|
70
|
+
else
|
|
129
71
|
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
{
|
|
133
|
-
let hueMotion = new HueMotionMessage(payload);
|
|
134
|
-
message.updated = hueMotion.msg;
|
|
72
|
+
let bridgeInformation = bridge.get("bridge", "bridge", { autoupdate: ((bridge.config.autoupdates && bridge.config.autoupdates == true) || typeof bridge.config.autoupdates == 'undefined') });
|
|
73
|
+
scope.lastBridgeInformation = Object.assign({}, bridgeInformation);
|
|
135
74
|
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
else if(payload.type == "ZLLLightLevel")
|
|
139
|
-
{
|
|
140
|
-
let hueBrightness = new HueBrightnessMessage(payload);
|
|
141
|
-
message.updated = hueBrightness.msg;
|
|
142
|
-
|
|
143
|
-
detType = "brightness";
|
|
144
|
-
}
|
|
145
|
-
else if(payload.type == "ZLLTemperature")
|
|
146
|
-
{
|
|
147
|
-
let hueTemperature = new HueTemperatureMessage(payload);
|
|
148
|
-
message.updated = hueTemperature.msg;
|
|
149
|
-
|
|
150
|
-
detType = "temperature";
|
|
151
|
-
}
|
|
152
|
-
else if(payload.type == "ZLLSwitch")
|
|
153
|
-
{
|
|
154
|
-
let hueSwitch = new HueSwitchMessage(payload);
|
|
155
|
-
message.updated = hueSwitch.msg;
|
|
156
|
-
|
|
157
|
-
detType = "switch";
|
|
158
|
-
}
|
|
159
|
-
else if(payload.type == "ZGPSwitch")
|
|
160
|
-
{
|
|
161
|
-
let hueTap = new HueTapMessage(sensor);
|
|
162
|
-
message.updated = hueTap.msg;
|
|
163
|
-
|
|
164
|
-
detType = "tap";
|
|
165
|
-
}
|
|
75
|
+
resolve(bridgeInformation);
|
|
166
76
|
}
|
|
167
|
-
|
|
168
|
-
// ADD TYPE
|
|
169
|
-
message.updated.type = detType;
|
|
170
|
-
|
|
171
|
-
// ADD BRIDGE INFORMATION
|
|
172
|
-
message.info = scope.bridgeInformation;
|
|
173
|
-
|
|
174
|
-
// SEND MESSAGE
|
|
175
|
-
scope.send(message);
|
|
176
77
|
});
|
|
177
78
|
}
|
|
178
79
|
|
|
179
80
|
//
|
|
180
|
-
//
|
|
181
|
-
|
|
81
|
+
// SUBSCRIBE TO UPDATES FROM THE BRIDGE
|
|
82
|
+
bridge.subscribe("bridge", "globalResourceUpdates", async function(info)
|
|
182
83
|
{
|
|
183
|
-
|
|
184
|
-
send = send || function() { scope.send.apply(scope,arguments); }
|
|
185
|
-
|
|
186
|
-
var commandSent = false;
|
|
84
|
+
let currentState = bridge.get(info.updatedType, info.id);
|
|
187
85
|
|
|
188
|
-
//
|
|
189
|
-
if(
|
|
86
|
+
// RESOURCE FOUND?
|
|
87
|
+
if(currentState !== false)
|
|
190
88
|
{
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
.then(() => {
|
|
194
|
-
scope.status({fill: "blue", shape: "ring", text: "hue-bridge.node.started-tl" });
|
|
195
|
-
if(done) { done(); }
|
|
196
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 30000);
|
|
197
|
-
})
|
|
198
|
-
.catch(error => {
|
|
199
|
-
scope.error(error);
|
|
200
|
-
if(done) { done(error); }
|
|
201
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// COMMAND SENT
|
|
205
|
-
commandSent = true;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// GET DEVICES
|
|
209
|
-
if(typeof msg.payload.fetch != 'undefined')
|
|
210
|
-
{
|
|
211
|
-
if(msg.payload.fetch == "users")
|
|
89
|
+
// UPDATE COUNTER
|
|
90
|
+
if(info.suppressMessage === false)
|
|
212
91
|
{
|
|
213
|
-
scope.status({fill: "
|
|
214
|
-
bridge.client.users.getAll()
|
|
215
|
-
.then(users => {
|
|
216
|
-
setTimeout(function(){ scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" }); }, 2000);
|
|
217
|
-
|
|
218
|
-
var message = {};
|
|
219
|
-
message.users = users;
|
|
220
|
-
message.info = scope.bridgeInformation;
|
|
92
|
+
scope.status({fill: "blue", shape: "dot", text: "hue-bridge.node.connected"});
|
|
221
93
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
scope.error(error);
|
|
227
|
-
if(done) { done(error); }
|
|
228
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
229
|
-
});
|
|
94
|
+
if(scope.timeout !== null) { clearTimeout(scope.timeout); }
|
|
95
|
+
scope.timeout = setTimeout(function() {
|
|
96
|
+
scope.setInitialState();
|
|
97
|
+
}, 1000);
|
|
230
98
|
}
|
|
231
|
-
else if(msg.payload.fetch == "lights")
|
|
232
|
-
{
|
|
233
|
-
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.f-lights" });
|
|
234
|
-
bridge.client.lights.getAll()
|
|
235
|
-
.then(lights => {
|
|
236
|
-
setTimeout(function(){ scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" }); }, 2000);
|
|
237
|
-
|
|
238
|
-
var message = {};
|
|
239
|
-
message.lights = lights;
|
|
240
|
-
message.info = scope.bridgeInformation;
|
|
241
99
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
})
|
|
245
|
-
.catch(error => {
|
|
246
|
-
scope.error(error);
|
|
247
|
-
if(done) { done(error); }
|
|
248
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
else if(msg.payload.fetch == "groups")
|
|
100
|
+
// SEND MESSAGE
|
|
101
|
+
if(!config.skipglobalevents && (config.initevents || info.suppressMessage == false))
|
|
252
102
|
{
|
|
253
|
-
scope.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
var message = {};
|
|
259
|
-
message.groups = groups;
|
|
260
|
-
message.info = scope.bridgeInformation;
|
|
103
|
+
scope.getBridgeInformation()
|
|
104
|
+
.then(function(info)
|
|
105
|
+
{
|
|
106
|
+
// ADD DEVICE UPDATE TO RESPONSE
|
|
107
|
+
info.updated = currentState;
|
|
261
108
|
|
|
262
|
-
|
|
263
|
-
if(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if(done) { done(error); }
|
|
268
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
else if(msg.payload.fetch == "sensors")
|
|
272
|
-
{
|
|
273
|
-
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.f-sensors" });
|
|
274
|
-
bridge.client.sensors.getAll()
|
|
275
|
-
.then(sensors => {
|
|
276
|
-
setTimeout(function(){ scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" }); }, 2000);
|
|
109
|
+
// SET LAST COMMAND
|
|
110
|
+
if(scope.lastCommand !== null)
|
|
111
|
+
{
|
|
112
|
+
info.command = scope.lastCommand;
|
|
113
|
+
}
|
|
277
114
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
message.info = scope.bridgeInformation;
|
|
115
|
+
// SEND MESSAGE
|
|
116
|
+
scope.send(info);
|
|
281
117
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
})
|
|
285
|
-
.catch(error => {
|
|
286
|
-
scope.error(error);
|
|
287
|
-
if(done) { done(error); }
|
|
288
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
118
|
+
// RESET LAST COMMAND
|
|
119
|
+
scope.lastCommand = null;
|
|
289
120
|
});
|
|
290
121
|
}
|
|
291
|
-
|
|
292
|
-
{
|
|
293
|
-
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.f-scenes" });
|
|
294
|
-
bridge.client.scenes.getAll()
|
|
295
|
-
.then(scenes => {
|
|
296
|
-
setTimeout(function(){ scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" }); }, 2000);
|
|
122
|
+
}
|
|
297
123
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
124
|
+
// CONNECTED?
|
|
125
|
+
if(scope.connected == false)
|
|
126
|
+
{
|
|
127
|
+
scope.connected = true;
|
|
128
|
+
scope.setInitialState();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
301
131
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
else if(msg.payload.fetch == "rules")
|
|
312
|
-
{
|
|
313
|
-
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.f-rules" });
|
|
314
|
-
bridge.client.rules.getAll()
|
|
315
|
-
.then(rules => {
|
|
316
|
-
setTimeout(function(){ scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" }); }, 2000);
|
|
132
|
+
//
|
|
133
|
+
// ON COMMAND
|
|
134
|
+
this.on('input', function(msg, send, done)
|
|
135
|
+
{
|
|
136
|
+
// REDEFINE SEND AND DONE IF NOT AVAILABLE
|
|
137
|
+
send = send || function() { scope.send.apply(scope,arguments); }
|
|
138
|
+
done = done || function() { scope.done.apply(scope,arguments); }
|
|
317
139
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
message.info = scope.bridgeInformation;
|
|
140
|
+
// SET LAST COMMAND
|
|
141
|
+
scope.lastCommand = RED.util.cloneMessage(msg);
|
|
321
142
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
else if(msg.payload.fetch == "schedules")
|
|
143
|
+
// GET BRIDGE INFORMATION
|
|
144
|
+
scope.getBridgeInformation()
|
|
145
|
+
.then(function(bridgeInformation)
|
|
146
|
+
{
|
|
147
|
+
// START TOUCHLINK
|
|
148
|
+
if(typeof msg.payload != 'undefined' && typeof msg.payload.touchLink != 'undefined')
|
|
332
149
|
{
|
|
333
|
-
|
|
334
|
-
bridge.
|
|
335
|
-
.then(schedules => {
|
|
336
|
-
setTimeout(function(){ scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" }); }, 2000);
|
|
337
|
-
|
|
338
|
-
var message = {};
|
|
339
|
-
message.schedules = schedules;
|
|
340
|
-
message.info = scope.bridgeInformation;
|
|
150
|
+
// SET STATUS
|
|
151
|
+
scope.status({fill: "yellow", shape: "dot", text: "hue-bridge.node.starting-tl" });
|
|
341
152
|
|
|
342
|
-
|
|
153
|
+
// ENABLE TOUCHLINK
|
|
154
|
+
bridge.patch("bridge", "/config", { touchlink: true }, 1)
|
|
155
|
+
.then(function(status)
|
|
156
|
+
{
|
|
157
|
+
// SET STATUS
|
|
158
|
+
scope.status({fill: "blue", shape: "ring", text: "hue-bridge.node.started-tl" });
|
|
343
159
|
if(done) { done(); }
|
|
344
|
-
})
|
|
345
|
-
.catch(error => {
|
|
346
|
-
scope.error(error);
|
|
347
|
-
if(done) { done(error); }
|
|
348
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
else if(msg.payload.fetch == "resourceLinks")
|
|
352
|
-
{
|
|
353
|
-
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.f-rlinks" });
|
|
354
|
-
bridge.client.resourceLinks.getAll()
|
|
355
|
-
.then(resourceLinks => {
|
|
356
|
-
setTimeout(function(){ scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" }); }, 2000);
|
|
357
|
-
|
|
358
|
-
var message = {};
|
|
359
|
-
message.resourceLinks = resourceLinks;
|
|
360
|
-
message.info = scope.bridgeInformation;
|
|
361
160
|
|
|
362
|
-
|
|
363
|
-
|
|
161
|
+
// RESET STATUS AFTER 30 SECONDS
|
|
162
|
+
setTimeout(function()
|
|
163
|
+
{
|
|
164
|
+
scope.setInitialState();
|
|
165
|
+
scope.getBridgeInformation(true);
|
|
166
|
+
}, 30000);
|
|
364
167
|
})
|
|
365
|
-
.catch(error
|
|
168
|
+
.catch(function(error)
|
|
169
|
+
{
|
|
366
170
|
scope.error(error);
|
|
367
171
|
if(done) { done(error); }
|
|
368
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
369
172
|
});
|
|
370
173
|
}
|
|
371
|
-
|
|
174
|
+
// FETCH RESOURCES
|
|
175
|
+
else if(typeof msg.payload != 'undefined' && typeof msg.payload.fetch != 'undefined')
|
|
372
176
|
{
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
177
|
+
let fetchTypes = [];
|
|
178
|
+
if(typeof msg.payload.fetch == 'string') { fetchTypes.push(msg.payload.fetch); }
|
|
179
|
+
else if(typeof msg.payload.fetch == 'object') { fetchTypes = msg.payload.fetch; }
|
|
180
|
+
else { return false; }
|
|
377
181
|
|
|
378
|
-
|
|
379
|
-
message.timeZones = timeZones;
|
|
380
|
-
message.info = scope.bridgeInformation;
|
|
182
|
+
scope.status({fill: "blue", shape: "dot", text: "hue-bridge.node.f-resources" });
|
|
381
183
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if(done) { done(error); }
|
|
388
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
184
|
+
// FETCH
|
|
185
|
+
bridgeInformation.results = {};
|
|
186
|
+
fetchTypes.forEach(function(fetch)
|
|
187
|
+
{
|
|
188
|
+
bridgeInformation.results[fetch] = bridge.get(fetch);
|
|
389
189
|
});
|
|
390
|
-
}
|
|
391
|
-
else if(msg.payload.fetch == "internetServices")
|
|
392
|
-
{
|
|
393
|
-
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.f-internet" });
|
|
394
|
-
bridge.client.internetServices.get()
|
|
395
|
-
.then(internetServices => {
|
|
396
|
-
setTimeout(function(){ scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" }); }, 2000);
|
|
397
190
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
191
|
+
// SEND RESULTS
|
|
192
|
+
if(scope.lastCommand !== null)
|
|
193
|
+
{
|
|
194
|
+
bridgeInformation.command = scope.lastCommand;
|
|
195
|
+
}
|
|
401
196
|
|
|
402
|
-
|
|
403
|
-
if(done) { done(); }
|
|
404
|
-
})
|
|
405
|
-
.catch(error => {
|
|
406
|
-
scope.error(error);
|
|
407
|
-
if(done) { done(error); }
|
|
408
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
else if(msg.payload.fetch == "portal")
|
|
412
|
-
{
|
|
413
|
-
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.f-portal" });
|
|
414
|
-
bridge.client.portal.get()
|
|
415
|
-
.then(portal => {
|
|
416
|
-
setTimeout(function(){ scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.connected" }); }, 2000);
|
|
197
|
+
send(bridgeInformation);
|
|
417
198
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
199
|
+
// RESET LAST COMMAND
|
|
200
|
+
scope.lastCommand = null;
|
|
201
|
+
if(done) { done(); }
|
|
421
202
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
})
|
|
425
|
-
.catch(error => {
|
|
426
|
-
scope.error(error);
|
|
427
|
-
if(done) { done(error); }
|
|
428
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
429
|
-
});
|
|
203
|
+
// RESET STATUS
|
|
204
|
+
setTimeout(function(){ scope.setInitialState(); }, 2000);
|
|
430
205
|
}
|
|
206
|
+
// UPDATE SETTINGS
|
|
207
|
+
else if(typeof msg.payload != 'undefined' && typeof msg.payload.settings != 'undefined')
|
|
208
|
+
{
|
|
209
|
+
let patchObject = {};
|
|
431
210
|
|
|
432
|
-
commandSent = true;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// UPDATING SETTINGS
|
|
436
|
-
if(typeof msg.payload.settings != 'undefined')
|
|
437
|
-
{
|
|
438
|
-
scope.status({fill: "grey", shape: "dot", text: "hue-bridge.node.updating-settings" });
|
|
439
|
-
bridge.client.bridge.get()
|
|
440
|
-
.then(bridgeConfig => {
|
|
441
211
|
if(typeof msg.payload.settings.name != 'undefined')
|
|
442
212
|
{
|
|
443
|
-
|
|
213
|
+
patchObject.name = msg.payload.settings.name;
|
|
444
214
|
}
|
|
445
215
|
if(typeof msg.payload.settings.zigbeeChannel != 'undefined')
|
|
446
216
|
{
|
|
447
|
-
|
|
217
|
+
patchObject.zigbeechannel = msg.payload.settings.zigbeeChannel;
|
|
448
218
|
}
|
|
449
219
|
if(typeof msg.payload.settings.ipAddress != 'undefined')
|
|
450
220
|
{
|
|
451
|
-
|
|
221
|
+
patchObject.ipaddress = msg.payload.settings.ipAddress;
|
|
452
222
|
}
|
|
453
223
|
if(typeof msg.payload.settings.dhcpEnabled != 'undefined')
|
|
454
224
|
{
|
|
455
|
-
|
|
225
|
+
patchObject.dhcp = msg.payload.settings.dhcpEnabled;
|
|
456
226
|
}
|
|
457
227
|
if(typeof msg.payload.settings.netmask != 'undefined')
|
|
458
228
|
{
|
|
459
|
-
|
|
229
|
+
patchObject.netmask = msg.payload.settings.netmask;
|
|
460
230
|
}
|
|
461
231
|
if(typeof msg.payload.settings.gateway != 'undefined')
|
|
462
232
|
{
|
|
463
|
-
|
|
233
|
+
patchObject.gateway = msg.payload.settings.gateway;
|
|
464
234
|
}
|
|
465
235
|
if(typeof msg.payload.settings.proxyPort != 'undefined')
|
|
466
236
|
{
|
|
467
|
-
|
|
237
|
+
patchObject.proxyport = msg.payload.settings.proxyPort;
|
|
468
238
|
}
|
|
469
239
|
if(typeof msg.payload.settings.proxyAddress != 'undefined')
|
|
470
240
|
{
|
|
471
|
-
|
|
241
|
+
patchObject.proxyaddress = msg.payload.settings.proxyAddress;
|
|
472
242
|
}
|
|
473
243
|
if(typeof msg.payload.settings.timeZone != 'undefined')
|
|
474
244
|
{
|
|
475
|
-
|
|
245
|
+
patchObject.timezone = msg.payload.settings.timeZone;
|
|
476
246
|
}
|
|
477
|
-
return bridge.client.bridge.save(bridgeConfig);
|
|
478
|
-
})
|
|
479
|
-
.then(bridgeInformation => {
|
|
480
|
-
scope.status({fill: "green", shape: "dot", text: "hue-bridge.node.settings-updated" });
|
|
481
|
-
if(done) { done(); }
|
|
482
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
483
|
-
})
|
|
484
|
-
.catch(error => {
|
|
485
|
-
scope.error(error);
|
|
486
|
-
if(done) { done(error); }
|
|
487
|
-
setTimeout(function(){ scope.getBridgeInformation(); }, 2000);
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
// COMMAND SENT
|
|
491
|
-
commandSent = true;
|
|
492
|
-
}
|
|
493
247
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
248
|
+
// PATCH BRIDGE!
|
|
249
|
+
if(Object.values(patchObject).length > 0)
|
|
250
|
+
{
|
|
251
|
+
// SET UPDATING STATUS
|
|
252
|
+
scope.status({fill: "yellow", shape: "dot", text: "hue-bridge.node.updating-settings" });
|
|
253
|
+
|
|
254
|
+
// PATCH BRIDGE
|
|
255
|
+
bridge.patch("bridge", "/config", patchObject, 1)
|
|
256
|
+
.then(function(patched)
|
|
257
|
+
{
|
|
258
|
+
// GET RELOADED BRIDGE INFORMATION
|
|
259
|
+
return scope.getBridgeInformation(true);
|
|
260
|
+
})
|
|
261
|
+
.then(function(bridgeInformation)
|
|
262
|
+
{
|
|
263
|
+
scope.status({fill: "blue", shape: "dot", text: "hue-bridge.node.settings-updated" });
|
|
264
|
+
|
|
265
|
+
// SET LAST COMMAND
|
|
266
|
+
if(scope.lastCommand !== null)
|
|
267
|
+
{
|
|
268
|
+
bridgeInformation.command = scope.lastCommand;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
scope.send(bridgeInformation);
|
|
272
|
+
|
|
273
|
+
// RESET LAST COMMAND
|
|
274
|
+
scope.lastCommand = null;
|
|
275
|
+
|
|
276
|
+
if(done) { done(); }
|
|
277
|
+
setTimeout(function(){ scope.setInitialState(); }, 3000);
|
|
278
|
+
})
|
|
279
|
+
.catch(function(error) {
|
|
280
|
+
scope.error(error);
|
|
281
|
+
if(done) { done(error); }
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// GIVE BACK CURRENT STATE
|
|
286
|
+
else
|
|
287
|
+
{
|
|
288
|
+
// SEND MESSAGE
|
|
289
|
+
if(scope.lastCommand !== null)
|
|
290
|
+
{
|
|
291
|
+
bridgeInformation.command = scope.lastCommand;
|
|
292
|
+
}
|
|
500
293
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
294
|
+
scope.send(bridgeInformation);
|
|
295
|
+
|
|
296
|
+
// RESET LAST COMMAND
|
|
297
|
+
scope.lastCommand = null;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
506
300
|
});
|
|
507
301
|
}
|
|
508
302
|
|