* Create ready markers for proper managed providers
"managed" markers (managed=item, managed=metadata, managed=rule, managed=thing and managed=itemchannellink) were created too early with the following providers: ScriptedItemProvider, ScriptedMetadataProvider, ScriptedRuleProvider, ScriptedThingProvider and ScriptedItemChannelLinkProvider.
They are now properly created with providers ManagedItemProvider, ManagedMetadataProviderImpl, ManagedRuleProvider, ManagedThingProvider and ManagedItemChannelLinkProvider.
Marker managed=sitemap is now also created with provider UIComponentSitemapProvider.
Marker managed=persistenceserviceconfiguration is now also created with provider ManagedPersistenceServiceConfigurationProvider.
Marker managed=semantictag is now also created with provider ManagedSemanticTagProvider.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Fix tests in core.model.script
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
---------
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Add semantic tags to conversion REST API
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Copilot comments: first set of changes
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* getAllFromModel: copy list
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* removeModel: get a mutable empty list
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Simplification in method parse (REST API)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Force UTF-8 charset when using the file-format APIs
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Change default value for parameter hideDefaultTags to false
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Add parameter to exclude non editable tags
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Finally apply hideNonEditableTags/hideDefaultTags params even when UIDs are provided
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Review comment: use/add methods isEditable/IsDefault from the registry
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Extend REST API getTags to have the info in the response if the tag is default
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
---------
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
The DSL Rule provider must handle rules and scripts in onReadyMarkerAdded.
Until now, only .rules files were handled, not .script files.
As a result, .script files were ignored by the rule provider.
Sometimes it worked well because there was a call to reloadAllModelsOfType for all scripts when the rule provider was ready and the .script files were then handled by the provider in modelChanged.
If this last call was done while the rule provider was not yet ready, the .script files were ignored because the rule provider was not yet setup to handle model changes.
So all of this depends on timing conditions at openHAB startup.
With that change, the .script files will always be considered by the DSL rule provider.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Avoid having a thing handler being initialized for a thing UID without first disposing the previous handler for this thing UID.
unregisterAndDisposeHandler is now called instead of unregisterHandler before calling registerAndInitializeHandler in this particular case (thing handler exists for the old thing version).
Fix#5575
Few logs added to help future debugging.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* [DSL Rule] Allow rule with no trigger in DSL file format
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Copilot review comment: call getByytes with StandardCharsets.UTF_8 as parameter
It was already called with StandardCharsets.UTF_8 for certain tests in that test class.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Fix order of lines in itests after resolving conflict
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Make triggers optional including the "when" key
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
---------
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Align with how it is implemented for any other registry/providers.
YAML files containing sitemaps are now properly loaded.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Accept any number of sub-widgets in a sitemap frame/page
The previous limit was 100.
Widget id coding is enhanced to support any size.
Old coding is still supported.
Closes#5434
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Simplify how is built the widget id (no need to retry)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
---------
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* Deprecate defining buttons as properties of a Butongrid widget
Remove specific related objects from core sitemap registry.
For backward compatibility, such buttons definition present in existing user sitemaps are automatically replaced by Button sub-widgets. A warning is logged to announce the deprecation when such definition is encountered.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
New file extension ".sitemaps" is added.
A .sitemaps file can contain one or several sitemap definitions.
.sitemap extension is kept for backward compatibility.
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
* add optional rule UID to DSL file syntax
* avoid notifying the rule registry for isolated models
* check other model files for rule with same name before rule removal
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Also-by: Ravi Nadahar <nadahar@rediffmail.com>
* [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>