home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.16k stars 29.84k forks source link

Metoffice integration Unit of measure sensor.met_office_gogerddan_visibility_distance_3_hourly #122521

Open dretful opened 1 month ago

dretful commented 1 month ago

The problem

Unit is km but value retrieved is text 20-40

Logger: homeassistant Source: components/sensor/init.py:655 First occurred: 23 July 2024 at 12:08:53 (97 occurrences) Last logged: 12:08:53

Error doing job: Task exception was never retrieved (None) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 648, in state numerical_value = int(value) ^^^^^^^^^^ ValueError: invalid literal for int() with base 10: '20-40'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 651, in state numerical_value = float(value) ^^^^^^^^^^^^ ValueError: could not convert string to float: '20-40'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 255, in _handle_refresh_interval await self._async_refresh(log_failures=True, scheduled=True) File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 411, in _async_refresh self.async_update_listeners() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_update_listeners update_callback() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 491, in _handle_coordinator_update self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1007, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1133, in _async_write_ha_state state, attr, capabilities, shadowed_attr = self.async_calculate_state() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1068, in async_calculate_state state = self._stringify_state(available) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1013, in _stringify_state if (state := self.state) is None: ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 655, in state raise ValueError( ValueError: Sensor sensor.met_office_gogerddan_visibility_distance_3_hourly has device class 'None', state class 'None' unit 'km' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '20-40' (<class 'str'>)

What version of Home Assistant Core has the issue?

core-2024.7.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Metoffice

Link to integration documentation on our website

https://www.home-assistant.io/integrations/metoffice/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Other units are wrong too.

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @mrharcombe, @avee87, mind taking a look at this issue as it has been labeled with an integration (metoffice) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `metoffice` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign metoffice` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


metoffice documentation metoffice source (message by IssueLinks)

dretful commented 1 month ago

Can I suggest that you edit sensor.py and delete line 115 native_unit_of_measurement=UnitOfLength.KILOMETERS, so that it works like the visibility section above?

thats because in const.py: VISIBILITY_DISTANCE_CLASSES = { "VP": "<1", "PO": "1-4", "MO": "4-10", "GO": "10-20", "VG": "20-40", "EX": ">40", } none of these are numbers.