@hurenkam/hue-services 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/node.js.yml +31 -0
- package/.nyc_output/ecb1b16f-015c-458b-96d5-32cb9569c1e8.json +1 -0
- package/.nyc_output/processinfo/ecb1b16f-015c-458b-96d5-32cb9569c1e8.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/.vscode/settings.json +15 -0
- package/.vscode/sftp.json +11 -0
- package/LICENSE +201 -0
- package/README.md +340 -0
- package/Todo.txt +18 -0
- package/coverage/BaseNode.js.html +379 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +101 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +161 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/RestApi.js.html +499 -0
- package/coverage/lcov-report/src/all.js.html +208 -0
- package/coverage/lcov-report/src/clip/ClipApi.js.html +1096 -0
- package/coverage/lcov-report/src/clip/Resource.js.html +481 -0
- package/coverage/lcov-report/src/clip/index.html +131 -0
- package/coverage/lcov-report/src/debug.js.html +253 -0
- package/coverage/lcov-report/src/files.js.html +118 -0
- package/coverage/lcov-report/src/index.html +161 -0
- package/coverage/lcov-report/src/nodes/BaseNode.js.html +381 -0
- package/coverage/lcov-report/src/nodes/BridgeConfigNode.js.html +817 -0
- package/coverage/lcov-report/src/nodes/ButtonNode.js.html +241 -0
- package/coverage/lcov-report/src/nodes/DevicePowerNode.js.html +199 -0
- package/coverage/lcov-report/src/nodes/GroupedLightNode.js.html +226 -0
- package/coverage/lcov-report/src/nodes/LightLevelNode.js.html +205 -0
- package/coverage/lcov-report/src/nodes/LightNode.js.html +226 -0
- package/coverage/lcov-report/src/nodes/MotionNode.js.html +205 -0
- package/coverage/lcov-report/src/nodes/RelativeRotaryNode.js.html +253 -0
- package/coverage/lcov-report/src/nodes/ResourceNode.js.html +388 -0
- package/coverage/lcov-report/src/nodes/SceneNode.js.html +124 -0
- package/coverage/lcov-report/src/nodes/ServiceNode.js.html +124 -0
- package/coverage/lcov-report/src/nodes/TemperatureNode.js.html +205 -0
- package/coverage/lcov-report/src/nodes/ZigbeeConnectivityNode.js.html +199 -0
- package/coverage/lcov-report/src/nodes/index.html +311 -0
- package/coverage/lcov-report/src/ui/BaseUI.js.html +484 -0
- package/coverage/lcov-report/src/ui/BridgeConfigUI.js.html +475 -0
- package/coverage/lcov-report/src/ui/ButtonUI.js.html +166 -0
- package/coverage/lcov-report/src/ui/DevicePowerUI.js.html +166 -0
- package/coverage/lcov-report/src/ui/GroupedLightUI.js.html +178 -0
- package/coverage/lcov-report/src/ui/LightLevelUI.js.html +166 -0
- package/coverage/lcov-report/src/ui/LightUI.js.html +178 -0
- package/coverage/lcov-report/src/ui/MotionUI.js.html +166 -0
- package/coverage/lcov-report/src/ui/RelativeRotaryUI.js.html +166 -0
- package/coverage/lcov-report/src/ui/ResourceUI.js.html +511 -0
- package/coverage/lcov-report/src/ui/SceneUI.js.html +160 -0
- package/coverage/lcov-report/src/ui/ServiceUI.js.html +868 -0
- package/coverage/lcov-report/src/ui/TemperatureUI.js.html +166 -0
- package/coverage/lcov-report/src/ui/ZigbeeConnectivityUI.js.html +166 -0
- package/coverage/lcov-report/src/ui/index.html +311 -0
- package/coverage/lcov.info +2217 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/coverage/src/RestApi.js.html +499 -0
- package/coverage/src/all.js.html +208 -0
- package/coverage/src/clip/ClipApi.js.html +1183 -0
- package/coverage/src/clip/Resource.js.html +481 -0
- package/coverage/src/clip/index.html +131 -0
- package/coverage/src/debug.js.html +253 -0
- package/coverage/src/files.js.html +118 -0
- package/coverage/src/index.html +116 -0
- package/coverage/src/nodes/BaseNode.js.html +379 -0
- package/coverage/src/nodes/BridgeConfigNode.js.html +517 -0
- package/coverage/src/nodes/ButtonNode.js.html +238 -0
- package/coverage/src/nodes/DevicePowerNode.js.html +196 -0
- package/coverage/src/nodes/GroupedLightNode.js.html +223 -0
- package/coverage/src/nodes/LightLevelNode.js.html +202 -0
- package/coverage/src/nodes/LightNode.js.html +223 -0
- package/coverage/src/nodes/MotionNode.js.html +202 -0
- package/coverage/src/nodes/RelativeRotaryNode.js.html +250 -0
- package/coverage/src/nodes/ResourceNode.js.html +373 -0
- package/coverage/src/nodes/SceneNode.js.html +124 -0
- package/coverage/src/nodes/ServiceNode.js.html +124 -0
- package/coverage/src/nodes/TemperatureNode.js.html +202 -0
- package/coverage/src/nodes/ZigbeeConnectivityNode.js.html +199 -0
- package/coverage/src/nodes/index.html +311 -0
- package/coverage/src/ui/BaseUI.js.html +484 -0
- package/coverage/src/ui/BridgeConfigUI.js.html +475 -0
- package/coverage/src/ui/ButtonUI.js.html +166 -0
- package/coverage/src/ui/DevicePowerUI.js.html +166 -0
- package/coverage/src/ui/GroupedLightUI.js.html +178 -0
- package/coverage/src/ui/LightLevelUI.js.html +166 -0
- package/coverage/src/ui/LightUI.js.html +178 -0
- package/coverage/src/ui/MotionUI.js.html +166 -0
- package/coverage/src/ui/RelativeRotaryUI.js.html +166 -0
- package/coverage/src/ui/ResourceUI.js.html +511 -0
- package/coverage/src/ui/SceneUI.js.html +160 -0
- package/coverage/src/ui/ServiceUI.js.html +868 -0
- package/coverage/src/ui/TemperatureUI.js.html +166 -0
- package/coverage/src/ui/ZigbeeConnectivityUI.js.html +166 -0
- package/coverage/src/ui/index.html +311 -0
- package/examples/flows.json +959 -0
- package/package.json +53 -0
- package/screenshots/Screenshot from 2022-11-29 00-29-23.png +0 -0
- package/screenshots/Screenshot from 2022-11-29 00-30-16.png +0 -0
- package/screenshots/Screenshot from 2022-11-29 00-30-58.png +0 -0
- package/screenshots/Screenshot from 2022-11-29 00-31-29.png +0 -0
- package/src/RestApi.js +138 -0
- package/src/all.html +52 -0
- package/src/all.js +42 -0
- package/src/clip/ClipApi.js +367 -0
- package/src/clip/Resource.js +132 -0
- package/src/debug.js +56 -0
- package/src/files.js +12 -0
- package/src/hue.js +98 -0
- package/src/nodes/BaseNode.js +98 -0
- package/src/nodes/BridgeConfigNode.js +144 -0
- package/src/nodes/ButtonNode.js +51 -0
- package/src/nodes/DevicePowerNode.js +37 -0
- package/src/nodes/GroupedLightNode.js +46 -0
- package/src/nodes/LightLevelNode.js +39 -0
- package/src/nodes/LightNode.js +46 -0
- package/src/nodes/MotionNode.js +39 -0
- package/src/nodes/RelativeRotaryNode.js +55 -0
- package/src/nodes/ResourceNode.js +95 -0
- package/src/nodes/SceneNode.js +13 -0
- package/src/nodes/ServiceNode.js +13 -0
- package/src/nodes/TemperatureNode.js +39 -0
- package/src/nodes/ZigbeeConnectivityNode.js +38 -0
- package/src/ui/BaseUI.js +133 -0
- package/src/ui/BridgeConfigUI.js +130 -0
- package/src/ui/ButtonUI.js +27 -0
- package/src/ui/DevicePowerUI.js +27 -0
- package/src/ui/GroupedLightUI.js +31 -0
- package/src/ui/LightLevelUI.js +27 -0
- package/src/ui/LightUI.js +31 -0
- package/src/ui/MotionUI.js +27 -0
- package/src/ui/RelativeRotaryUI.js +27 -0
- package/src/ui/ResourceUI.js +142 -0
- package/src/ui/SceneUI.js +25 -0
- package/src/ui/ServiceUI.js +261 -0
- package/src/ui/TemperatureUI.js +27 -0
- package/src/ui/ZigbeeConnectivityUI.js +27 -0
- package/test/BaseNode_spec.js +246 -0
- package/test/BaseUI_spec.js +17 -0
- package/test/BridgeConfigNode_spec.js +184 -0
- package/test/ButtonNode_spec.js +178 -0
- package/test/ClipApi_spec.js +769 -0
- package/test/DevicePowerNode_spec.js +186 -0
- package/test/GroupedLightNode_spec.js +218 -0
- package/test/LightLevelNode_spec.js +154 -0
- package/test/LightNode_spec.js +218 -0
- package/test/MotionNode_spec.js +186 -0
- package/test/RelativeRotataryNode_spec.js +325 -0
- package/test/ResourceNode_spec.js +308 -0
- package/test/Resource_spec.js +392 -0
- package/test/SceneNode_spec.js +33 -0
- package/test/ServiceNode_spec.js +33 -0
- package/test/TemperatureNode_spec.js +153 -0
- package/test/ZigbeeConnectivityNode_spec.js +186 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
const helper = require("node-red-node-test-helper");
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const sinon = require('sinon');
|
|
4
|
+
|
|
5
|
+
const testnodes = function(RED) {
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const BaseNode = require('../src/nodes/BaseNode');
|
|
9
|
+
BaseNode.nodeAPI = RED;
|
|
10
|
+
|
|
11
|
+
RED.nodes.registerType("RelativeRotaryNode",RelativeRotaryNode);
|
|
12
|
+
}
|
|
13
|
+
const RelativeRotaryNode = require('../src/nodes/RelativeRotaryNode')
|
|
14
|
+
|
|
15
|
+
describe('RelativeRotaryNode', function () {
|
|
16
|
+
beforeEach(()=>{
|
|
17
|
+
sandbox = sinon.createSandbox();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(function () {
|
|
21
|
+
sandbox.restore();
|
|
22
|
+
helper.unload();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should load', function (done) {
|
|
26
|
+
|
|
27
|
+
var flow = [{
|
|
28
|
+
id: "n1",
|
|
29
|
+
type: "RelativeRotaryNode",
|
|
30
|
+
name: "relative rotary node",
|
|
31
|
+
}];
|
|
32
|
+
|
|
33
|
+
helper.load(testnodes, flow, function () {
|
|
34
|
+
var n1 = helper.getNode("n1");
|
|
35
|
+
n1.should.have.property('config');
|
|
36
|
+
|
|
37
|
+
var config = n1.config;
|
|
38
|
+
config.should.have.property('name', 'relative rotary node');
|
|
39
|
+
done();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should call updateStatus() twice with 3s delay when onUpdate(event) is called', function (done) {
|
|
44
|
+
var statuscount = 0;
|
|
45
|
+
const fakeStatus = sandbox.fake(() => {
|
|
46
|
+
if (statuscount++ > 0) {
|
|
47
|
+
done()
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
sandbox.replace(RelativeRotaryNode.prototype,'updateStatus',fakeStatus);
|
|
51
|
+
|
|
52
|
+
var flow = [{
|
|
53
|
+
id: "n1",
|
|
54
|
+
type: "RelativeRotaryNode",
|
|
55
|
+
name: "relative rotary node",
|
|
56
|
+
}];
|
|
57
|
+
|
|
58
|
+
helper.load(testnodes, flow, function () {
|
|
59
|
+
var n1 = helper.getNode("n1");
|
|
60
|
+
n1.onUpdate({
|
|
61
|
+
name: "event"
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should call status() with "blue/dot/action >> 400 | 400" and "grey/dot/action >> 400 | 400"', function (done) {
|
|
67
|
+
var statuscount = 0;
|
|
68
|
+
const fakeStatus = sandbox.fake(() => {
|
|
69
|
+
var args = fakeStatus.firstArg;
|
|
70
|
+
if (statuscount++ == 0) {
|
|
71
|
+
assert.equal(args.fill,"blue");
|
|
72
|
+
assert.equal(args.shape,"dot");
|
|
73
|
+
assert.equal(args.text,"action >> 400 | 400");
|
|
74
|
+
} else {
|
|
75
|
+
assert.equal(args.fill,"grey");
|
|
76
|
+
assert.equal(args.shape,"dot");
|
|
77
|
+
assert.equal(args.text,"action >> 400 | 400");
|
|
78
|
+
done()
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
sandbox.replace(RelativeRotaryNode.prototype,'status',fakeStatus);
|
|
82
|
+
const fakeResource = sandbox.fake(() => {
|
|
83
|
+
return {
|
|
84
|
+
data: function() {
|
|
85
|
+
return { relative_rotary: {
|
|
86
|
+
last_event: {
|
|
87
|
+
action: "action",
|
|
88
|
+
rotation: {
|
|
89
|
+
direction: "clock_wise",
|
|
90
|
+
duration: 400,
|
|
91
|
+
steps: 400
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
sandbox.replace(RelativeRotaryNode.prototype,'resource',fakeResource);
|
|
99
|
+
|
|
100
|
+
var flow = [{
|
|
101
|
+
id: "n1",
|
|
102
|
+
type: "RelativeRotaryNode",
|
|
103
|
+
name: "relative rotary node",
|
|
104
|
+
}];
|
|
105
|
+
|
|
106
|
+
helper.load(testnodes, flow, function () {
|
|
107
|
+
var n1 = helper.getNode("n1");
|
|
108
|
+
n1.onUpdate({
|
|
109
|
+
relative_rotary: {
|
|
110
|
+
last_event: {
|
|
111
|
+
action: "action",
|
|
112
|
+
rotation: {
|
|
113
|
+
direction: "clock_wise",
|
|
114
|
+
duration: 400,
|
|
115
|
+
steps: 400
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should call status() with "blue/dot/action << 200 | 100" and "grey/dot/action << 200 | 100"', function (done) {
|
|
124
|
+
var statuscount = 0;
|
|
125
|
+
const fakeStatus = sandbox.fake(() => {
|
|
126
|
+
var args = fakeStatus.firstArg;
|
|
127
|
+
if (statuscount++ == 0) {
|
|
128
|
+
assert.equal(args.fill,"blue");
|
|
129
|
+
assert.equal(args.shape,"dot");
|
|
130
|
+
assert.equal(args.text,"action << 200 | 100");
|
|
131
|
+
} else {
|
|
132
|
+
assert.equal(args.fill,"grey");
|
|
133
|
+
assert.equal(args.shape,"dot");
|
|
134
|
+
assert.equal(args.text,"action << 200 | 100");
|
|
135
|
+
done()
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
sandbox.replace(RelativeRotaryNode.prototype,'status',fakeStatus);
|
|
139
|
+
const fakeResource = sandbox.fake(() => {
|
|
140
|
+
return {
|
|
141
|
+
data: function() {
|
|
142
|
+
return { relative_rotary: {
|
|
143
|
+
last_event: {
|
|
144
|
+
action: "action",
|
|
145
|
+
rotation: {
|
|
146
|
+
direction: "counter_clock_wise",
|
|
147
|
+
duration: 200,
|
|
148
|
+
steps: 100
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
sandbox.replace(RelativeRotaryNode.prototype,'resource',fakeResource);
|
|
156
|
+
|
|
157
|
+
var flow = [{
|
|
158
|
+
id: "n1",
|
|
159
|
+
type: "RelativeRotaryNode",
|
|
160
|
+
name: "relative rotary node",
|
|
161
|
+
}];
|
|
162
|
+
|
|
163
|
+
helper.load(testnodes, flow, function () {
|
|
164
|
+
var n1 = helper.getNode("n1");
|
|
165
|
+
n1.onUpdate({
|
|
166
|
+
relative_rotary: {
|
|
167
|
+
last_event: {
|
|
168
|
+
action: "action",
|
|
169
|
+
rotation: {
|
|
170
|
+
direction: "clock_wise",
|
|
171
|
+
duration: 400,
|
|
172
|
+
steps: 400
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should call status() with "blue/dot/" and "grey/dot/" when resource==null', function (done) {
|
|
181
|
+
var statuscount = 0;
|
|
182
|
+
const fakeStatus = sandbox.fake(() => {
|
|
183
|
+
var args = fakeStatus.firstArg;
|
|
184
|
+
if (statuscount++ == 0) {
|
|
185
|
+
assert.equal(args.fill,"blue");
|
|
186
|
+
assert.equal(args.shape,"dot");
|
|
187
|
+
assert.equal(args.text,"");
|
|
188
|
+
} else {
|
|
189
|
+
assert.equal(args.fill,"grey");
|
|
190
|
+
assert.equal(args.shape,"dot");
|
|
191
|
+
assert.equal(args.text,"");
|
|
192
|
+
done()
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
sandbox.replace(RelativeRotaryNode.prototype,'status',fakeStatus);
|
|
196
|
+
const fakeResource = sandbox.fake(() => {
|
|
197
|
+
return null
|
|
198
|
+
});
|
|
199
|
+
sandbox.replace(RelativeRotaryNode.prototype,'resource',fakeResource);
|
|
200
|
+
|
|
201
|
+
var flow = [{
|
|
202
|
+
id: "n1",
|
|
203
|
+
type: "RelativeRotaryNode",
|
|
204
|
+
name: "relative rotary node",
|
|
205
|
+
}];
|
|
206
|
+
|
|
207
|
+
helper.load(testnodes, flow, function () {
|
|
208
|
+
var n1 = helper.getNode("n1");
|
|
209
|
+
n1.onUpdate({
|
|
210
|
+
relative_rotary: {
|
|
211
|
+
last_event: {
|
|
212
|
+
action: "action",
|
|
213
|
+
rotation: {
|
|
214
|
+
direction: "clock_wise",
|
|
215
|
+
duration: 400,
|
|
216
|
+
steps: 400
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
it('should call status() with "blue/dot/" and "grey/dot/" when last_event==null', function (done) {
|
|
224
|
+
var statuscount = 0;
|
|
225
|
+
const fakeStatus = sandbox.fake(() => {
|
|
226
|
+
var args = fakeStatus.firstArg;
|
|
227
|
+
if (statuscount++ == 0) {
|
|
228
|
+
assert.equal(args.fill,"blue");
|
|
229
|
+
assert.equal(args.shape,"dot");
|
|
230
|
+
assert.equal(args.text,"");
|
|
231
|
+
} else {
|
|
232
|
+
assert.equal(args.fill,"grey");
|
|
233
|
+
assert.equal(args.shape,"dot");
|
|
234
|
+
assert.equal(args.text,"");
|
|
235
|
+
done()
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
sandbox.replace(RelativeRotaryNode.prototype,'status',fakeStatus);
|
|
239
|
+
const fakeResource = sandbox.fake(() => {
|
|
240
|
+
return {
|
|
241
|
+
data: function() {
|
|
242
|
+
return { relative_rotary: {
|
|
243
|
+
last_event: null
|
|
244
|
+
}}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
sandbox.replace(RelativeRotaryNode.prototype,'resource',fakeResource);
|
|
249
|
+
|
|
250
|
+
var flow = [{
|
|
251
|
+
id: "n1",
|
|
252
|
+
type: "RelativeRotaryNode",
|
|
253
|
+
name: "relative rotary node",
|
|
254
|
+
}];
|
|
255
|
+
|
|
256
|
+
helper.load(testnodes, flow, function () {
|
|
257
|
+
var n1 = helper.getNode("n1");
|
|
258
|
+
n1.onUpdate({
|
|
259
|
+
relative_rotary: {
|
|
260
|
+
last_event: {
|
|
261
|
+
action: "action",
|
|
262
|
+
rotation: {
|
|
263
|
+
direction: "clock_wise",
|
|
264
|
+
duration: 400,
|
|
265
|
+
steps: 400
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('should call status() with "blue/dot/action" and "grey/dot/action" when rotation==null', function (done) {
|
|
274
|
+
var statuscount = 0;
|
|
275
|
+
const fakeStatus = sandbox.fake(() => {
|
|
276
|
+
var args = fakeStatus.firstArg;
|
|
277
|
+
if (statuscount++ == 0) {
|
|
278
|
+
assert.equal(args.fill,"blue");
|
|
279
|
+
assert.equal(args.shape,"dot");
|
|
280
|
+
assert.equal(args.text,"action");
|
|
281
|
+
} else {
|
|
282
|
+
assert.equal(args.fill,"grey");
|
|
283
|
+
assert.equal(args.shape,"dot");
|
|
284
|
+
assert.equal(args.text,"action");
|
|
285
|
+
done()
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
sandbox.replace(RelativeRotaryNode.prototype,'status',fakeStatus);
|
|
289
|
+
const fakeResource = sandbox.fake(() => {
|
|
290
|
+
return {
|
|
291
|
+
data: function() {
|
|
292
|
+
return { relative_rotary: {
|
|
293
|
+
last_event: {
|
|
294
|
+
action: "action",
|
|
295
|
+
rotation: null
|
|
296
|
+
}
|
|
297
|
+
}}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
sandbox.replace(RelativeRotaryNode.prototype,'resource',fakeResource);
|
|
302
|
+
|
|
303
|
+
var flow = [{
|
|
304
|
+
id: "n1",
|
|
305
|
+
type: "RelativeRotaryNode",
|
|
306
|
+
name: "relative rotary node",
|
|
307
|
+
}];
|
|
308
|
+
|
|
309
|
+
helper.load(testnodes, flow, function () {
|
|
310
|
+
var n1 = helper.getNode("n1");
|
|
311
|
+
n1.onUpdate({
|
|
312
|
+
relative_rotary: {
|
|
313
|
+
last_event: {
|
|
314
|
+
action: "action",
|
|
315
|
+
rotation: {
|
|
316
|
+
direction: "clock_wise",
|
|
317
|
+
duration: 400,
|
|
318
|
+
steps: 400
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
});
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
var helper = require("node-red-node-test-helper");
|
|
2
|
+
const BaseNode = require('../src/nodes/BaseNode');
|
|
3
|
+
const ResourceNode = require("../src/nodes/ResourceNode");
|
|
4
|
+
const assert = require('assert');
|
|
5
|
+
const sinon = require('sinon');
|
|
6
|
+
|
|
7
|
+
var testnodes = function(RED) {
|
|
8
|
+
"use strict";
|
|
9
|
+
BaseNode.nodeAPI = RED;
|
|
10
|
+
RED.nodes.registerType("ResourceNode",ResourceNode);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('Resource Node', function () {
|
|
14
|
+
beforeEach(()=>{
|
|
15
|
+
sandbox = sinon.createSandbox();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(function () {
|
|
19
|
+
helper.unload();
|
|
20
|
+
sandbox.restore();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should be loaded', function (done) {
|
|
24
|
+
var flow = [{
|
|
25
|
+
id: "n1",
|
|
26
|
+
type: "ResourceNode",
|
|
27
|
+
name: "resource node",
|
|
28
|
+
}];
|
|
29
|
+
|
|
30
|
+
helper.load(testnodes, flow, function () {
|
|
31
|
+
var n1 = helper.getNode("n1");
|
|
32
|
+
var config = n1.config;
|
|
33
|
+
config.should.have.property('name', 'resource node');
|
|
34
|
+
done();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should call bridge.requestStartup on construction', function (done) {
|
|
39
|
+
const fake = sandbox.fake(() => {
|
|
40
|
+
return {
|
|
41
|
+
requestStartup: function(resource) {
|
|
42
|
+
done();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fake);
|
|
47
|
+
|
|
48
|
+
var flow = [{
|
|
49
|
+
id: "n1",
|
|
50
|
+
type: "ResourceNode",
|
|
51
|
+
}];
|
|
52
|
+
|
|
53
|
+
helper.load(testnodes, flow, function () {
|
|
54
|
+
helper.getNode("n1");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should call on("update") when start() is called', function (done) {
|
|
59
|
+
var flow = [{
|
|
60
|
+
id: "n1",
|
|
61
|
+
type: "ResourceNode",
|
|
62
|
+
}];
|
|
63
|
+
|
|
64
|
+
const fake = sandbox.fake(() => {
|
|
65
|
+
return {
|
|
66
|
+
requestStartup: function(resource) {}
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fake);
|
|
70
|
+
|
|
71
|
+
helper.load(testnodes, flow, function () {
|
|
72
|
+
var n1 = helper.getNode("n1");
|
|
73
|
+
n1.start({
|
|
74
|
+
on: function(event,callback) {
|
|
75
|
+
assert.equal(event,'update');
|
|
76
|
+
done();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should call updateStatus() when start() is called', function (done) {
|
|
83
|
+
var flow = [{
|
|
84
|
+
id: "n1",
|
|
85
|
+
type: "ResourceNode",
|
|
86
|
+
}];
|
|
87
|
+
|
|
88
|
+
const fakeRequestStartup = sandbox.fake(() => {
|
|
89
|
+
return { requestStartup: function(resource) {} };
|
|
90
|
+
});
|
|
91
|
+
const fakeUpdateStatus = sandbox.fake(() => {
|
|
92
|
+
done();
|
|
93
|
+
});
|
|
94
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fakeRequestStartup);
|
|
95
|
+
sandbox.replace(ResourceNode.prototype,'updateStatus',fakeUpdateStatus);
|
|
96
|
+
|
|
97
|
+
helper.load(testnodes, flow, function () {
|
|
98
|
+
var n1 = helper.getNode("n1");
|
|
99
|
+
n1.start({
|
|
100
|
+
on: function(event,callback) {
|
|
101
|
+
assert.equal(event,'update');
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should return resource provided in start(resource) call when resource() is called', function (done) {
|
|
108
|
+
var flow = [{
|
|
109
|
+
id: "n1",
|
|
110
|
+
type: "ResourceNode",
|
|
111
|
+
}];
|
|
112
|
+
|
|
113
|
+
const fake = sandbox.fake(() => {
|
|
114
|
+
return { requestStartup: function(resource) {} };
|
|
115
|
+
});
|
|
116
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fake);
|
|
117
|
+
|
|
118
|
+
helper.load(testnodes, flow, function () {
|
|
119
|
+
var n1 = helper.getNode("n1");
|
|
120
|
+
n1.start({
|
|
121
|
+
on: function(event,callback) {
|
|
122
|
+
assert.equal(event,'update');
|
|
123
|
+
},
|
|
124
|
+
data: function() { return { name: "test resource" } }
|
|
125
|
+
});
|
|
126
|
+
var resource = n1.resource();
|
|
127
|
+
assert.equal(resource.data().name, "test resource");
|
|
128
|
+
done();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should return uuid provided in config when rid() is called', function (done) {
|
|
133
|
+
var uuid = "c9f1b449-d9de-41c6-8bd4-46368eedd447";
|
|
134
|
+
var flow = [{
|
|
135
|
+
id: "n1",
|
|
136
|
+
type: "ResourceNode",
|
|
137
|
+
uuid: uuid
|
|
138
|
+
}];
|
|
139
|
+
|
|
140
|
+
const fake = sandbox.fake(() => {
|
|
141
|
+
return { requestStartup: function(resource) {} };
|
|
142
|
+
});
|
|
143
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fake);
|
|
144
|
+
|
|
145
|
+
helper.load(testnodes, flow, function () {
|
|
146
|
+
var n1 = helper.getNode("n1");
|
|
147
|
+
var rid = n1.rid();
|
|
148
|
+
assert.equal(rid,uuid);
|
|
149
|
+
done();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Todo:
|
|
154
|
+
// - bridge()
|
|
155
|
+
|
|
156
|
+
it('should call send() when onUpdate(event) is called', function (done) {
|
|
157
|
+
var uuid = "c9f1b449-d9de-41c6-8bd4-46368eedd447";
|
|
158
|
+
var flow = [{
|
|
159
|
+
id: "n1",
|
|
160
|
+
type: "ResourceNode",
|
|
161
|
+
wires: [["n2"]]
|
|
162
|
+
},{
|
|
163
|
+
id: "n2",
|
|
164
|
+
type: "helper"
|
|
165
|
+
}];
|
|
166
|
+
|
|
167
|
+
helper.load(testnodes, flow, function () {
|
|
168
|
+
var n1 = helper.getNode("n1");
|
|
169
|
+
var n2 = helper.getNode("n2");
|
|
170
|
+
n2.on("input", function (msg) {
|
|
171
|
+
done();
|
|
172
|
+
});
|
|
173
|
+
n1.onUpdate({ name: "event" });
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should call resource.put when onInput(msg) is called and msg.rtypes contains matching type', function (done) {
|
|
178
|
+
var flow = [{
|
|
179
|
+
id: "n1",
|
|
180
|
+
type: "ResourceNode",
|
|
181
|
+
name: "resource node",
|
|
182
|
+
}];
|
|
183
|
+
|
|
184
|
+
const fake = sandbox.fake(() => {
|
|
185
|
+
return { requestStartup: function(resource) {} };
|
|
186
|
+
});
|
|
187
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fake);
|
|
188
|
+
|
|
189
|
+
helper.load(testnodes, flow, function () {
|
|
190
|
+
var n1 = helper.getNode("n1");
|
|
191
|
+
n1.start({
|
|
192
|
+
on: function(event,callback) {
|
|
193
|
+
assert.equal(event,'update');
|
|
194
|
+
},
|
|
195
|
+
rtype: function() { return "button" },
|
|
196
|
+
put: function(msg) { done(); }
|
|
197
|
+
});
|
|
198
|
+
n1.receive({ rtypes: ["button"], payload: {} });
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should call resource.put when onInput(msg) is called and msg.rids contains matching rid', function (done) {
|
|
203
|
+
var flow = [{
|
|
204
|
+
id: "n1",
|
|
205
|
+
type: "ResourceNode",
|
|
206
|
+
name: "resource node",
|
|
207
|
+
uuid: "1c0fb40c-41af-4ed3-a2e0-552398dbd0d8"
|
|
208
|
+
}];
|
|
209
|
+
|
|
210
|
+
const fake = sandbox.fake(() => {
|
|
211
|
+
return { requestStartup: function(resource) {} };
|
|
212
|
+
});
|
|
213
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fake);
|
|
214
|
+
|
|
215
|
+
helper.load(testnodes, flow, function () {
|
|
216
|
+
var n1 = helper.getNode("n1");
|
|
217
|
+
n1.start({
|
|
218
|
+
on: function(event,callback) {
|
|
219
|
+
assert.equal(event,'update');
|
|
220
|
+
},
|
|
221
|
+
rid: function() { return "1c0fb40c-41af-4ed3-a2e0-552398dbd0d8" },
|
|
222
|
+
put: function(msg) { done(); }
|
|
223
|
+
});
|
|
224
|
+
n1.receive({ rids: ["1c0fb40c-41af-4ed3-a2e0-552398dbd0d8"], payload: {} });
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('should not call resource.put when onInput(msg) is called and msg.rids contains no matching rid', function (done) {
|
|
229
|
+
var flow = [{
|
|
230
|
+
id: "n1",
|
|
231
|
+
type: "ResourceNode",
|
|
232
|
+
name: "resource node",
|
|
233
|
+
uuid: "1c0fb40c-41af-4ed3-a2e0-552398dbd0d8"
|
|
234
|
+
}];
|
|
235
|
+
|
|
236
|
+
const fake = sandbox.fake(() => {
|
|
237
|
+
return { requestStartup: function(resource) {} };
|
|
238
|
+
});
|
|
239
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fake);
|
|
240
|
+
|
|
241
|
+
helper.load(testnodes, flow, function () {
|
|
242
|
+
var n1 = helper.getNode("n1");
|
|
243
|
+
n1.start({
|
|
244
|
+
on: function(event,callback) {
|
|
245
|
+
assert.equal(event,'update');
|
|
246
|
+
},
|
|
247
|
+
rid: function() { return "1c0fb40c-41af-4ed3-a2e0-552398dbd0d8" },
|
|
248
|
+
put: function(msg) { assert.fail('did not expect resource.put() to be called'); }
|
|
249
|
+
});
|
|
250
|
+
n1.receive({ rids: ["4157244d-f3ba-4fa3-857b-b946b3d661ce"], payload: {} });
|
|
251
|
+
setTimeout(() => {
|
|
252
|
+
done();
|
|
253
|
+
}, 0);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('should not call resource.put when onInput(msg) is called and msg.rtypes contains no matching type', function (done) {
|
|
258
|
+
var flow = [{
|
|
259
|
+
id: "n1",
|
|
260
|
+
type: "ResourceNode",
|
|
261
|
+
name: "resource node",
|
|
262
|
+
uuid: "1c0fb40c-41af-4ed3-a2e0-552398dbd0d8"
|
|
263
|
+
}];
|
|
264
|
+
|
|
265
|
+
const fake = sandbox.fake(() => {
|
|
266
|
+
return { requestStartup: function(resource) {} };
|
|
267
|
+
});
|
|
268
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fake);
|
|
269
|
+
|
|
270
|
+
helper.load(testnodes, flow, function () {
|
|
271
|
+
var n1 = helper.getNode("n1");
|
|
272
|
+
n1.start({
|
|
273
|
+
on: function(event,callback) {
|
|
274
|
+
assert.equal(event,'update');
|
|
275
|
+
},
|
|
276
|
+
rtype: function() { return "button" },
|
|
277
|
+
put: function(msg) { assert.fail('did not expect resource.put() to be called'); }
|
|
278
|
+
});
|
|
279
|
+
n1.receive({ rtypes: ["light"], payload: {} });
|
|
280
|
+
setTimeout(() => {
|
|
281
|
+
done();
|
|
282
|
+
}, 0);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('should not call resource.put when onInput(msg) is called and resource==null', function (done) {
|
|
287
|
+
var flow = [{
|
|
288
|
+
id: "n1",
|
|
289
|
+
type: "ResourceNode",
|
|
290
|
+
name: "resource node",
|
|
291
|
+
uuid: "1c0fb40c-41af-4ed3-a2e0-552398dbd0d8"
|
|
292
|
+
}];
|
|
293
|
+
|
|
294
|
+
const fake = sandbox.fake(() => {
|
|
295
|
+
return { requestStartup: function(resource) {} };
|
|
296
|
+
});
|
|
297
|
+
sandbox.replace(ResourceNode.prototype,'bridge',fake);
|
|
298
|
+
|
|
299
|
+
helper.load(testnodes, flow, function () {
|
|
300
|
+
var n1 = helper.getNode("n1");
|
|
301
|
+
n1.start(null);
|
|
302
|
+
n1.receive({ rtypes: ["light"], payload: {} });
|
|
303
|
+
setTimeout(() => {
|
|
304
|
+
done();
|
|
305
|
+
}, 0);
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
});
|