Persist resolved unit type for Number entities as well as Sensor entities#61
Merged
seime merged 2 commits intoseime:masterfrom Jan 1, 2026
Merged
Persist resolved unit type for Number entities as well as Sensor entities#61seime merged 2 commits intoseime:masterfrom
seime merged 2 commits intoseime:masterfrom
Conversation
…ties Otherwise we were setting the unit on the channel definition, but not being applied to the incoming number, so if the linked Item uses a different unit, it wasn't getting converted correctly. Signed-off-by: Cody Cutrer <cody@cutrer.us>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors unit type resolution logic to ensure that the resolved unit is persisted in the configuration for both Number and Sensor entities. Previously, the unit was set on the channel definition but not applied to incoming states, causing unit conversion issues when linked Items used different units.
Key Changes:
- Centralized unit type resolution logic by moving it from SensorMessageHandler to AbstractMessageHandler
- Updated both SensorMessageHandler and NumberMessageHandler to use the shared resolution method and persist units in configuration
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| AbstractMessageHandler.java | Added Configuration parameter to resolveNumericItemType() method to enable unit persistence; method now stores valid units in the configuration |
| SensorMessageHandler.java | Removed duplicate unit validation logic and removed unused UnitUtils import; now delegates to shared resolveNumericItemType() method |
| NumberMessageHandler.java | Updated resolveNumericItemType() call to pass configuration parameter for unit persistence |
Comments suppressed due to low confidence (1)
src/main/java/no/seime/openhab/binding/esphome/internal/message/AbstractMessageHandler.java:195
- Variable deviceClass may be null at this access as suggested by this null guard.
itemTypeToUse = deviceClass.getItemType();
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/no/seime/openhab/binding/esphome/internal/message/AbstractMessageHandler.java
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Otherwise we were setting the unit on the channel definition, but not being applied to the incoming state, so if the linked Item uses a different unit, it wasn't getting converted correctly.