Skip to content

Commit

Permalink
Add status info about requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ihrigb committed Aug 24, 2022
1 parent 424ee21 commit de1e4b2
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 12 deletions.
23 changes: 19 additions & 4 deletions nodes/doorbird-info.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
module.exports = function(RED) {
"use strict";
module.exports = function (RED) {
const statusUtils = require('./utils/status');

function DoorbirdInfoNode(config) {
RED.nodes.createNode(this, config);
var node = this;

node.station = RED.nodes.getNode(config.station);

node.on('input', function(_msg) {
node.on('input', function (_msg) {
var doorbird = node.station.doorbird;
this.status({
fill: 'blue',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-info.runtime.status.requesting')}`
});
doorbird.getInfo((info) => {
this.status({
fill: 'green',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-info.runtime.status.success')}`
});
node.send({
payload: info
});
}, (error) => {
this.status({
fill: 'red',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-info.runtime.status.error')}`
});
node.error(RED._('doorbird-info.runtime.error'), error);
});
});

RED.httpAdmin.post('/DoorbirdUltimate/:id/info', RED.auth.needsPermission('DoorbirdUltimate.info'), function(req, res) {
RED.httpAdmin.post('/DoorbirdUltimate/:id/info', RED.auth.needsPermission('DoorbirdUltimate.info'), function (req, res) {
var node = RED.nodes.getNode(req.params.id);
try {
node.receive();
Expand Down
23 changes: 19 additions & 4 deletions nodes/doorbird-light.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
module.exports = function(RED) {
"use strict";
module.exports = function (RED) {
const statusUtils = require('./utils/status');

function DoorbirdLightNode(config) {
RED.nodes.createNode(this, config);
var node = this;

node.station = RED.nodes.getNode(config.station);

node.on('input', function(_msg) {

node.on('input', function (_msg) {
var doorbird = node.station.doorbird;

this.status({
fill: 'blue',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-light.runtime.status.requesting')}`
});
doorbird.lightOn((response) => {
this.status({
fill: 'green',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-light.runtime.status.success')}`
});
node.send({
payload: response
});
}, (err) => {
this.status({
fill: 'red',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-light.runtime.status.error')}`
});
node.error(RED._('doorbird-light.runtime.error'), err);
});
});
Expand Down
23 changes: 19 additions & 4 deletions nodes/doorbird-open.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function(RED) {
"use strict";
module.exports = function (RED) {
const statusUtils = require('./utils/status');

function DoorbirdOpenNode(config) {
RED.nodes.createNode(this, config);
Expand All @@ -8,14 +8,29 @@ module.exports = function(RED) {
node.station = RED.nodes.getNode(config.station);
node.relay = config.relay;

node.on('input', function(_msg) {

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, (response) => {
this.status({
fill: 'green',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-open.runtime.status.success')}`
});
node.send({
payload: response
});
}, (err) => {
this.status({
fill: 'red',
shape: 'dot',
text: `${statusUtils.statusDateString()}: ${RED._('doorbird-open.runtime.status.error')}`
});
node.error(RED._('doorbird-open.runtime.error'), err);
});
});
Expand Down
5 changes: 5 additions & 0 deletions nodes/locales/en-US/doorbird-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
}
},
"runtime": {
"status": {
"requesting": "Requesting ...",
"success": "Success",
"error": "Error"
},
"error": "Error in Doorbird communication."
}
}
Expand Down
5 changes: 5 additions & 0 deletions nodes/locales/en-US/doorbird-light.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
}
},
"runtime": {
"status": {
"requesting": "Requesting ...",
"success": "Success",
"error": "Error"
},
"error": "Error in Doorbird communication."
}
}
Expand Down
5 changes: 5 additions & 0 deletions nodes/locales/en-US/doorbird-open.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
}
},
"runtime": {
"status": {
"requesting": "Requesting ...",
"success": "Success",
"error": "Error"
},
"error": "Error in Doorbird communication."
}
}
Expand Down
16 changes: 16 additions & 0 deletions nodes/utils/status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

function statusDateString() {
return new Date().toLocaleString(undefined, {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
}

module.exports = {
statusDateString: statusDateString
};

0 comments on commit de1e4b2

Please sign in to comment.