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

TypeError: dailyData[currentIndex][PropertyName.START_INDEX.value] is NoneType (ran by Home Assistant) #74

Closed
C-Duv opened this issue Dec 9, 2024 · 4 comments

Comments

@C-Duv
Copy link

C-Duv commented Dec 9, 2024

Hello, I have an issue running the library. I am not using it directly: I am running it via home-assistant-gazpar but I think the issue comes from the library so I am posting it there.

Home Assistant logs shows

2024-12-09 09:14:50.623 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 1055, in _async_update_entity_states
    await entity.async_update_ha_state(True)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 978, in async_update_ha_state
    self._async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1148, in _async_write_ha_state
    self.__async_calculate_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1085, in __async_calculate_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1029, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/config/custom_components/gazpar/sensor.py", line 239, in state
    return Util.toState(self._dataByFrequency)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gazpar/util.py", line 38, in toState
    while (currentIndex < len(dailyData)) and (float(dailyData[currentIndex][PropertyName.START_INDEX.value]) == float(dailyData[currentIndex][PropertyName.END_INDEX.value])):
                                               ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: float() argument must be a string or a real number, not 'NoneType'
2024-12-09 09:14:52.169 ERROR (SyncWorker_3) [pygazpar.datasource] An error occurred while loading data. Retry in 3 seconds.
2024-12-09 09:14:55.403 ERROR (SyncWorker_3) [pygazpar.datasource] An error occurred while loading data. Retry in 3 seconds.
2024-12-09 09:14:58.636 ERROR (SyncWorker_3) [pygazpar.datasource] An error occurred while loading data. Retry in 3 seconds.
2024-12-09 09:15:01.883 ERROR (SyncWorker_3) [pygazpar.datasource] An error occurred while loading data. Retry in 3 seconds.
2024-12-09 09:15:05.119 ERROR (SyncWorker_3) [pygazpar.datasource] An error occurred while loading data. Retry in 3 seconds.
2024-12-09 09:15:08.350 ERROR (SyncWorker_3) [pygazpar.datasource] An error occurred while loading data. Retry in 3 seconds.
2024-12-09 09:15:13.283 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 978, in async_update_ha_state
    self._async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1148, in _async_write_ha_state
    self.__async_calculate_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1085, in __async_calculate_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1029, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/config/custom_components/gazpar/sensor.py", line 239, in state
    return Util.toState(self._dataByFrequency)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gazpar/util.py", line 38, in toState
    while (currentIndex < len(dailyData)) and (float(dailyData[currentIndex][PropertyName.START_INDEX.value]) == float(dailyData[currentIndex][PropertyName.END_INDEX.value])):
                                               ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: float() argument must be a string or a real number, not 'NoneType'

I guess something is wrong with the obtained data but I feel library should not "crash" like that.

Note: My home-assistant-gazpar's scan_interval is set to 08:00:00.

@C-Duv
Copy link
Author

C-Duv commented Dec 9, 2024

By the look of ssenart/home-assistant-gazpar#72 I guess you reproduced the bug?

@ssenart
Copy link
Owner

ssenart commented Dec 9, 2024

Yes, thanks.

The bug was triggered by empty measures where we expect some.

Anyway, I fix that case in: https://github.com/ssenart/home-assistant-gazpar/releases/tag/1.3.11-alpha.0

And in the meantime, GrDF republished clean data. The problem should be fixed on your side as well without doing anything. Do you confirm ?

@C-Duv
Copy link
Author

C-Duv commented Dec 9, 2024

Great, I'll tell you tomorrow then, once the update process occurs in Home Assistant.

@C-Duv
Copy link
Author

C-Duv commented Dec 15, 2024

Yes, it does not fail anymore: I do have data now.

Only error I sometimes get in the logs are:

2024-12-15 06:14:28.993 ERROR (SyncWorker_0) [pygazpar.datasource] An error occurred while loading data. Retry in 3 seconds.

But:

  • The data from yesterday are not available (but I think I've read something about this in an issue)
  • Sometime there are negative reading (decreasing the consumption)

@C-Duv C-Duv closed this as completed Dec 15, 2024
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