UNPKG

node-red-contrib-nanoleaf-aurora

Version:

A node-red module, which provides nodes to manipulate a Nanoleaf Aurora installation.

34 lines (26 loc) 1.36 kB
module.exports = function (RED) { 'use strict' const axios = require('axios') function Installation(config) { RED.nodes.createNode(this, config) var node = this this.host = config.host this.base = config.base this.port = config.port this.accessToken = config.accessToken this.request = () => axios.create({ baseURL: `http://${this.host}:${this.port}${this.base}${this.accessToken}` }) this.info = () => this.request().get('/').then(r => r.data) this.identify = () => this.request().put('/identify').then(r => r.data) this.state = (field) => this.request().get(`/state/${field}`) .then(r => Object.prototype.hasOwnProperty.call(r, 'value') ? r.data.value : r.data) this.setState = (field, value) => this.setStates({ [field]: value }) this.setStates = (state) => this.request().put('/state', state) this.effects = () => this.request().get('/effects/effectsList').then(r => r.data) this.effect = () => this.request().get('/effects/select').then(r => r.data) this.setEffect = (name) => this.setEffects({ select: name }) this.setEffects = (effect) => this.request().put('/effects', effect) } RED.nodes.registerType('installation', Installation) }