node-red-contrib-doorbird-ultimate
Version:
Node-Red Integration for Doorbird Devices
40 lines (35 loc) • 1.45 kB
JavaScript
module.exports = function (RED) {
const statusUtils = require('./utils/status');
function DoorbirdOpenNode(config) {
RED.nodes.createNode(this, config);
var node = this;
node.station = RED.nodes.getNode(config.station);
node.relay = config.relay;
node.on('input', function (_msg) {
var doorbird = node.station.doorbird;
this.status({
fill: 'blue',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-open.runtime.status.requesting')}`
});
doorbird.openDoor(node.relay).then(response => {
this.status({
fill: 'green',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-open.runtime.status.success')}`
});
node.send({
payload: response
});
}).catch(error => {
this.status({
fill: 'red',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-open.runtime.status.error')}`
});
node.error(RED._('doorbird-open.runtime.error'), error);
});
});
}
RED.nodes.registerType('doorbird-open', DoorbirdOpenNode);
}