UNPKG

node-red-contrib-nanoleaf

Version:

[![platform](https://img.shields.io/badge/platform-Node--RED-red?logo=nodered)](https://nodered.org) [![Min Node Version](https://img.shields.io/node/v/node-red-contrib-nanoleaf.svg)](https://nodejs.org/en/) [![GitHub version](https://img.shields.io/githu

37 lines (29 loc) 1.52 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.timeout = 3000 this.accessToken = config.accessToken this.request = () => axios.create({ timeout: this.timeout, 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) // this.event = (id) => this.request().get(`/events?id=${id}`).then(r => r.data) } RED.nodes.registerType('installation', Installation) }