diff --git a/README.md b/README.md index 21d2f63..bb499e7 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ Please note that this script does not cover everything, see below for a list of - `ui_slider` - converted to Dashboard 2.0's `ui-slider` - `ui_text_input` - converted to Dashboard 2.0's `ui-text-input` - `.tooltip` is not supported +- `ui_led` - converted to Dashboard 2.0's `ui-led`. This is not a core node, but can be installed through the [Node-RED Palette Manager](https://flows.nodered.org/node/@flowfuse/node-red-dashboard-2-ui-led) - `ui_numeric` - converted to Dashboard 2.0's `ui-numeric-input` - ### Config Nodes - `ui_tab` - converted to Dashboard 2.0's `ui-page` diff --git a/tests/flows/basic-layout-after.json b/tests/flows/basic-layout-after.json index cc1e8a5..1f98f8f 100644 --- a/tests/flows/basic-layout-after.json +++ b/tests/flows/basic-layout-after.json @@ -231,38 +231,70 @@ ] }, { - "id": "940a12ce19bf2212", - "type": "ui-number-input", - "z": "94d6d107f1742efb", - "name": "", - "label": "numeric", - "tooltip": "", - "group": "f663864dda246564", - "order": 13, - "width": 0, - "height": 0, - "passthru": true, - "topic": "topic", - "topicType": "msg", - "min": 0, - "max": 10, - "step": 1, - "className": "", - "x": 320, - "y": 440, - "wires": [ - [ + "id": "71985e85957f8be3", + "type": "ui-led", + "z": "78ee589ecd091670", + "name": "My Led", + "group": "f663864dda246564", + "order": 8, + "width": 0, + "height": 0, + "label": "My Led", + "labelPlacement": "left", + "labelAlignment": "left", + "states": [ + { + "value": "false", + "valueType": "bool", + "color": "#ff0000" + }, + { + "value": "true", + "valueType": "bool", + "color": "#00ff00" + } + ], + "allowColorForValueInMessage": false, + "shape": "circle", + "showBorder": true, + "showGlow": true, + "x": 990, + "y": 200, + "wires": [] + }, + { + "id": "940a12ce19bf2212", + "type": "ui-number-input", + "z": "94d6d107f1742efb", + "name": "", + "label": "numeric", + "tooltip": "", + "group": "f663864dda246564", + "order": 13, + "width": 0, + "height": 0, + "passthru": true, + "topic": "topic", + "topicType": "msg", + "min": 0, + "max": 10, + "step": 1, + "className": "", + "x": 320, + "y": 440, + "wires": [ + [ - ] - ], - "sendOnBlur": true, - "sendOnEnter": true, - "clearable": false, - "icon": "", - "iconPosition": "left", - "iconInnerPosition": "inside", - "spinner": "default" - }, + ] + ], + "sendOnBlur": true, + "sendOnEnter": true, + "clearable": false, + "icon": "", + "iconPosition": "left", + "iconInnerPosition": "inside", + "spinner": "default" + }, { "id": "856a31bba370e7fc", "type": "ui-group", diff --git a/tests/flows/basic-layout-before.json b/tests/flows/basic-layout-before.json index 1c7797f..ca90d4c 100644 --- a/tests/flows/basic-layout-before.json +++ b/tests/flows/basic-layout-before.json @@ -224,6 +224,39 @@ ] }, { + "id": "ddca2be4bd1c8726", + "type": "ui_led", + "z": "78ee589ecd091670", + "order": 8, + "group": "856a31bba370e7fc", + "width": 0, + "height": 0, + "label": "My Led", + "labelPlacement": "left", + "labelAlignment": "left", + "colorForValue": [ + { + "color": "#ff0000", + "value": "false", + "valueType": "bool" + }, + { + "color": "#00ff00", + "value": "true", + "valueType": "bool" + } + ], + "allowColorForValueInMessage": false, + "shape": "circle", + "showGlow": true, + "name": "My Led", + "x": 990, + "y": 200, + "wires": [ + [] + ] + }, + { "id": "b52c292d531874a6", "type": "ui_numeric", "z": "94d6d107f1742efb", diff --git a/tests/index.js b/tests/index.js index 028d30b..807f279 100644 --- a/tests/index.js +++ b/tests/index.js @@ -162,6 +162,19 @@ describe('Dashboard Migration Script', function () { } }) }) + describe('UI LED:', function () { + const input = utils.getByType(migratedFlow, 'ui-led')[0] + const input1 = utils.getByType(basicLayoutAfter, 'ui-led')[0] + + const excludeFromChecks = ['id', 'group'] + Object.keys(input).forEach((prop) => { + if (!excludeFromChecks.includes(prop)) { + it('should set ' + prop + ' correctly ', function () { + input[prop].should.eql(input1[prop]) + }) + } + }) + }) describe('UI Switch:', function () { const swtch = utils.getByType(migratedFlow, 'ui-switch')[0] diff --git a/transformers/index.js b/transformers/index.js index 8f39fef..d9b8c52 100644 --- a/transformers/index.js +++ b/transformers/index.js @@ -8,5 +8,6 @@ module.exports = { uiSwitch: require('./nodes/ui-switch'), uiText: require('./nodes/ui-text'), uiTextInput: require('./nodes/ui-text-input'), + uiLed: require('./nodes/ui-led'), uiNumeric: require('./nodes/ui-numeric') } diff --git a/transformers/map.json b/transformers/map.json index 9a1a789..5767192 100644 --- a/transformers/map.json +++ b/transformers/map.json @@ -8,5 +8,6 @@ "ui_switch": "uiSwitch", "ui_text": "uiText", "ui_text_input": "uiTextInput", + "ui_led" : "uiLed", "ui_numeric": "uiNumeric" } diff --git a/transformers/nodes/ui-led.js b/transformers/nodes/ui-led.js new file mode 100644 index 0000000..ab4f094 --- /dev/null +++ b/transformers/nodes/ui-led.js @@ -0,0 +1,13 @@ +module.exports = function (node, baseId, themeId) { + node.type = 'ui-led' + + // update properties + node.states = node.colorForValue + + // new properties + node.showBorder = true + + // remove properties + delete node.colorForValue + return node +}