node-red-contrib-alice 2.2.5 → 2.3.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/.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 +105 -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 +108 -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-sensor.js
CHANGED
|
@@ -1,107 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function AliceSensor(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
|
-
this.status({fill:"red",shape:"dot",text:"error"});
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = (RED) => {
|
|
3
|
+
function AliceSensor(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 = config.stype;
|
|
9
|
+
const unit = config.unit;
|
|
10
|
+
const instance = config.instance;
|
|
11
|
+
const curentState = {
|
|
12
|
+
type: stype,
|
|
13
|
+
state: {
|
|
14
|
+
instance: instance,
|
|
15
|
+
value: 0
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
let lastUpdateTime = 0;
|
|
19
|
+
const UPDATE_INTERVAL = 10 * 60 * 1000;
|
|
20
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
21
|
+
const init = () => {
|
|
22
|
+
this.debug("Starting sensor initilization ...");
|
|
23
|
+
const sensor = {
|
|
24
|
+
type: stype,
|
|
25
|
+
reportable: true,
|
|
26
|
+
retrievable: true,
|
|
27
|
+
parameters: {
|
|
28
|
+
instance: instance,
|
|
29
|
+
unit: unit
|
|
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
|
+
})
|
|
37
|
+
.catch(err => {
|
|
38
|
+
this.error("Error on create sensor: " + err.message);
|
|
39
|
+
this.status({ fill: "red", shape: "dot", text: "error" });
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
if (device.initState)
|
|
43
|
+
init();
|
|
44
|
+
device.on("online", () => {
|
|
45
|
+
init();
|
|
47
46
|
});
|
|
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
|
-
|
|
47
|
+
device.on("offline", () => {
|
|
48
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
49
|
+
});
|
|
50
|
+
this.on('input', (msg, _send, done) => {
|
|
51
|
+
if (typeof msg.payload != 'number') {
|
|
52
|
+
this.error("Wrong type! msg.payload must be number.");
|
|
53
|
+
if (done) {
|
|
54
|
+
done();
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (unit == 'unit.temperature.celsius' || unit == 'unit.ampere' || unit == 'unit.pressure.bar') {
|
|
59
|
+
msg.payload = +msg.payload.toFixed(1);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
msg.payload = +msg.payload.toFixed(0);
|
|
63
|
+
}
|
|
64
|
+
const timeSinceLastUpdate = Date.now() - lastUpdateTime;
|
|
65
|
+
if (curentState.state.value == msg.payload && timeSinceLastUpdate < UPDATE_INTERVAL) {
|
|
66
|
+
this.debug("Value not changed. Cancel update");
|
|
67
|
+
if (done) {
|
|
68
|
+
done();
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
curentState.state.value = msg.payload;
|
|
73
|
+
lastUpdateTime = Date.now();
|
|
74
|
+
device.updateSensorState(id, curentState)
|
|
75
|
+
.then(() => {
|
|
76
|
+
this.status({ fill: "green", shape: "dot", text: String(msg.payload) });
|
|
77
|
+
if (done) {
|
|
78
|
+
done();
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
.catch(err => {
|
|
82
|
+
this.error("Error on update sensor state: " + err.message);
|
|
83
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
84
|
+
if (done) {
|
|
85
|
+
done();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
this.on('close', (removed, done) => {
|
|
90
|
+
if (removed) {
|
|
91
|
+
device.delSensor(id)
|
|
92
|
+
.then(() => { done(); })
|
|
93
|
+
.catch(err => {
|
|
94
|
+
this.error("Error on delete property: " + err.message);
|
|
95
|
+
done();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
device.setMaxListeners(device.getMaxListeners() - 1);
|
|
100
|
+
done();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
RED.nodes.registerType("Sensor", AliceSensor);
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=alice-sensor.js.map
|
package/nodes/alice-togle.js
CHANGED
|
@@ -1,127 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (config.response === undefined){
|
|
15
|
-
this.response = true;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
19
|
-
|
|
20
|
-
this.init = ()=>{
|
|
21
|
-
this.debug("Starting capability initilization ...");
|
|
22
|
-
let capab = {
|
|
23
|
-
type: this.ctype,
|
|
24
|
-
retrievable: true,
|
|
25
|
-
reportable: true,
|
|
26
|
-
parameters: {
|
|
27
|
-
instance: this.instance,
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = (RED) => {
|
|
3
|
+
function AliceToggle(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.toggle';
|
|
8
|
+
const instance = config.instance || '';
|
|
9
|
+
let response = config.response;
|
|
10
|
+
let value = false;
|
|
11
|
+
if (config.response === undefined) {
|
|
12
|
+
response = true;
|
|
28
13
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
14
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
15
|
+
const init = () => {
|
|
16
|
+
this.debug("Starting capability initilization ...");
|
|
17
|
+
const capab = {
|
|
18
|
+
type: ctype,
|
|
19
|
+
retrievable: true,
|
|
20
|
+
reportable: true,
|
|
21
|
+
parameters: {
|
|
22
|
+
instance: instance,
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
device.setCapability(this.id, capab)
|
|
26
|
+
.then(() => {
|
|
27
|
+
this.debug("Capability initilization - success!");
|
|
28
|
+
this.status({ fill: "green", shape: "dot", text: "online" });
|
|
29
|
+
})
|
|
30
|
+
.catch(err => {
|
|
31
|
+
this.error("Error on create capability: " + err.message);
|
|
32
|
+
this.status({ fill: "red", shape: "dot", text: "error" });
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
if (device.initState)
|
|
36
|
+
init();
|
|
37
|
+
device.on("online", () => {
|
|
38
|
+
init();
|
|
40
39
|
});
|
|
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
|
-
this.
|
|
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
|
-
this.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
done();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
RED.nodes.registerType("Toggle",AliceToggle);
|
|
127
|
-
};
|
|
40
|
+
device.on("offline", () => {
|
|
41
|
+
this.status({ fill: "red", shape: "dot", text: "offline" });
|
|
42
|
+
});
|
|
43
|
+
device.on(this.id, (val) => {
|
|
44
|
+
this.debug("Received a new value from Yandex...");
|
|
45
|
+
this.send({ payload: val });
|
|
46
|
+
const state = {
|
|
47
|
+
type: ctype,
|
|
48
|
+
state: {
|
|
49
|
+
instance: instance,
|
|
50
|
+
value: val
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
if (response) {
|
|
54
|
+
this.debug("Automatic confirmation is true, sending confirmation to Yandex ...");
|
|
55
|
+
device.updateCapabState(this.id, state)
|
|
56
|
+
.then(() => {
|
|
57
|
+
value = val;
|
|
58
|
+
this.status({ fill: "green", shape: "dot", text: String(val) });
|
|
59
|
+
})
|
|
60
|
+
.catch(err => {
|
|
61
|
+
this.error("Error on update capability state: " + err.message);
|
|
62
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
this.on('input', (msg, _send, done) => {
|
|
67
|
+
if (typeof msg.payload != 'boolean') {
|
|
68
|
+
this.error("Wrong type! msg.payload must be boolean.");
|
|
69
|
+
if (done) {
|
|
70
|
+
done();
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (msg.payload === value) {
|
|
75
|
+
this.debug("Value not changed. Cancel update");
|
|
76
|
+
if (done) {
|
|
77
|
+
done();
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const state = {
|
|
82
|
+
type: ctype,
|
|
83
|
+
state: {
|
|
84
|
+
instance: instance,
|
|
85
|
+
value: msg.payload
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
device.updateCapabState(this.id, state)
|
|
89
|
+
.then(() => {
|
|
90
|
+
value = msg.payload;
|
|
91
|
+
this.status({ fill: "green", shape: "dot", text: String(msg.payload) });
|
|
92
|
+
if (done) {
|
|
93
|
+
done();
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch(err => {
|
|
97
|
+
this.error("Error on update capability state: " + err.message);
|
|
98
|
+
this.status({ fill: "red", shape: "dot", text: "Error" });
|
|
99
|
+
if (done) {
|
|
100
|
+
done();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
this.on('close', (removed, done) => {
|
|
105
|
+
if (removed) {
|
|
106
|
+
device.delCapability(this.id)
|
|
107
|
+
.then(() => { done(); })
|
|
108
|
+
.catch(err => {
|
|
109
|
+
this.error("Error on delete capability: " + err.message);
|
|
110
|
+
done();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
done();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
RED.nodes.registerType("Toggle", AliceToggle);
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=alice-togle.js.map
|