Skip to content

Comments

Persist resolved unit type for Number entities as well as Sensor entities#61

Merged
seime merged 2 commits intoseime:masterfrom
ccutrer:number-entity-unit
Jan 1, 2026
Merged

Persist resolved unit type for Number entities as well as Sensor entities#61
seime merged 2 commits intoseime:masterfrom
ccutrer:number-entity-unit

Conversation

@ccutrer
Copy link
Contributor

@ccutrer ccutrer commented Dec 19, 2025

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.

…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>
Copy link
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 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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@seime seime merged commit abd4f53 into seime:master Jan 1, 2026
2 checks passed
@ccutrer ccutrer deleted the number-entity-unit branch January 1, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants