Skip to content

Keep resolveConfig in sync - #5776

Merged
mherwege merged 1 commit into
openhab:mainfrom
lsiepel:resolveconfig-addition
Aug 14, 2026
Merged

Keep resolveConfig in sync#5776
mherwege merged 1 commit into
openhab:mainfrom
lsiepel:resolveconfig-addition

Conversation

@lsiepel

@lsiepel lsiepel commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

As a follow up to #5568

That PR made the BaseThingHandler caches the resolved Thing configuration in resolvedConfig.

The default thingUpdated(Thing) implementation updates both the Thing and this cache. Custom implementations cannot do the same because resolvedConfig is private. Assigning a new value to this.thing can therefore leave getConfig() and getConfigAs() returning configuration resolved from the previous Thing.

This change extracts the existing replacement logic into a protected final setThing(Thing) method. The default thingUpdated(Thing) implementation uses this method, so its behavior remains unchanged.

Custom implementations can now replace the Thing without using the default dispose/reinitialize lifecycle while keeping the resolved configuration cache in sync.

A unit test was added that populates the old cache, replaces the Thing using setThing(), and verifies that the new resolved configuration is returned.

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
@lsiepel
lsiepel requested a review from a team as a code owner August 13, 2026 22:08
Copilot AI lite review requested due to automatic review settings August 13, 2026 22:08
@lsiepel

lsiepel commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

fyi @wborn / @florian-h05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses a correctness gap introduced by caching resolved Thing configuration in BaseThingHandler: replacing this.thing directly could leave getConfig() / getConfigAs() returning values resolved from a previous Thing. It extracts the Thing+cache replacement logic into a dedicated protected method so custom thingUpdated(Thing) implementations can keep the cache consistent without forcing a full dispose/reinitialize lifecycle.

Changes:

  • Extracted Thing replacement + resolved-config refresh into a new protected helper (setThing(Thing)), and updated the default thingUpdated(Thing) to use it.
  • Added a unit test that primes the config cache, replaces the Thing via the new helper, and asserts the resolved configuration is updated.

Reviewed changes

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

File Description
bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/BaseThingHandler.java Adds a protected helper to replace the handled Thing while keeping the resolved configuration cache in sync.
bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/BaseThingHandlerTest.java Adds coverage to ensure setThing() updates the resolved configuration cache even after it was previously populated.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@florian-h05 florian-h05 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!

@mherwege mherwege left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@mherwege
mherwege merged commit 2f8343f into openhab:main Aug 14, 2026
5 checks passed
@mherwege mherwege added this to the 5.3 milestone Aug 14, 2026
@mherwege mherwege added the enhancement An enhancement or new feature of the Core label Aug 14, 2026
@lsiepel
lsiepel deleted the resolveconfig-addition branch August 14, 2026 12:35
wborn pushed a commit that referenced this pull request Aug 20, 2026
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
@wborn wborn added the backported A PR that has been cherry-picked to a patch release branch label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported A PR that has been cherry-picked to a patch release branch enhancement An enhancement or new feature of the Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants