Fix ValueError for non-numeric value#166300
Fix ValueError for non-numeric value#166300LG-ThinQ-Integration wants to merge 9 commits intohome-assistant:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a Home Assistant sensor validation ValueError in the lg_thinq integration by avoiding setting a unit of measurement when a ThinQ property reports a non-numeric string value.
Changes:
- Gate assignment of
native_unit_of_measurementbehind a numeric-type check fordata.value. - Extend the debug log message to include the runtime type of
data.value.
07f3b73 to
3dc48da
Compare
frenck
left a comment
There was a problem hiding this comment.
Oh hi there @LG-ThinQ-Integration 👋
Thanks for the pull request. However, Copilot did catch some issues I agree with.
Additionally, this PR is missing tests. Please add a regression test that covers a sensor whose API value becomes a non-numeric string while a unit would normally be set, verifying that native_unit_of_measurement is cleared and no ValueError is raised.
../Frenck
Blogging my personal ramblings at frenck.dev
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
90755e4 to
94fb7aa
Compare
frenck
left a comment
There was a problem hiding this comment.
Thanks for the follow up @LG-ThinQ-Integration 👍
However, could you add the requested test case above?
Thanks already!
../Frenck
Blogging my personal ramblings at frenck.dev
f8c91d7 to
be8c4b7
Compare
joostlek
left a comment
There was a problem hiding this comment.
Okay so I don't want to block this PR per se as this change doesn't add the entities, but I do want to ask the question
be8c4b7 to
3b96771
Compare
|
The climate has seperated to #166865. |
|
@joostlek Given the remaining work, I don't believe these changes will be ready for the April 2026 release. Therefore, I'd like to revert the thinqconnect bump for now. Should I submit a separate revert PR, or is there another preferred way to handle this? Please let me know. |
0d3a738 to
3314324
Compare
Proposed change
The value of a refrigerator's temperature sensor is both a number and a string. Previously, there was no problem even if the value was a string and had a unit, but currently, a ValueError occurs, preventing the entity from being activated.
Error:
ValueError: Sensor sensor.2reb1krs11_h_middle_temperature has device class 'None', state class 'None' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'kimchi' (<class 'str'>)
Fix:
Modified to set 'unit_of_measurement' only when the data.value is a number.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: