@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,186 @@
|
|
|
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("DevicePowerNode",DevicePowerNode);
|
|
12
|
+
}
|
|
13
|
+
const DevicePowerNode = require('../src/nodes/DevicePowerNode');
|
|
14
|
+
const { isNull } = require("util");
|
|
15
|
+
|
|
16
|
+
describe('DevicePowerNode', function () {
|
|
17
|
+
beforeEach(()=>{
|
|
18
|
+
sandbox = sinon.createSandbox();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(function () {
|
|
22
|
+
sandbox.restore();
|
|
23
|
+
helper.unload();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should load', function (done) {
|
|
27
|
+
var flow = [{
|
|
28
|
+
id: "n1",
|
|
29
|
+
type: "DevicePowerNode",
|
|
30
|
+
name: "device power 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', 'device power node');
|
|
39
|
+
done();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should call updateStatus() when onUpdate(event) is called', function (done) {
|
|
44
|
+
const fakeStatus = sandbox.fake(() => {
|
|
45
|
+
done()
|
|
46
|
+
});
|
|
47
|
+
sandbox.replace(DevicePowerNode.prototype,'updateStatus',fakeStatus);
|
|
48
|
+
|
|
49
|
+
var flow = [{
|
|
50
|
+
id: "n1",
|
|
51
|
+
type: "DevicePowerNode",
|
|
52
|
+
name: "device power node",
|
|
53
|
+
}];
|
|
54
|
+
|
|
55
|
+
helper.load(testnodes, flow, function () {
|
|
56
|
+
var n1 = helper.getNode("n1");
|
|
57
|
+
n1.onUpdate({
|
|
58
|
+
name: "event"
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should call status() with "green/dot/90%"', function (done) {
|
|
64
|
+
const fakeResource = sandbox.fake.returns({
|
|
65
|
+
data: function() {
|
|
66
|
+
return { power_state: { battery_level: 90 } }
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
sandbox.replace(DevicePowerNode.prototype,'resource',fakeResource);
|
|
70
|
+
const fakeStatus = sandbox.fake(() => {
|
|
71
|
+
|
|
72
|
+
args = fakeStatus.firstArg;
|
|
73
|
+
assert.equal(args.fill,"green");
|
|
74
|
+
assert.equal(args.shape,"dot");
|
|
75
|
+
assert.equal(args.text,"90%");
|
|
76
|
+
|
|
77
|
+
done()
|
|
78
|
+
});
|
|
79
|
+
sandbox.replace(DevicePowerNode.prototype,'status',fakeStatus);
|
|
80
|
+
|
|
81
|
+
var flow = [{
|
|
82
|
+
id: "n1",
|
|
83
|
+
type: "DevicePowerNode",
|
|
84
|
+
name: "device power node",
|
|
85
|
+
}];
|
|
86
|
+
|
|
87
|
+
helper.load(testnodes, flow, function () {
|
|
88
|
+
var n1 = helper.getNode("n1");
|
|
89
|
+
n1.onUpdate({
|
|
90
|
+
power_state: { battery_level: 90 }
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should call status() with "red/dot/5%"', function (done) {
|
|
96
|
+
const fakeResource = sandbox.fake.returns({
|
|
97
|
+
data: function() {
|
|
98
|
+
return { power_state: { battery_level: 5 } }
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
sandbox.replace(DevicePowerNode.prototype,'resource',fakeResource);
|
|
102
|
+
const fakeStatus = sandbox.fake(() => {
|
|
103
|
+
|
|
104
|
+
args = fakeStatus.firstArg;
|
|
105
|
+
assert.equal(args.fill,"red");
|
|
106
|
+
assert.equal(args.shape,"dot");
|
|
107
|
+
assert.equal(args.text,"5%");
|
|
108
|
+
|
|
109
|
+
done()
|
|
110
|
+
});
|
|
111
|
+
sandbox.replace(DevicePowerNode.prototype,'status',fakeStatus);
|
|
112
|
+
|
|
113
|
+
var flow = [{
|
|
114
|
+
id: "n1",
|
|
115
|
+
type: "DevicePowerNode",
|
|
116
|
+
name: "device power node",
|
|
117
|
+
}];
|
|
118
|
+
|
|
119
|
+
helper.load(testnodes, flow, function () {
|
|
120
|
+
var n1 = helper.getNode("n1");
|
|
121
|
+
n1.onUpdate({
|
|
122
|
+
power_state: { battery_level: 5 }
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should call status() with "grey/dot/" when resource==null', function (done) {
|
|
128
|
+
const fakeResource = sandbox.fake.returns(null);
|
|
129
|
+
sandbox.replace(DevicePowerNode.prototype,'resource',fakeResource);
|
|
130
|
+
const fakeStatus = sandbox.fake(() => {
|
|
131
|
+
|
|
132
|
+
args = fakeStatus.firstArg;
|
|
133
|
+
assert.equal(args.fill,"grey");
|
|
134
|
+
assert.equal(args.shape,"dot");
|
|
135
|
+
assert.equal(args.text,"");
|
|
136
|
+
|
|
137
|
+
done()
|
|
138
|
+
});
|
|
139
|
+
sandbox.replace(DevicePowerNode.prototype,'status',fakeStatus);
|
|
140
|
+
|
|
141
|
+
var flow = [{
|
|
142
|
+
id: "n1",
|
|
143
|
+
type: "DevicePowerNode",
|
|
144
|
+
name: "device power node",
|
|
145
|
+
}];
|
|
146
|
+
|
|
147
|
+
helper.load(testnodes, flow, function () {
|
|
148
|
+
var n1 = helper.getNode("n1");
|
|
149
|
+
n1.onUpdate({
|
|
150
|
+
power_state: { battery_level: 90 }
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should call status() with "grey/dot/" when battery_level==null', function (done) {
|
|
156
|
+
const fakeResource = sandbox.fake.returns({
|
|
157
|
+
data: function() {
|
|
158
|
+
return { power_state: { battery_level: null } }
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
sandbox.replace(DevicePowerNode.prototype,'resource',fakeResource);
|
|
162
|
+
const fakeStatus = sandbox.fake(() => {
|
|
163
|
+
|
|
164
|
+
args = fakeStatus.firstArg;
|
|
165
|
+
assert.equal(args.fill,"grey");
|
|
166
|
+
assert.equal(args.shape,"dot");
|
|
167
|
+
assert.equal(args.text,"");
|
|
168
|
+
|
|
169
|
+
done()
|
|
170
|
+
});
|
|
171
|
+
sandbox.replace(DevicePowerNode.prototype,'status',fakeStatus);
|
|
172
|
+
|
|
173
|
+
var flow = [{
|
|
174
|
+
id: "n1",
|
|
175
|
+
type: "DevicePowerNode",
|
|
176
|
+
name: "device power node",
|
|
177
|
+
}];
|
|
178
|
+
|
|
179
|
+
helper.load(testnodes, flow, function () {
|
|
180
|
+
var n1 = helper.getNode("n1");
|
|
181
|
+
n1.onUpdate({
|
|
182
|
+
power_state: { battery_level: 90 }
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -0,0 +1,218 @@
|
|
|
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("GroupedLightNode",GroupedLightNode);
|
|
12
|
+
}
|
|
13
|
+
const GroupedLightNode = require('../src/nodes/GroupedLightNode');
|
|
14
|
+
const { isNull } = require("util");
|
|
15
|
+
|
|
16
|
+
describe('GroupedLightNode', function () {
|
|
17
|
+
beforeEach(()=>{
|
|
18
|
+
sandbox = sinon.createSandbox();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(function () {
|
|
22
|
+
sandbox.restore();
|
|
23
|
+
helper.unload();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should load', function (done) {
|
|
27
|
+
var flow = [{
|
|
28
|
+
id: "n1",
|
|
29
|
+
type: "GroupedLightNode",
|
|
30
|
+
name: "grouped light 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', 'grouped light node');
|
|
39
|
+
done();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should call updateStatus() when onUpdate(event) is called', function (done) {
|
|
44
|
+
const fakeStatus = sandbox.fake(() => {
|
|
45
|
+
done()
|
|
46
|
+
});
|
|
47
|
+
sandbox.replace(GroupedLightNode.prototype,'updateStatus',fakeStatus);
|
|
48
|
+
|
|
49
|
+
var flow = [{
|
|
50
|
+
id: "n1",
|
|
51
|
+
type: "GroupedLightNode",
|
|
52
|
+
name: "grouped light node",
|
|
53
|
+
}];
|
|
54
|
+
|
|
55
|
+
helper.load(testnodes, flow, function () {
|
|
56
|
+
var n1 = helper.getNode("n1");
|
|
57
|
+
n1.onUpdate({
|
|
58
|
+
name: "event"
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should call status() with "yellow/dot/90%" when on==true and brightness==90', function (done) {
|
|
64
|
+
const fakeResource = sandbox.fake.returns({
|
|
65
|
+
data: function() {
|
|
66
|
+
return { on: { on: true }, dimming: { brightness: 90 } }
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
sandbox.replace(GroupedLightNode.prototype,'resource',fakeResource);
|
|
70
|
+
const fakeStatus = sandbox.fake(() => {
|
|
71
|
+
|
|
72
|
+
args = fakeStatus.firstArg;
|
|
73
|
+
assert.equal(args.fill,"yellow");
|
|
74
|
+
assert.equal(args.shape,"dot");
|
|
75
|
+
assert.equal(args.text,"90%");
|
|
76
|
+
|
|
77
|
+
done()
|
|
78
|
+
});
|
|
79
|
+
sandbox.replace(GroupedLightNode.prototype,'status',fakeStatus);
|
|
80
|
+
|
|
81
|
+
var flow = [{
|
|
82
|
+
id: "n1",
|
|
83
|
+
type: "GroupedLightNode",
|
|
84
|
+
name: "grouped light node",
|
|
85
|
+
}];
|
|
86
|
+
|
|
87
|
+
helper.load(testnodes, flow, function () {
|
|
88
|
+
var n1 = helper.getNode("n1");
|
|
89
|
+
n1.onUpdate({
|
|
90
|
+
on: { on: true }, dimming: { brightness: 90 }
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should call status() with "grey/dot/off" when on==false and brightness==90', function (done) {
|
|
96
|
+
const fakeResource = sandbox.fake.returns({
|
|
97
|
+
data: function() {
|
|
98
|
+
return { on: { on: false }, dimming: { brightness: 90 } }
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
sandbox.replace(GroupedLightNode.prototype,'resource',fakeResource);
|
|
102
|
+
const fakeStatus = sandbox.fake(() => {
|
|
103
|
+
|
|
104
|
+
args = fakeStatus.firstArg;
|
|
105
|
+
assert.equal(args.fill,"grey");
|
|
106
|
+
assert.equal(args.shape,"dot");
|
|
107
|
+
assert.equal(args.text,"off");
|
|
108
|
+
|
|
109
|
+
done()
|
|
110
|
+
});
|
|
111
|
+
sandbox.replace(GroupedLightNode.prototype,'status',fakeStatus);
|
|
112
|
+
|
|
113
|
+
var flow = [{
|
|
114
|
+
id: "n1",
|
|
115
|
+
type: "GroupedLightNode",
|
|
116
|
+
name: "grouped light node",
|
|
117
|
+
}];
|
|
118
|
+
|
|
119
|
+
helper.load(testnodes, flow, function () {
|
|
120
|
+
var n1 = helper.getNode("n1");
|
|
121
|
+
n1.onUpdate({
|
|
122
|
+
on: { on: false }, dimming: { brightness: 90 }
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should call status() with "grey/dot/" when resource==null', function (done) {
|
|
128
|
+
const fakeResource = sandbox.fake.returns(null);
|
|
129
|
+
sandbox.replace(GroupedLightNode.prototype,'resource',fakeResource);
|
|
130
|
+
const fakeStatus = sandbox.fake(() => {
|
|
131
|
+
|
|
132
|
+
args = fakeStatus.firstArg;
|
|
133
|
+
assert.equal(args.fill,"grey");
|
|
134
|
+
assert.equal(args.shape,"dot");
|
|
135
|
+
assert.equal(args.text,"");
|
|
136
|
+
|
|
137
|
+
done()
|
|
138
|
+
});
|
|
139
|
+
sandbox.replace(GroupedLightNode.prototype,'status',fakeStatus);
|
|
140
|
+
|
|
141
|
+
var flow = [{
|
|
142
|
+
id: "n1",
|
|
143
|
+
type: "GroupedLightNode",
|
|
144
|
+
name: "grouped light node",
|
|
145
|
+
}];
|
|
146
|
+
|
|
147
|
+
helper.load(testnodes, flow, function () {
|
|
148
|
+
var n1 = helper.getNode("n1");
|
|
149
|
+
n1.onUpdate({
|
|
150
|
+
on: { on: true }, dimming: { brightness: 90 }
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should call status() with "grey/dot/" when on==null', function (done) {
|
|
156
|
+
const fakeResource = sandbox.fake.returns({
|
|
157
|
+
data: function() {
|
|
158
|
+
return { on: { on: null }, dimming: { brightness: 90 } }
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
sandbox.replace(GroupedLightNode.prototype,'resource',fakeResource);
|
|
162
|
+
const fakeStatus = sandbox.fake(() => {
|
|
163
|
+
|
|
164
|
+
args = fakeStatus.firstArg;
|
|
165
|
+
assert.equal(args.fill,"grey");
|
|
166
|
+
assert.equal(args.shape,"dot");
|
|
167
|
+
assert.equal(args.text,"");
|
|
168
|
+
|
|
169
|
+
done()
|
|
170
|
+
});
|
|
171
|
+
sandbox.replace(GroupedLightNode.prototype,'status',fakeStatus);
|
|
172
|
+
|
|
173
|
+
var flow = [{
|
|
174
|
+
id: "n1",
|
|
175
|
+
type: "GroupedLightNode",
|
|
176
|
+
name: "grouped light node",
|
|
177
|
+
}];
|
|
178
|
+
|
|
179
|
+
helper.load(testnodes, flow, function () {
|
|
180
|
+
var n1 = helper.getNode("n1");
|
|
181
|
+
n1.onUpdate({
|
|
182
|
+
on: { on: true }, dimming: { brightness: 90 }
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('should call status() with "yellow/dot/" when dimming==null', function (done) {
|
|
188
|
+
const fakeResource = sandbox.fake.returns({
|
|
189
|
+
data: function() {
|
|
190
|
+
return { on: { on: true }, dimming: null }
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
sandbox.replace(GroupedLightNode.prototype,'resource',fakeResource);
|
|
194
|
+
const fakeStatus = sandbox.fake(() => {
|
|
195
|
+
args = fakeStatus.firstArg;
|
|
196
|
+
|
|
197
|
+
assert.equal(args.fill,"yellow");
|
|
198
|
+
assert.equal(args.shape,"dot");
|
|
199
|
+
assert.equal(args.text,"");
|
|
200
|
+
|
|
201
|
+
done();
|
|
202
|
+
});
|
|
203
|
+
sandbox.replace(GroupedLightNode.prototype,'status',fakeStatus);
|
|
204
|
+
|
|
205
|
+
var flow = [{
|
|
206
|
+
id: "n1",
|
|
207
|
+
type: "GroupedLightNode",
|
|
208
|
+
name: "grouped light node",
|
|
209
|
+
}];
|
|
210
|
+
|
|
211
|
+
helper.load(testnodes, flow, function () {
|
|
212
|
+
var n1 = helper.getNode("n1");
|
|
213
|
+
n1.onUpdate({
|
|
214
|
+
on: { on: true }, dimming: { brightness: 90 }
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
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("LightLevelNode",LightLevelNode);
|
|
12
|
+
}
|
|
13
|
+
const LightLevelNode = require('../src/nodes/LightLevelNode');
|
|
14
|
+
const { isNull } = require("util");
|
|
15
|
+
|
|
16
|
+
describe('LightLevelNode', function () {
|
|
17
|
+
beforeEach(()=>{
|
|
18
|
+
sandbox = sinon.createSandbox();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(function () {
|
|
22
|
+
sandbox.restore();
|
|
23
|
+
helper.unload();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should load', function (done) {
|
|
27
|
+
var flow = [{
|
|
28
|
+
id: "n1",
|
|
29
|
+
type: "LightLevelNode",
|
|
30
|
+
name: "light level 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', 'light level node');
|
|
39
|
+
done();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should call updateStatus() when onUpdate(event) is called', function (done) {
|
|
44
|
+
const fakeStatus = sandbox.fake(() => {
|
|
45
|
+
done()
|
|
46
|
+
});
|
|
47
|
+
sandbox.replace(LightLevelNode.prototype,'updateStatus',fakeStatus);
|
|
48
|
+
|
|
49
|
+
var flow = [{
|
|
50
|
+
id: "n1",
|
|
51
|
+
type: "LightLevelNode",
|
|
52
|
+
name: "light level node",
|
|
53
|
+
}];
|
|
54
|
+
|
|
55
|
+
helper.load(testnodes, flow, function () {
|
|
56
|
+
var n1 = helper.getNode("n1");
|
|
57
|
+
n1.onUpdate({
|
|
58
|
+
name: "event"
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should call status() with "green/dot/12345"', function (done) {
|
|
64
|
+
const fakeResource = sandbox.fake.returns({
|
|
65
|
+
data: function() {
|
|
66
|
+
return { light: { light_level: 12345 } }
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
sandbox.replace(LightLevelNode.prototype,'resource',fakeResource);
|
|
70
|
+
const fakeStatus = sandbox.fake(() => {
|
|
71
|
+
args = fakeStatus.firstArg;
|
|
72
|
+
|
|
73
|
+
assert.equal(args.fill,"green");
|
|
74
|
+
assert.equal(args.shape,"dot");
|
|
75
|
+
assert.equal(args.text,"12345");
|
|
76
|
+
|
|
77
|
+
done()
|
|
78
|
+
});
|
|
79
|
+
sandbox.replace(LightLevelNode.prototype,'status',fakeStatus);
|
|
80
|
+
|
|
81
|
+
var flow = [{
|
|
82
|
+
id: "n1",
|
|
83
|
+
type: "LightLevelNode",
|
|
84
|
+
name: "light level node",
|
|
85
|
+
}];
|
|
86
|
+
|
|
87
|
+
helper.load(testnodes, flow, function () {
|
|
88
|
+
var n1 = helper.getNode("n1");
|
|
89
|
+
n1.onUpdate({
|
|
90
|
+
light: { light_level: 12345 }
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should call status() with "grey/dot/" when resource==null', function (done) {
|
|
96
|
+
const fakeResource = sandbox.fake.returns(null);
|
|
97
|
+
sandbox.replace(LightLevelNode.prototype,'resource',fakeResource);
|
|
98
|
+
const fakeStatus = sandbox.fake(() => {
|
|
99
|
+
|
|
100
|
+
args = fakeStatus.firstArg;
|
|
101
|
+
assert.equal(args.fill,"grey");
|
|
102
|
+
assert.equal(args.shape,"dot");
|
|
103
|
+
assert.equal(args.text,"");
|
|
104
|
+
|
|
105
|
+
done()
|
|
106
|
+
});
|
|
107
|
+
sandbox.replace(LightLevelNode.prototype,'status',fakeStatus);
|
|
108
|
+
|
|
109
|
+
var flow = [{
|
|
110
|
+
id: "n1",
|
|
111
|
+
type: "LightLevelNode",
|
|
112
|
+
name: "light level node",
|
|
113
|
+
}];
|
|
114
|
+
|
|
115
|
+
helper.load(testnodes, flow, function () {
|
|
116
|
+
var n1 = helper.getNode("n1");
|
|
117
|
+
n1.onUpdate({
|
|
118
|
+
light: { light_level: 12345 }
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should call status() with "grey/dot/" when light_level==null', function (done) {
|
|
124
|
+
const fakeResource = sandbox.fake.returns({
|
|
125
|
+
data: function() {
|
|
126
|
+
return { light: { light_level: null } }
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
sandbox.replace(LightLevelNode.prototype,'resource',fakeResource);
|
|
130
|
+
const fakeStatus = sandbox.fake(() => {
|
|
131
|
+
|
|
132
|
+
args = fakeStatus.firstArg;
|
|
133
|
+
assert.equal(args.fill,"grey");
|
|
134
|
+
assert.equal(args.shape,"dot");
|
|
135
|
+
assert.equal(args.text,"");
|
|
136
|
+
|
|
137
|
+
done()
|
|
138
|
+
});
|
|
139
|
+
sandbox.replace(LightLevelNode.prototype,'status',fakeStatus);
|
|
140
|
+
|
|
141
|
+
var flow = [{
|
|
142
|
+
id: "n1",
|
|
143
|
+
type: "LightLevelNode",
|
|
144
|
+
name: "light level node",
|
|
145
|
+
}];
|
|
146
|
+
|
|
147
|
+
helper.load(testnodes, flow, function () {
|
|
148
|
+
var n1 = helper.getNode("n1");
|
|
149
|
+
n1.onUpdate({
|
|
150
|
+
light: { light_level: 12345 }
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|