UNPKG

@tbowmo/node-red-small-timer

Version:

Small timer node for Node-RED with support for sunrise, sunset etc. timers

33 lines (32 loc) 1.21 kB
"use strict"; const small_timer_runner_1 = require("../lib/small-timer-runner"); const sun_and_moon_1 = require("../lib/sun-and-moon"); module.exports = (RED) => { RED.nodes.registerType('smalltimer', function (props) { RED.nodes.createNode(this, props); this.position = RED.nodes.getNode(props.position); this.smallTimer = new small_timer_runner_1.SmallTimerRunner(this.position, props, this); this.on('input', (msg, _send, done) => { try { this.smallTimer.onMessage(msg); done(); } catch (err) { done(err); } }); this.on('close', () => { this.smallTimer.cleanup(); }); }); RED.httpAdmin.get('/smalltimer/sunCalc/:position', (req, res) => { const positionNode = RED.nodes.getNode(req.params.position); if (positionNode?.latitude && positionNode?.longitude) { const sunAndMoon = new sun_and_moon_1.SunAndMoon(positionNode.latitude, positionNode.longitude); res.json(sunAndMoon.getTimes()); } else { res.status(400).send('Missing position'); } }); };