* [DSL rule] Add time of day trigger to DSL file syntax
Closes#5435
Exampele of rule:
```
rule "Test time of day trigger"
when
Time is 20:13
then
logInfo("Rule","Test")
end
```
For backward compatibility, using "noon" and "midnight" is still supported.
"timer.TimeOfDayTrigger" is now used (instead of "timer.GenericCronTrigger").
Here is the log confirming the execution of the rule at the expected time:
```
20:13:00.531 [INFO ] [org.openhab.core.model.script.Rule ] - Test
```
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
The enhancement consists in just getting the UID of the elements to be removed rather than building a full object.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Move YAML test files in sub-folders
Tests for YamlThingProvider moved in a separate class.
Also test that a thing change listener is properly called when loading a YAML file containing things.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* [REST] API /file-format/parse: do not extend thing/channel config
The /file-format/parse API does no more extend the thing and channel configuration with parameters having a default value. The output will contain hte thing/channel configuration parameters provided in the input.
It is fixed for YAML and DSL formats.
Unit tests added for YAML models containing Thing
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* [YAML provider] Add INFO log for config TEXT param value not parsed as string
Related to openhab/openhab-webui#3696
Follow-up #5248
A log at level INFO is now displayed when a YAML file is loaded and contains a thing or channel configuration parameter of type TEXT whose value is not parsed as a string. This occurs when an unquoted number is provided. The log recommends enclosing the value in double quotes to prevent conversion.
For better consistency, the YAML provider is now also processing any BigDecimal value to convert it into a String type when the config paramater is of type TEXT.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This PR normalizes thing/channel configuration before producing the response.
It allows having proper types for config parameters in the JSON response of the API.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* [YAML provider] Add special handling to thing/channel config param of type text
Related to openhab/openhab-webui#3696
For configuration parameter of type text only, if the value in YAML is an unquoted number (value is then of type BigDecimal after loading and mapping in our DTO) and there is no decimal, we convert it to an integer and return a String from that integer.
Value 1 in YAML is converted into String "1"
Value 1.0 in YAML is converted into String "1"
Value 1.5 in YAML is untouched
Value "1" in YAML is untouched
Value "1.0" in YAML is untouched
Value "1.5" in YAML is untouched
All this is to avoid that 1 filled in YAML without quotes finally results in string "1.0" after configuration normalization.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Related to openhab/openhab-webui#3696
We setup our YAML generator library to use quotes for strings when the value is a number.
Strings being not a number will still be generated without quotes.
It avoids later when parsing the generated YAML to retrieve a BigDecimal type instead of a String type when the DTO is defined with a Java Object type (that is the case for thing/channel configuration in particular).
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Isolated DSL/YAML models are models that do not fill the things/items/... registries when they are loaded.
They are used as temporary models for particular features.
These models have a particular prefix in their names to distinguish them.
It was "tmp_" before, it is now "___tmp_".
The risk that a user names one of its file with such prefix is reduced.
If a DSL file with prefix "___tmp_" is by the way used by a user, this file is ignored and a message is now logged to inform the user.
Closed#5134
Change pattern for isolated model name
tmp_DSL_model_<N>.items => ___tmp_model_<N>.items
tmp_YAML_model_<N>.yaml => ___tmp_model_<N>.yaml
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* [DSL/YAML generator] Consider item pattern formatter even without label
Items without label but with a formatter are now properly considered when generating DSL and YAML syntax.
Example: Number SceneItem "[MAP(scene.map):%s]"
Bug was reported on the community forum.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Fix typos discovered by Copilot
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
---------
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Concerned fields are:
- group in the "groups" list of an item
- UID of a linked channel in an item
- namespace of a metadata attached to an item
- UID of a thing
- "bridge" field of a thing
- channel id of a channel declared in a thing
- "type" field of a channel
A check was also added for the "profile" configuration parameter of a linked channel.
Related to #5057
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* [REST] New API for conversion between file format and JSON
Related to #4585
This PR supports conversion of things and items.
It supports DSL and YAML file formats.
A first new API (POST /file-format/create) allows to create a file format (DSL or YAML) from a JSON object.
A second new API (POST /file-format/parse) allows to parse a file format (DSL or YAML) to a JSON object.
These 2 APIs should help Main UI displaying DSL and YAML file formats for things.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Before this fix, the AddonSuggestionService service was started and an incomplete configuration was considered, a configuration containing none of the user settings defining if each suggestion finder should be enabled or disabled.
Later, when AddonFinderService service was added, the same incomplete configuration was reused.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Reduce potential collisions in hashCode()
Make identical a null list/set and an empty list/set
Test hashCode in addition to equals in unit tests.
Add new tests for YamlItemDTO (equals/hashCode)
Related to #4936
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Fix openhab/openhab-addons#18945
Regression from #4880
For Metadata, it was reported on the community forum, it occured when an item is linked to several channels.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Related to #3823
Replaces #4444
If the sub-folder where models are supposed to be found does not exist, the service is marked as ready anyway.
If not, start level 100 could be never reached at OH startup.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* WARN log when an object with same ID is added to a registry by a second provider
Log was existing but at DEBUG level, meaning the general user was not informed that he defined the same object (thing, item, ...) at different places (providers) like for example an item in Main UI and an item in config file with same name.
Fix#4810
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
While things can now be loaded even when the binding is not yet available, channel types for user defined channels could be not yet in the registry when these channels are first created.
So when the binding is finally available, the thing is updated and user defined channels are now created again to retrieve properties from channel types.
This fix avoids warnings at startup regarding missing channel types.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* YAML configuration: add support for items/metadata/channel links
This PR adds the support of items in the YAML configuration file.
It also includes the support of items metadata and items channel links.
Related to #3666
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Makes it consistent with managed thing provider.
Removes the OSGi reference between YamlThingProvider and YamlModelRepository and as consequence removes the circular reference.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Fix#4778
Things and items are now sorted in output only when all elements are requested.
If the API is requested only for a subset of elements (things or items), the output respects the input order of elements.
DSL generator for things and items is also fixed to avoid a crash when called with 0 element.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Each YAML element provider can now define which YAML file versions it is applicable to and whether it is deprecated or not.
Related to #3666
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Introduce YAML configuration version 2
Version 2 uses map to store elements while version 1 uses table.
Version 1 is still supported.
Unit tests have been extended to cover version 1 and 2.
Related to #3666
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Enhance ThingActions UI support
Fixes#1745
Return config description parameters for the ActionInputs of ThingActions for the REST GET /action/{thingUID} and REST GET /module-types endpoints.
The config description parameters are only provided if all input parameters have a type that can be mapped to a config description parameter (String, boolean, Boolean, byte, Byte, short, Short, int, Integer, long, Long, float, Float, double, Double, Number, DecimalType, QuantityType<?>, LocalDateTime, LocalDate, LocalTime, ZonedDateTime, Date, Instant and Duration).
Enhance the REST POST /actions/{thingUID}/{actionUid} endpoint (allows invoking Thing actions via REST) and the AnnotationActionHandler (allows invoking Thing actions from UI-rules) in order to be more flexible regarding the type of each provided argument value and to map the value to the expected data type. Number and string values will be accepted as inputs and the expected data type will be created from this value.
This will be used by the UI's Thing page and rule editor to allow invoking Thing actions through the UI or adding them to UI-bases rules.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Fixopenhab/openhab-webui#2641
The i18n key for add-on configuration parameter should now start with addon.config.<param>.
To maintain compatibility with hundreds of existing translations, an alternative key starting with <type>.config.<param> is still accepted for an add-on parameter
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Apply the same logic in AbstractThingHandlerDiscoveryService as in AbstractDiscoveryService to determine if background discovery should be enabled or disabled.
Fixopenhab/openhab-addons#17089
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This fix allows having translated label for bindings when showing list of installed bindings in Main UI parameters.
Fixopenhab/openhab-webui#2639
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Use item state formatter to format input of transformation, meaning using state.format(format) instead of String.format(format, state.toString())
This was already the case in sitemap API but not in other APIs used by Main UI.
Make sure to call transformation even for NULL and UNDEF states.
It was not the case in one API used by Main UI.
When calling transformation and state is NULL or UNDEF, do not apply format to the input value and do not replace by "-".
That means the transformation will be called with "NULL" or "UNDEF".
Sitemap API was calling the transformation using a pattern containing "-".
Fix#4101
Also related to discussion in openhab/openhab-addons#13777
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Problem introduced by #4223
checkFramesInWidgetList for LinkableWidget was triggering an error when the Buttongrid element has no parameter set.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Extend sitemap syntax for switch to support press & release buttons
Mappings attribute for switch element now accepts one or two commands for each button.
If only one command is provided, the button is a click button, the command is sent to the item when the button is clicked.
If two commands are provided (separated by ":"), the button is a press & release button, the first command is sent to the item when the button is pressed and the second when the button is released.
Syntax example for a click button: Switch item=DemoSwitch mappings=[ ON="ON" ]
Syntax example for a press & release button: Switch item=DemoSwitch mappings=[ ON:OFF="ON" ]
Related to #3822
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Fix#2283Fix#4050
This PR is fixing two things in the computation of the displayState:
- If a transformation is present in the state pattern, it has now priority over options provided by the state description
- If no transformation is present in state pattern but options are provided by the state description, the provided state pattern is applied to the matching option
Also remove a deprecated call to transform.
If there is no transformation but options are provided without any matching with the current state and there is a pattern provided, then this pattern is used to format the output.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Set a default presentation pattern for String/Number/Datetime items
A default state pattern was previously provided by ChannelStateDescriptionProvider only for String and Number items linked to a channel.
It is now the class DefaultStateDescriptionFragmentProvider which is responsible for providing the default state pattern for items, whether the item is linked to a channel or not.
This new class is the lowest ranked StateDescriptionFragmentProvider so that all other providers have priority in setting the state pattern.
Default pattern for string item: %s
Default pattern for datetime item or group with datetime state: %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS
Default pattern for number item or group with number state: %.0f
Default pattern for number+dimension item or group with number+dimension state: %.0f %unit%
Closes#4071Closes#3835
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Add a YAML file provider for semantic tags
Files in folder conf/tags are loaded by this provider.
Related to #3619
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This allows dynamic icons based on items states even with non OH icon sources.
This also allows overwritting the default handling with state done by the icon servlet.
Example: icon=[item1>0=temperature,==0=material:settings,f7:house]
Related to openhab/openhab-webui#1938
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Concerns labelcolor, valuecolor and visibility
Also fix wrong positions of ")" in Sitemap.xtext
Closes#3058
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* [Sitemap] Accept an optional icon for each value/label mapping
When set by the user, the icon can be used by UIs for switch element with mappings to render a button with the icon rather than the label.
Related to #3441
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
When set, the UI should not provide the item state when requestiong the
OH icon and should not request again the icon when the item state is
updated.
Related to openhab/openhab-android#3404
Signed-off-by: Laurent Garnier <lg.hc@free.fr>