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.

utility.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.mapColorForValue = exports.nodeToStringFactory = exports.checkConfig = void 0;
  4. /**
  5. * Check for that we have a config instance and that our config instance has a group selected, otherwise report an error
  6. * @param {object} config - The config instance
  7. * @param {object} node - The node to report the error on
  8. * @returns {boolean} `false` if we encounter an error, otherwise `true`
  9. */
  10. const checkConfig = (config, node, RED) => {
  11. if (!config) {
  12. // TODO: have to think further if it makes sense to separate these out, it isn't clear what the user can do if they encounter this besides use the explicit error to more clearly debug the code
  13. node.error(RED._('ui_led.error.no-config'));
  14. return false;
  15. }
  16. if (!config.group) {
  17. node.error(RED._('ui_led.error.no-group'));
  18. return false;
  19. }
  20. if (RED.nodes.getNode(config.group) === undefined) {
  21. node.error(RED._('ui_led.error.invalid-group'));
  22. return false;
  23. }
  24. return true;
  25. };
  26. exports.checkConfig = checkConfig;
  27. const nodeToStringFactory = (config) => {
  28. return () => {
  29. let result = 'LED';
  30. if (config.name) {
  31. result += ' name: ' + config.label;
  32. }
  33. if (config.label) {
  34. result += ' label: ' + config.label;
  35. }
  36. return result;
  37. };
  38. };
  39. exports.nodeToStringFactory = nodeToStringFactory;
  40. // TODO: should we be doing this at message time? less performant but does it allow config changes where doing before doesn't?
  41. const mapColorForValue = (node, config, RED) => {
  42. return config.map((value) => {
  43. return {
  44. color: value.color,
  45. value: RED.util.evaluateNodeProperty(value.value, value.valueType, node, {}),
  46. valueType: value.valueType
  47. };
  48. });
  49. };
  50. exports.mapColorForValue = mapColorForValue;
  51. //# sourceMappingURL=utility.js.map