[smhi] Use parameter API endpoint#20642
Conversation
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>
There was a problem hiding this comment.
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
ParameterMetadatamodel and parsing support for SMHI’s parameter metadata endpoint. - Introduce
SmhiChannelTypeProviderto 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.
Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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.
lsiepel
left a comment
There was a problem hiding this comment.
Thanks for providing this patch. Guess this is the final review. All is well tested?
Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
|
Thanks for the review.
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. |
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