Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: could not convert string to float: 'No Departures' in HA 2023.5 #16

Open
keithellis74 opened this issue May 7, 2023 · 2 comments

Comments

@keithellis74
Copy link

After upgrading Home Assistant to 2023.5 I now get a ValueError: could not convert string to float: 'No Departures'
Complete output from log is below:

Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:583
Integration: Sensor (documentation, issues)
First occurred: 18:55:38 (2 occurrences)
Last logged: 18:55:38

Error adding entities for domain sensor with platform realtime_trains_api
Error while setting up realtime_trains_api platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 581, in state
    numerical_value = float(value)  # type:ignore[arg-type]
ValueError: could not convert string to float: 'No Departures'

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 455, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 731, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 846, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 585, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 649, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 591, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, in state
    raise ValueError(
ValueError: Sensor sensor.next_train_from_ips_to_lst has device class None, state class None unit min and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: No Departures (<class 'str'>)
@keithellis74
Copy link
Author

I replaced the following code in sensor.py at lines 203 and 204:

    if nextDepartureEstimatedTs is None:
        self._state = "No Departures"

with

    if nextDepartureEstimatedTs is None:
        self._state = "0"

and I no longer get the error. There is probably a more elegant way of doing this, but the integration now runs without errors. However instead of showing "No departures" it now looks like this.

Screenshot 2023-05-07 at 19 20 50

@pbulteel
Copy link

I have the same issue.

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

No branches or pull requests

2 participants