Closed AmoebeLabs closed 2 years ago
The current parser assumes that we have a live, instantiated tool (with state, etc).
For configuration stuff, we just have the configuration, and we need to be able to distinguish these things.
Solution implemented:
[[[[ ]]]]
(four square brackets!!) for configuration only JavaScript[[[ ]]]
(three square brackets!) for runtime stuffThe configuration parser replaces the JavaScript evaluations with the result.
The Problem To Be Solved
Layout templates are a great thing to re-use layouts. A template can use variables to 'configure' the template. However, the layout is still more or less fixed: one could use
display: none
to disable a tool run-time, but it would be nice if that could be done during configuration setup for tools that won't be needed.Take for instance a layout with a battery icon and warning: if the sensor doesn't have a battery entity, that tool is not needed. By disabling this tool, this layout can be used for both a layout with a battery indicator (wireless sensor) and without (wired sensor).
Without this support, one would need two different - but almost identical - layout templates!
By explicitly enabling and disabling tools, one could even overlay certain tools in a single layout, and get different layouts depending on a certain variable flag.
Additional background:
By disabling a tool from the configuration, this tool is not created: ie no runtime overhead!
Related Issues (if any)
(Optional): Suggested Solution
A simple flag
disabled: true/false
would be enough for starters...For the more complex use, ie enabling and disabling other tools with a single variable flag, some JavaScript is required as YAML does not allow for logical operators, ie
not true
or!true
...(Optional): Alternative Solutions
For the more complex use, there is a weird alternative by using two explicit settings:
disabled
andenabled
flags.Say we have two tools. One is enabled by a single flag, the other one disabled, and vice versa:
Flag = true, tool1 shown (default disabled, but enabled through flag), tool2 not (default enabled, but disabled by flag)
Flag = false, tool1 is hidden (default disabled, and not enabled through flag), tool2 is shown (default enabled and not disabled by flag)
This solves the simple true/false flag variable without any use of JavaScript, but what if that variable holds another value, a setting that involves more than one tool or group of tools?
Furthermore, this combined setting of flag might be confusing for users 😃, where a simple yes/no flag is not.