node-red-contrib-alice 2.2.5 → 2.3.1
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.
Potentially problematic release.
This version of node-red-contrib-alice might be problematic. Click here for more details.
- package/.claude/settings.local.json +11 -0
- package/CLAUDE.md +54 -0
- package/nodes/alice-color.js +208 -231
- package/nodes/alice-device.js +252 -286
- package/nodes/alice-event.js +110 -114
- package/nodes/alice-get.js +2 -3
- package/nodes/alice-mode.js +136 -145
- package/nodes/alice-onoff.js +126 -130
- package/nodes/alice-range.js +144 -150
- package/nodes/alice-sensor.js +101 -106
- package/nodes/alice-togle.js +118 -125
- package/nodes/alice-video.js +88 -132
- package/nodes/alice.js +11 -18
- package/nodes/types.js +3 -0
- package/package.json +2 -7
- package/src/alice-color.html +255 -0
- package/src/alice-color.ts +227 -0
- package/src/alice-device.html +94 -0
- package/src/alice-device.ts +301 -0
- package/src/alice-event.html +148 -0
- package/src/alice-event.ts +112 -0
- package/src/alice-get.ts +12 -15
- package/src/alice-mode.html +296 -0
- package/src/alice-mode.ts +139 -0
- package/src/alice-onoff.html +93 -0
- package/src/alice-onoff.ts +132 -0
- package/src/alice-range.html +293 -0
- package/src/alice-range.ts +144 -0
- package/src/alice-sensor.html +307 -0
- package/src/alice-sensor.ts +103 -0
- package/src/alice-togle.html +96 -0
- package/src/alice-togle.ts +122 -0
- package/src/alice-video.html +90 -0
- package/src/alice-video.ts +99 -0
- package/src/alice.ts +98 -248
- package/src/types.ts +157 -0
- package/tsconfig.json +13 -106
- package/.eslintrc.json +0 -20
package/nodes/alice-event.js
CHANGED
|
@@ -1,115 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function AliceEvent(config){
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = (RED) => {
|
|
3
|
+
function AliceEvent(config) {
|
|
4
|
+
RED.nodes.createNode(this, config);
|
|
5
|
+
const device = RED.nodes.getNode(config.device);
|
|
6
|
+
device.setMaxListeners(device.getMaxListeners() + 1);
|
|
7
|
+
const id = JSON.parse(JSON.stringify(this.id));
|
|
8
|
+
const stype = 'devices.properties.event';
|
|
9
|
+
const instance = config.instance;
|
|
10
|
+
const events = config.events;
|
|
11
|
+
let initState = false;
|
|
12
|
+
const curentState = {
|
|
13
|
+
type: stype,
|
|
14
|
+
state: {
|
|
15
|
+
instance: instance,
|
|
16
|
+
value: ''
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
20
|
+
const init = () => {
|
|
21
|
+
this.debug("Starting sensor initilization ...");
|
|
22
|
+
const objEvents = events.map(v => ({ value: v }));
|
|
23
|
+
const sensor = {
|
|
24
|
+
type: stype,
|
|
25
|
+
reportable: true,
|
|
26
|
+
retrievable: false,
|
|
27
|
+
parameters: {
|
|
28
|
+
instance: instance,
|
|
29
|
+
events: objEvents
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
device.setSensor(id, sensor)
|
|
33
|
+
.then(() => {
|
|
34
|
+
this.debug("Sensor initilization - success!");
|
|
35
|
+
this.status({ fill: "green", shape: "dot", text: "online" });
|
|
36
|
+
initState = true;
|
|
37
|
+
})
|
|
38
|
+
.catch(err => {
|
|
39
|
+
this.error("Error on create sensor: " + err.message);
|
|
40
|
+
this.status({ fill: "red", shape: "dot", text: "error" });
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
if (device.initState)
|
|
44
|
+
init();
|
|
45
|
+
device.on("online", () => {
|
|
46
|
+
if (!initState) {
|
|
47
|
+
init();
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.status({ fill: "green", shape: "dot", text: curentState.state.value });
|
|
51
|
+
}
|
|
49
52
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
})
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}else{
|
|
110
|
-
done();
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
RED.nodes.registerType("Event",AliceEvent);
|
|
115
|
-
};
|
|
53
|
+
device.on("offline", () => {
|
|
54
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
55
|
+
});
|
|
56
|
+
this.on('input', (msg, _send, done) => {
|
|
57
|
+
if (!events.includes(msg.payload)) {
|
|
58
|
+
this.error("Wrong type! msg.payload must be from the list of allowed events.");
|
|
59
|
+
if (done) {
|
|
60
|
+
done();
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (curentState.state.value == msg.payload) {
|
|
65
|
+
this.debug("Value not changed. Cancel update");
|
|
66
|
+
if (done) {
|
|
67
|
+
done();
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
curentState.state.value = msg.payload;
|
|
73
|
+
}
|
|
74
|
+
if (instance == 'button') {
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
curentState.state.value = null;
|
|
77
|
+
this.status({ fill: "green", shape: "dot", text: "" });
|
|
78
|
+
}, 1000);
|
|
79
|
+
}
|
|
80
|
+
device.updateSensorState(id, curentState)
|
|
81
|
+
.then(() => {
|
|
82
|
+
this.status({ fill: "green", shape: "dot", text: curentState.state.value });
|
|
83
|
+
if (done) {
|
|
84
|
+
done();
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
.catch(err => {
|
|
88
|
+
this.error("Error on update sensor state: " + err.message);
|
|
89
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
90
|
+
if (done) {
|
|
91
|
+
done();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
this.on('close', (removed, done) => {
|
|
96
|
+
if (removed) {
|
|
97
|
+
device.delSensor(id)
|
|
98
|
+
.then(() => { done(); })
|
|
99
|
+
.catch(err => {
|
|
100
|
+
this.error("Error on delete property: " + err.message);
|
|
101
|
+
done();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
done();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
RED.nodes.registerType("Event", AliceEvent);
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=alice-event.js.map
|
package/nodes/alice-get.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
;
|
|
3
2
|
module.exports = (RED) => {
|
|
4
3
|
function AliceGet(config) {
|
|
5
4
|
RED.nodes.createNode(this, config);
|
|
6
|
-
const
|
|
5
|
+
const _service = RED.nodes.getNode(config.service);
|
|
7
6
|
}
|
|
8
|
-
;
|
|
9
7
|
RED.nodes.registerType("Alice-Get", AliceGet);
|
|
10
8
|
};
|
|
9
|
+
//# sourceMappingURL=alice-get.js.map
|
package/nodes/alice-mode.js
CHANGED
|
@@ -1,146 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.initState = false;
|
|
14
|
-
this.value;
|
|
15
|
-
|
|
16
|
-
if (config.response === undefined){
|
|
17
|
-
this.response = true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
this.init = _=>{
|
|
21
|
-
if (this.modes.length<1){
|
|
22
|
-
this.status({fill:"red",shape:"dot",text:"error"});
|
|
23
|
-
this.error("In the list of supported commands, there must be at least one command");
|
|
24
|
-
return;
|
|
25
|
-
};
|
|
26
|
-
if (!this.instance){
|
|
27
|
-
this.status({fill:"red",shape:"dot",text:"error"});
|
|
28
|
-
this.error("Mode type not selected");
|
|
29
|
-
return;
|
|
30
|
-
};
|
|
31
|
-
var cfgModes = [];
|
|
32
|
-
this.modes.forEach(v=>{
|
|
33
|
-
cfgModes.push({value:v});
|
|
34
|
-
});
|
|
35
|
-
let capab = {
|
|
36
|
-
type: this.ctype,
|
|
37
|
-
retrievable: this.retrievable,
|
|
38
|
-
reportable: true,
|
|
39
|
-
parameters: {
|
|
40
|
-
instance: this.instance,
|
|
41
|
-
modes: cfgModes
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
this.device.setCapability(this.id,capab)
|
|
45
|
-
.then(res=>{
|
|
46
|
-
this.initState = true;
|
|
47
|
-
this.status({fill:"green",shape:"dot",text:"online"});
|
|
48
|
-
})
|
|
49
|
-
.catch(err=>{
|
|
50
|
-
this.error("Error on create capability: " + err.message);
|
|
51
|
-
this.status({fill:"red",shape:"dot",text:"error"});
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Проверяем сам девайс уже инициирован
|
|
56
|
-
if (this.device.initState) this.init();
|
|
57
|
-
|
|
58
|
-
this.device.on("online",()=>{
|
|
59
|
-
this.init();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
this.device.on("offline",()=>{
|
|
63
|
-
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
this.device.on(this.id,(val,fullstate)=>{
|
|
67
|
-
let value = val;
|
|
68
|
-
this.send({
|
|
69
|
-
payload: value
|
|
70
|
-
});
|
|
71
|
-
let state= {
|
|
72
|
-
type:this.ctype,
|
|
73
|
-
state:{
|
|
74
|
-
instance: this.instance,
|
|
75
|
-
value: value
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = (RED) => {
|
|
3
|
+
function AliceMode(config) {
|
|
4
|
+
RED.nodes.createNode(this, config);
|
|
5
|
+
const device = RED.nodes.getNode(config.device);
|
|
6
|
+
const ctype = 'devices.capabilities.mode';
|
|
7
|
+
const instance = config.instance || '';
|
|
8
|
+
const modes = config.modes;
|
|
9
|
+
let response = config.response;
|
|
10
|
+
let value;
|
|
11
|
+
if (config.response === undefined) {
|
|
12
|
+
response = true;
|
|
76
13
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
})
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
14
|
+
const init = () => {
|
|
15
|
+
if (modes.length < 1) {
|
|
16
|
+
this.status({ fill: "red", shape: "dot", text: "error" });
|
|
17
|
+
this.error("In the list of supported commands, there must be at least one command");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!instance) {
|
|
21
|
+
this.status({ fill: "red", shape: "dot", text: "error" });
|
|
22
|
+
this.error("Mode type not selected");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const cfgModes = modes.map(v => ({ value: v }));
|
|
26
|
+
const capab = {
|
|
27
|
+
type: ctype,
|
|
28
|
+
retrievable: true,
|
|
29
|
+
reportable: true,
|
|
30
|
+
parameters: {
|
|
31
|
+
instance: instance,
|
|
32
|
+
modes: cfgModes
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
device.setCapability(this.id, capab)
|
|
36
|
+
.then(() => {
|
|
37
|
+
this.status({ fill: "green", shape: "dot", text: "online" });
|
|
38
|
+
})
|
|
39
|
+
.catch(err => {
|
|
40
|
+
this.error("Error on create capability: " + err.message);
|
|
41
|
+
this.status({ fill: "red", shape: "dot", text: "error" });
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
if (device.initState)
|
|
45
|
+
init();
|
|
46
|
+
device.on("online", () => {
|
|
47
|
+
init();
|
|
48
|
+
});
|
|
49
|
+
device.on("offline", () => {
|
|
50
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
51
|
+
});
|
|
52
|
+
device.on(this.id, (val) => {
|
|
53
|
+
this.send({ payload: val });
|
|
54
|
+
const state = {
|
|
55
|
+
type: ctype,
|
|
56
|
+
state: {
|
|
57
|
+
instance: instance,
|
|
58
|
+
value: val
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
if (response) {
|
|
62
|
+
device.updateCapabState(this.id, state)
|
|
63
|
+
.then(() => {
|
|
64
|
+
value = val;
|
|
65
|
+
this.status({ fill: "green", shape: "dot", text: "online" });
|
|
66
|
+
})
|
|
67
|
+
.catch(err => {
|
|
68
|
+
this.error("Error on update capability state: " + err.message);
|
|
69
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
this.on('input', (msg, _send, done) => {
|
|
74
|
+
const newValue = msg.payload;
|
|
75
|
+
if (typeof newValue != 'string') {
|
|
76
|
+
this.error("Wrong type! msg.payload must be String.");
|
|
77
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
78
|
+
if (done) {
|
|
79
|
+
done();
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (modes.indexOf(newValue) < 0) {
|
|
84
|
+
this.error("Error! Unsupported command.");
|
|
85
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
86
|
+
if (done) {
|
|
87
|
+
done();
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (newValue === value) {
|
|
92
|
+
this.debug("Value not changed. Cancel update");
|
|
93
|
+
if (done) {
|
|
94
|
+
done();
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const state = {
|
|
99
|
+
type: ctype,
|
|
100
|
+
state: {
|
|
101
|
+
instance: instance,
|
|
102
|
+
value: newValue
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
device.updateCapabState(this.id, state)
|
|
106
|
+
.then(() => {
|
|
107
|
+
value = newValue;
|
|
108
|
+
this.status({ fill: "green", shape: "dot", text: newValue });
|
|
109
|
+
if (done) {
|
|
110
|
+
done();
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
.catch(err => {
|
|
114
|
+
this.error("Error on update capability state: " + err.message);
|
|
115
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
116
|
+
if (done) {
|
|
117
|
+
done();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
this.on('close', (removed, done) => {
|
|
122
|
+
if (removed) {
|
|
123
|
+
device.delCapability(this.id)
|
|
124
|
+
.then(() => { done(); })
|
|
125
|
+
.catch(err => {
|
|
126
|
+
this.error("Error on delete capability: " + err.message);
|
|
127
|
+
done();
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
done();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
RED.nodes.registerType("Mode", AliceMode);
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=alice-mode.js.map
|