Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui-led.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. module.exports = function (RED) {
  2. function UILedNode (config) {
  3. RED.nodes.createNode(this, config)
  4. const node = this
  5. // which group are we rendering this widget
  6. const group = RED.nodes.getNode(config.group)
  7. const base = group.getBase()
  8. // server-side event handlers
  9. const evts = {
  10. onInput: function (msg, send, done) {
  11. // store the latest value in our Node-RED datastore
  12. base.stores.data.save(base, node, msg)
  13. // send it to any connected nodes in Node-RED
  14. send(msg)
  15. }
  16. }
  17. // evaluated (server-side) the colour value options, so we can compute which colour to display client-side
  18. const evalColors = []
  19. config.states.forEach((state) => {
  20. const value = RED.util.evaluateNodeProperty(state.value, state.valueType, node)
  21. evalColors.push({
  22. value,
  23. color: state.color
  24. })
  25. })
  26. config.evaluated = evalColors
  27. // inform the dashboard UI that we are adding this node
  28. if (group) {
  29. group.register(node, config, evts)
  30. } else {
  31. node.error('No group configured')
  32. }
  33. }
  34. RED.nodes.registerType('ui-led', UILedNode)
  35. }