node-red-contrib-alice 2.2.4 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +11 -0
- package/CLAUDE.md +54 -0
- package/nodes/alice-color.js +208 -231
- package/nodes/alice-device.html +6 -1
- package/nodes/alice-device.js +252 -286
- package/nodes/alice-event.js +110 -114
- package/nodes/alice-get.html +91 -0
- package/nodes/alice-get.js +9 -0
- 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.html +0 -2
- 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 +127 -122
- package/nodes/types.js +3 -0
- package/package.json +22 -8
- 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.html +67 -6
- 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.html +242 -0
- package/src/alice.ts +146 -0
- package/src/types.ts +157 -0
- package/tsconfig.json +13 -106
- package/.eslintrc.json +0 -20
package/nodes/alice-onoff.js
CHANGED
|
@@ -1,131 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function AliceOnOff(config){
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
response = true;
|
|
23
|
-
};
|
|
24
|
-
if (config.split === undefined){
|
|
25
|
-
split = false;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
29
|
-
|
|
30
|
-
this.init = ()=>{
|
|
31
|
-
this.debug("Starting capability initilization ...");
|
|
32
|
-
let capab = {
|
|
33
|
-
type: ctype,
|
|
34
|
-
retrievable: true,
|
|
35
|
-
reportable: true,
|
|
36
|
-
parameters: {
|
|
37
|
-
instance: instance,
|
|
38
|
-
split: split
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = (RED) => {
|
|
3
|
+
function AliceOnOff(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 ctype = 'devices.capabilities.on_off';
|
|
9
|
+
const instance = 'on';
|
|
10
|
+
let response = config.response;
|
|
11
|
+
let split = config.split;
|
|
12
|
+
let initState = false;
|
|
13
|
+
const curentState = {
|
|
14
|
+
type: ctype,
|
|
15
|
+
state: {
|
|
16
|
+
instance: instance,
|
|
17
|
+
value: false
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
if (config.response === undefined) {
|
|
21
|
+
response = true;
|
|
39
22
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
23
|
+
if (config.split === undefined) {
|
|
24
|
+
split = false;
|
|
25
|
+
}
|
|
26
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
27
|
+
const init = () => {
|
|
28
|
+
this.debug("Starting capability initilization ...");
|
|
29
|
+
const capab = {
|
|
30
|
+
type: ctype,
|
|
31
|
+
retrievable: true,
|
|
32
|
+
reportable: true,
|
|
33
|
+
parameters: {
|
|
34
|
+
instance: instance,
|
|
35
|
+
split: split
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
device.setCapability(id, capab)
|
|
39
|
+
.then(() => {
|
|
40
|
+
this.debug("Capability initilization - success!");
|
|
41
|
+
initState = true;
|
|
42
|
+
this.status({ fill: "green", shape: "dot", text: "online" });
|
|
43
|
+
})
|
|
44
|
+
.catch(err => {
|
|
45
|
+
this.error("Error on create capability: " + err.message);
|
|
46
|
+
this.status({ fill: "red", shape: "dot", text: "error" });
|
|
47
|
+
});
|
|
48
|
+
device.updateCapabState(id, curentState)
|
|
49
|
+
.then(() => {
|
|
50
|
+
this.status({ fill: "green", shape: "dot", text: "online" });
|
|
51
|
+
})
|
|
52
|
+
.catch(err => {
|
|
53
|
+
this.error("Error on update capability state: " + err.message);
|
|
54
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
if (device.initState)
|
|
58
|
+
init();
|
|
59
|
+
device.on("online", () => {
|
|
60
|
+
init();
|
|
61
|
+
});
|
|
62
|
+
device.on("offline", () => {
|
|
63
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
64
|
+
});
|
|
65
|
+
device.on(id, (val) => {
|
|
66
|
+
this.send({ payload: val });
|
|
67
|
+
if (response) {
|
|
68
|
+
curentState.state.value = val;
|
|
69
|
+
device.updateCapabState(id, curentState)
|
|
70
|
+
.then(() => {
|
|
71
|
+
this.status({ fill: "green", shape: "dot", text: val.toString() });
|
|
72
|
+
})
|
|
73
|
+
.catch(err => {
|
|
74
|
+
this.error("Error on update capability state: " + err.message);
|
|
75
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
this.on('input', (msg, _send, done) => {
|
|
80
|
+
if (typeof msg.payload != 'boolean') {
|
|
81
|
+
this.error("Wrong type! msg.payload must be boolean.");
|
|
82
|
+
if (done) {
|
|
83
|
+
done();
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (msg.payload === curentState.state.value) {
|
|
88
|
+
this.debug("Value not changed. Cancel update");
|
|
89
|
+
if (done) {
|
|
90
|
+
done();
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
curentState.state.value = msg.payload;
|
|
95
|
+
device.updateCapabState(id, curentState)
|
|
96
|
+
.then(() => {
|
|
97
|
+
this.status({ fill: "green", shape: "dot", text: String(msg.payload) });
|
|
98
|
+
if (done) {
|
|
99
|
+
done();
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
.catch(err => {
|
|
103
|
+
this.error("Error on update capability state: " + err.message);
|
|
104
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
105
|
+
if (done) {
|
|
106
|
+
done();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
this.on('close', (removed, done) => {
|
|
111
|
+
device.setMaxListeners(device.getMaxListeners() - 1);
|
|
112
|
+
if (removed) {
|
|
113
|
+
device.delCapability(id)
|
|
114
|
+
.then(() => { done(); })
|
|
115
|
+
.catch(err => {
|
|
116
|
+
this.error("Error on delete capability: " + err.message);
|
|
117
|
+
done();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
done();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
RED.nodes.registerType("On_Off", AliceOnOff);
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=alice-onoff.js.map
|
package/nodes/alice-range.js
CHANGED
|
@@ -1,153 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (config.response === undefined){
|
|
21
|
-
this.response = true;
|
|
22
|
-
};
|
|
23
|
-
if (typeof this.min != 'number'){this.min = 0};
|
|
24
|
-
if (typeof this.max != 'number'){this.max = 100};
|
|
25
|
-
if (typeof this.precision != 'number'){this.precision = 1};
|
|
26
|
-
|
|
27
|
-
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
28
|
-
|
|
29
|
-
this.init = ()=>{
|
|
30
|
-
let capab = {
|
|
31
|
-
type: this.ctype,
|
|
32
|
-
retrievable: this.retrievable,
|
|
33
|
-
reportable: true,
|
|
34
|
-
parameters: {
|
|
35
|
-
instance: this.instance,
|
|
36
|
-
unit: this.unit,
|
|
37
|
-
random_access: this.random_access,
|
|
38
|
-
range: {
|
|
39
|
-
min: this.min,
|
|
40
|
-
max: this.max,
|
|
41
|
-
precision: this.precision
|
|
42
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = (RED) => {
|
|
3
|
+
function AliceRange(config) {
|
|
4
|
+
RED.nodes.createNode(this, config);
|
|
5
|
+
const device = RED.nodes.getNode(config.device);
|
|
6
|
+
device.setMaxListeners(device.getMaxListeners() + 1);
|
|
7
|
+
const ctype = 'devices.capabilities.range';
|
|
8
|
+
const retrievable = config.retrievable;
|
|
9
|
+
const instance = config.instance || '';
|
|
10
|
+
const unit = config.unit;
|
|
11
|
+
const random_access = true;
|
|
12
|
+
let min = parseFloat(config.min);
|
|
13
|
+
let max = parseFloat(config.max);
|
|
14
|
+
let precision = parseFloat(config.precision);
|
|
15
|
+
let response = config.response;
|
|
16
|
+
let value = null;
|
|
17
|
+
if (config.response === undefined) {
|
|
18
|
+
response = true;
|
|
43
19
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (this.unit == "unit.number"){
|
|
47
|
-
delete capab.parameters.unit;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
this.device.setCapability(this.id,capab)
|
|
51
|
-
.then(res=>{
|
|
52
|
-
this.initState = true;
|
|
53
|
-
this.status({fill:"green",shape:"dot",text:"online"});
|
|
54
|
-
})
|
|
55
|
-
.catch(err=>{
|
|
56
|
-
this.error("Error on create capability: " + err.message);
|
|
57
|
-
this.status({fill:"red",shape:"dot",text:"error"});
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Проверяем сам девайс уже инициирован
|
|
62
|
-
if (this.device.initState) this.init();
|
|
63
|
-
|
|
64
|
-
this.device.on("online",()=>{
|
|
65
|
-
this.init();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
this.device.on("offline",()=>{
|
|
69
|
-
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
this.device.on(this.id,(val, fullstate)=>{
|
|
73
|
-
let value = val;
|
|
74
|
-
//проверка является ли значение относительным и нужно ли отдавать полное значение
|
|
75
|
-
if (fullstate.relative && this.retrievable){
|
|
76
|
-
value = this.value + val;
|
|
77
|
-
if (val<0 && value<this.min) value=this.min;
|
|
78
|
-
if (val>0 && value>this.max) value=this.max;
|
|
79
|
-
};
|
|
80
|
-
this.send({
|
|
81
|
-
payload: value
|
|
82
|
-
});
|
|
83
|
-
let state= {
|
|
84
|
-
type:this.ctype,
|
|
85
|
-
state:{
|
|
86
|
-
instance: this.instance,
|
|
87
|
-
value: value
|
|
20
|
+
if (typeof min != 'number' || isNaN(min)) {
|
|
21
|
+
min = 0;
|
|
88
22
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (this.response){
|
|
92
|
-
this.device.updateCapabState(this.id,state)
|
|
93
|
-
.then (res=>{
|
|
94
|
-
this.value = value;
|
|
95
|
-
this.status({fill:"green",shape:"dot",text:"online"});
|
|
96
|
-
})
|
|
97
|
-
.catch(err=>{
|
|
98
|
-
this.error("Error on update capability state: " + err.message);
|
|
99
|
-
this.status({fill:"red",shape:"dot",text:"Error"});
|
|
100
|
-
})
|
|
101
|
-
};
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
this.on('input', (msg, send, done)=>{
|
|
105
|
-
const value = msg.payload;
|
|
106
|
-
if (typeof value != 'number'){
|
|
107
|
-
this.error("Wrong type! msg.payload must be Number.");
|
|
108
|
-
if (done) {done();}
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (value === this.value){
|
|
112
|
-
this.debug("Value not changed. Cancel update");
|
|
113
|
-
if (done) {done();}
|
|
114
|
-
return;
|
|
115
|
-
};
|
|
116
|
-
let state= {
|
|
117
|
-
type:this.ctype,
|
|
118
|
-
state:{
|
|
119
|
-
instance: this.instance,
|
|
120
|
-
value: value
|
|
23
|
+
if (typeof max != 'number' || isNaN(max)) {
|
|
24
|
+
max = 100;
|
|
121
25
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
26
|
+
if (typeof precision != 'number' || isNaN(precision)) {
|
|
27
|
+
precision = 1;
|
|
28
|
+
}
|
|
29
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
30
|
+
const init = () => {
|
|
31
|
+
const parameters = {
|
|
32
|
+
instance: instance,
|
|
33
|
+
unit: unit,
|
|
34
|
+
random_access: random_access,
|
|
35
|
+
range: { min, max, precision }
|
|
36
|
+
};
|
|
37
|
+
if (unit == "unit.number") {
|
|
38
|
+
delete parameters.unit;
|
|
39
|
+
}
|
|
40
|
+
device.setCapability(this.id, {
|
|
41
|
+
type: ctype,
|
|
42
|
+
retrievable: retrievable,
|
|
43
|
+
reportable: true,
|
|
44
|
+
parameters: parameters
|
|
45
|
+
})
|
|
46
|
+
.then(() => {
|
|
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
|
+
if (device.initState)
|
|
55
|
+
init();
|
|
56
|
+
device.on("online", () => {
|
|
57
|
+
init();
|
|
58
|
+
});
|
|
59
|
+
device.on("offline", () => {
|
|
60
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
61
|
+
});
|
|
62
|
+
device.on(this.id, (val, fullstate) => {
|
|
63
|
+
let newValue = val;
|
|
64
|
+
if (fullstate.relative && retrievable && value !== null) {
|
|
65
|
+
newValue = value + val;
|
|
66
|
+
if (val < 0 && newValue < min)
|
|
67
|
+
newValue = min;
|
|
68
|
+
if (val > 0 && newValue > max)
|
|
69
|
+
newValue = max;
|
|
70
|
+
}
|
|
71
|
+
this.send({ payload: newValue });
|
|
72
|
+
const state = {
|
|
73
|
+
type: ctype,
|
|
74
|
+
state: {
|
|
75
|
+
instance: instance,
|
|
76
|
+
value: newValue
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
if (response) {
|
|
80
|
+
device.updateCapabState(this.id, state)
|
|
81
|
+
.then(() => {
|
|
82
|
+
value = newValue;
|
|
83
|
+
this.status({ fill: "green", shape: "dot", text: "online" });
|
|
84
|
+
})
|
|
85
|
+
.catch(err => {
|
|
86
|
+
this.error("Error on update capability state: " + err.message);
|
|
87
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
this.on('input', (msg, _send, done) => {
|
|
92
|
+
const newValue = msg.payload;
|
|
93
|
+
if (typeof newValue != 'number') {
|
|
94
|
+
this.error("Wrong type! msg.payload must be Number.");
|
|
95
|
+
if (done) {
|
|
96
|
+
done();
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (newValue === value) {
|
|
101
|
+
this.debug("Value not changed. Cancel update");
|
|
102
|
+
if (done) {
|
|
103
|
+
done();
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const state = {
|
|
108
|
+
type: ctype,
|
|
109
|
+
state: {
|
|
110
|
+
instance: instance,
|
|
111
|
+
value: newValue
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
device.updateCapabState(this.id, state)
|
|
115
|
+
.then(() => {
|
|
116
|
+
value = newValue;
|
|
117
|
+
this.status({ fill: "green", shape: "dot", text: String(newValue) });
|
|
118
|
+
if (done) {
|
|
119
|
+
done();
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
.catch(err => {
|
|
123
|
+
this.error("Error on update capability state: " + err.message);
|
|
124
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
125
|
+
if (done) {
|
|
126
|
+
done();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
this.on('close', (removed, done) => {
|
|
131
|
+
device.setMaxListeners(device.getMaxListeners() - 1);
|
|
132
|
+
if (removed) {
|
|
133
|
+
device.delCapability(this.id)
|
|
134
|
+
.then(() => { done(); })
|
|
135
|
+
.catch(err => {
|
|
136
|
+
this.error("Error on delete capability: " + err.message);
|
|
137
|
+
done();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
done();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
RED.nodes.registerType("Range", AliceRange);
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=alice-range.js.map
|