Skip to content

Commit 890763b

Browse files
committed
fix: catch rejected promises from Yeelight lib in State node
1 parent 01cdc56 commit 890763b

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/YeeLightNodeState.js

+26-11
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,32 @@ export default function YeeLightNodeState(RED) {
1111

1212
// on, hex, bri, hue, sat, duration
1313
const onInput = msg => {
14-
node.serverConfig.yeelight.sync().then(state => {
15-
msg.payload = sanitizeState(state);
16-
// only send message if new information or if requested by input
17-
if (
18-
JSON.stringify(msg.payload) !== JSON.stringify(lastSentState) ||
19-
Object.keys(msg).length > 1
20-
) {
21-
node.send(msg);
22-
lastSentState = msg.payload;
23-
}
24-
});
14+
node.serverConfig.yeelight
15+
.sync()
16+
.then(state => {
17+
msg.payload = sanitizeState(state);
18+
// only send message if new information or if requested by input
19+
if (
20+
JSON.stringify(msg.payload) !== JSON.stringify(lastSentState) ||
21+
Object.keys(msg).length > 1
22+
) {
23+
node.send(msg);
24+
lastSentState = msg.payload;
25+
}
26+
})
27+
.catch(e => {
28+
if (e.message === 'timeout') {
29+
e.code = 'timeout';
30+
e.message = 'Local timeout in "Yeelight.command" execution';
31+
}
32+
node.log('An error occured while syncing or setting a new value');
33+
console.error(e);
34+
node.status({
35+
fill: 'red',
36+
shape: 'ring',
37+
text: `Command send error: ${e.code}`,
38+
});
39+
});
2540
};
2641

2742
(function init() {

0 commit comments

Comments
 (0)