astrandb / viva

A modern Home Assistant integration for ViVa weather service from Swedish Sjöfartsverket
MIT License
5 stars 1 forks source link

Sensor type Sight can not handle "greater than" (>) sign #32

Closed moorgrove closed 8 months ago

moorgrove commented 8 months ago

The problem

If the sight is greater than 20 000 meters ViVa reports it as >20000 which is not convertible into a float value.

2023-10-20 10:37:00.037 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 588, in state
    numerical_value = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '>20000'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 591, in state
    numerical_value = float(value)
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: '>20000'

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 233, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 389, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 172, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 469, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 779, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 879, in _async_write_ha_state
    state, attr = self._async_generate_attributes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 820, in _async_generate_attributes
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 785, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 595, in state
    raise ValueError(
ValueError: Sensor sensor.tan_sikt has device class 'distance', state class 'None' unit 'm' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '>20000' (<class 'str'>)

Version of viva integration having the issue?

1.0.3

Version of Home Assistant Core having the issue?

2023.10.3

Anything in the logs that might be useful for us?

No response

Additional information

No response

astrandb commented 8 months ago

I am aware of this problem. Home Assistant has been more and more sesitive to this type of data. I think I will just remove the">" character before storing the value in HA.