Preserve Short‑Form format When Generating YAML#5306
Conversation
|
@lolodomo, when you have a moment, could you take a look at this? I want to make sure I’ve understood the override logic correctly, especially around the injected vs. default formats. I might be missing some of the intent from the original implementation, so your insight would be really helpful. |
|
This case is very complex in particular due to the way it is managed by the DSL provider. |
|
Looking at the code, I see that I did not consider the short form for |
|
This whole default / injected stateFormatter logic seems strange to me. I would think the short form / long form should only relate to what's actually stored in the metadata and it should be done without any regard to any default / injected format from anywhere else. |
DSL provider does not use metadata but another feature. I remember I hesitated to change the DSL provider to remove that. I did not do it because I was not 100% of the possible impacts. |
|
But let me remember the scenario which was a problem. |
There was a problem hiding this comment.
Pull request overview
This pull request enhances the YAML generator for openHAB to preserve the short-form format syntax when exporting items. Previously, even when items were defined with the concise format: '%d' syntax, the generator would always expand this to the full metadata.stateDescription.config.pattern structure. This PR adds logic to detect when stateDescription metadata contains only a pattern value and generates the short-form instead, maintaining symmetry between input and output YAML.
Changes:
- Added logic to convert stateDescription metadata with only a pattern config back to short-form
formatfield - Refactored metadata handling to use early continue statements for improved readability
- Added comprehensive tests for both short-form and long-form stateDescription scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| YamlItemFileConverter.java | Refactored metadata handling logic to detect and preserve short-form format syntax when appropriate; simplified control flow with early continue statements |
| YamlItemFileConverterTest.java | Added tests to verify stateDescription metadata conversion to short-form format and long-form preservation when additional config exists |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@openhab/core-maintainers : please wait before merging, I would like to investigate more. |
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
4f6feb7 to
920190d
Compare
|
rebased to resolve conflict |
|
Need to find again the use case that will be problematic with DSL. |
Preserve Short‑Form
formatWhen Generating YAMLopenHAB already supports the short‑form
formatsyntax for Items in YAML. For example:Internally, this is correctly translated into the equivalent metadata structure:
However, when exporting or regenerating YAML from this internal representation, the system currently does not restore the short‑form. Instead, it always emits the full metadata block, even when the only metadata present is the
patternvalue that corresponds directly to theformatshorthand.This PR updates the YAML generator so that:
stateDescriptionmetadata contains only apatternvalue,→ the YAML generator emits the concise
format: '<pattern>'form.stateDescriptionmetadata is present,→ the generator falls back to the full metadata representation.
✔️ Benefits
formatshorthand is needed.