Repository navigation
(wmbus_common) Don't assign "?" unit to sensors of fields without unit suffix - #56
Closed
KrzysztofHajdamowicz wants to merge 2 commits into
Closed
KrzysztofHajdamowicz wants to merge 2 commits into
KrzysztofHajdamowicz wants to merge 2 commits into
Conversation
For well-known fields without a unit suffix (e.g. timestamp), the auto-detected unit_of_measurement fell back to "?". Home Assistant treats any sensor with a unit as numeric, while its ESPHome integration delivers a datetime for device_class: timestamp - every state update is rejected and the entity stays unavailable forever. Skip setting unit_of_measurement entirely when no unit can be inferred from the field name. Fields with a proper unit suffix (_kwh, _m3, _dbm, ...) are unaffected. Fixes IoTLabs-pl#55 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
|
@KrzysztofHajdamowicz Can you check if it still works? |
Member
|
Superseded by #75 |
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.
Problem
As described in #55: for well-known fields without a unit suffix (e.g.
timestamp), the auto-detectedunit_of_measurementfell back to"?".Home Assistant treats any sensor with a unit of measurement as numeric, while its ESPHome integration delivers a
datetimevalue fordevice_class: timestampsensors. This conflict makes HA reject every state update, so the entity stays unavailable forever. The only workaround was an explicitunit_of_measurement: ""in the user's YAML.Fix
get_human_readable_unit()returns an empty string instead of"?"when no unit can be inferred from the field name (the function has a single call site, so this is safe),default_unit_of_measurement()skips settingunit_of_measuremententirely in that case.Fields with a proper unit suffix (
_kwh,_m3,_dbm, …) are unaffected — the only behavioral change is for fields that previously got the question mark.Also added a
field: timestampsensor withdevice_class: timestamptotests/wmbus.yamlto cover this case.Fixes #55
🤖 Generated with Claude Code