Skip to content

[smhi] Use parameter API endpoint#20642

Merged
lsiepel merged 8 commits intoopenhab:mainfrom
pacive:smhi-parameters
May 4, 2026
Merged

[smhi] Use parameter API endpoint#20642
lsiepel merged 8 commits intoopenhab:mainfrom
pacive:smhi-parameters

Conversation

@pacive
Copy link
Copy Markdown
Member

@pacive pacive commented Apr 28, 2026

Use the parameters endpoint in SMHI's API to get metadata for different parameters. This enables the binding to automatically apply unit conversions if these change in the API, and also to create new channels automatically if parameters are added.

Fixes #20592

Use the parameters endpoint in SMHI's API to get metadata for different parameters. This enables the binding to automatically apply unit conversions if these change in the API, and also to create new channels automatically if parameters are added.

Fixes openhab#20592

Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
@pacive pacive added the enhancement An enhancement or new feature for an existing add-on label Apr 28, 2026
@pacive pacive requested a review from Copilot April 28, 2026 05:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the SMHI binding to consume SMHI’s parameter.json endpoint for parameter metadata, enabling dynamic unit handling and (potentially) dynamic channel-type creation when SMHI adds/changes parameters.

Changes:

  • Add ParameterMetadata model and parsing support for SMHI’s parameter metadata endpoint.
  • Introduce SmhiChannelTypeProvider to create/store channel types from parameter metadata.
  • Refactor handler/aggregator/time series logic to operate on ParameterMetadata (with updated tests/fixtures).

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/Forecast.java Switch forecast state conversion to metadata-based API.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/ForecastAggregator.java Refactor aggregation methods to accept ParameterMetadata (nullable) and return UNDEF when missing.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/Parser.java Add parsing for parameter.json into ParameterMetadata list.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiBindingConstants.java Add parameter endpoint URL, unit/semantic maps, aggregate metadata definitions.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiConnector.java Add parameter-metadata fetch and refactor common request logic.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiHandler.java Integrate parameter-metadata initialization, dynamic channel recreation, and metadata-driven updates.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiHandlerFactory.java Inject SmhiChannelTypeProvider and ChannelTypeRegistry into handler.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiTimeSeries.java Make timeseries generation metadata-based.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/Util.java Add channel-type/state-description creation and unit conversion based on metadata.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/provider/ParameterMetadata.java New record for parameter metadata.
bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/provider/SmhiChannelTypeProvider.java New storage-based channel type provider + in-memory metadata store.
bundles/org.openhab.binding.smhi/src/test/java/org/openhab/binding/smhi/internal/MockSmhiChannelTypeProvider.java Test helper for metadata storage.
bundles/org.openhab.binding.smhi/src/test/java/org/openhab/binding/smhi/internal/SmhiTest.java Update tests to use parameter metadata fixture and metadata-driven logic.
bundles/org.openhab.binding.smhi/src/test/resources/org/openhab/binding/smhi/internal/parameters.json New parameter metadata fixture.
bundles/org.openhab.binding.smhi/src/test/resources/org/openhab/binding/smhi/internal/snow1g2.json Remove unused forecast fixture.
bundles/org.openhab.binding.smhi/src/test/resources/org/openhab/binding/smhi/internal/snow1g3.json Remove unused forecast fixture.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See copilot comments

pacive added 4 commits April 28, 2026 16:46
Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing this patch. Guess this is the final review. All is well tested?

Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
@pacive
Copy link
Copy Markdown
Member Author

pacive commented Apr 29, 2026

Thanks for the review.

All is well tested?

I updated the tests to cover more different cases for the parameters, but that's as long as the API stays consistent. Could possibly add a testcase to simulate if another parameter would change in the same way as happened previously. Apart from that I need to improve my testing skills to verify that the Thing gets built properly and etc. But have done that manually with a few different configurations.

Copy link
Copy Markdown
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

@lsiepel lsiepel merged commit ee6ebad into openhab:main May 4, 2026
2 checks passed
@lsiepel lsiepel added this to the 5.2 milestone May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or new feature for an existing add-on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[smhi] Get parameters from API

3 participants