UNPKG

rpi-profalux-shutters

Version:

Node library to control Profalux roller shutters with a Raspberry Pi through an HTTP API

25 lines (21 loc) 938 B
const argv = require('minimist')(process.argv.slice(2)); const config = ((configName) => { const configPath = require('path').join(process.cwd(), configName); if (!require('fs').existsSync(configPath)) { console.error(`Config file "${configPath}" could not be found.`); //eslint-disable-line no-console process.exit(127); } return require(configPath); })(argv.config || 'config.json'); const Server = require('./lib/server'); const Shutter = require('./lib/shutter'); const shutter = new Shutter(config.shutter); shutter.init() .then(() => Server.init(config)) .then(() => { Server.on('getPosition', (callback) => callback(Math.round(shutter.currentPosition))); Server.on('getState', (callback) => callback(shutter.currentState)); Server.on('setPosition', ({ targetPosition }) => shutter.update(targetPosition)); Server.on('stop', () => shutter.stop()); }) ;