I would like to use the node.status()
method to update the status of a config node for the user. How can I display the node's status in the config panel?
Is there an event that is emitted when the status changes?
I would like to use the node.status()
method to update the status of a config node for the user. How can I display the node's status in the config panel?
Is there an event that is emitted when the status changes?
Got it.
RED.comms.subscribe(`status/${node.id}`,function(topic,msg){
console.log(topic,msg);
});
There is an unsubscribe also.
Where do you show the status?
I'm showing it in the config node panel.
/* Subscribe / unsubscribe from the NR websocket status updates for a node */
subscribeConfigStatus: function(nodeId,handler){
RED.comms.subscribe(`status/${nodeId}`,handler);
},
unsubscribeConfigStatus: function(nodeId,handler){
RED.comms.unsubscribe(`status/${nodeId}`,handler);
},
configStatusHandler: function(topic,msg){
switch(msg.fill){
case 'red': msg.fill = '#cc0000'; break;
case 'green': msg.fill = '#55aa88'; break;
case 'yellow': msg.fill = '#F9DF31'; break;
case 'blue': msg.fill = '#53A3F3'; break;
case 'grey': msg.fill = '#d3d3d3'; break;
}
let shape = `background-color: ${msg.fill};`;
if(msg.shape === 'ring'){
shape = `border-color: ${msg.fill}; border-width: 2px;`
}
let container = $(".insteon-status");
container.css('margin-top','5px');
container.empty();
let rect = $("<div/>",{style: `margin-right: 4px; height: 14px; width: 14px; float: left; border-radius: 3px; ${shape}`});
let text = $("<span/>",{text: msg.text, style: "position: relative; top: -2px"});
rect.appendTo(container);
text.appendTo(container);
},
Thank you!!
Does this API still exist in v1.2.x? I am getting "RED.comms.subscribe is not a function".
I decided to override the status()
method of the config node to capture the status()
calls.
this.status = function (status) {
if (status.text === 'node-red:common.status.disconnected') {
// Handle disconnection
}
}