mawinkler / astroweather

Asynchronous Astro Weather Forecast for Home Assistant
GNU General Public License v3.0
69 stars 9 forks source link

Weather entity not added after upgrading to 0.42.0 #40

Closed kaizersoje closed 9 months ago

kaizersoje commented 10 months ago

After upgrading to v0.42.0, the following entities are not getting set up -

This is what I can see in the logs.

Error adding entities for domain weather with platform astroweather
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 743, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 843, in _async_write_ha_state
    state, attr = self._async_generate_attributes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 787, in _async_generate_attributes
    attr.update(self.extra_state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/astroweather/weather.py", line 446, in extra_state_attributes
    ATTR_WEATHER_DEEPSKY_TOMORROW_PLAIN: self.deepsky_forecast_tomorrow_plain,
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/astroweather/weather.py", line 295, in deepsky_forecast_tomorrow_plain
    return self._current.deepsky_forecast_tomorrow_plain
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyastroweatherio/dataclasses.py", line 463, in deepsky_forecast_tomorrow_plain
    for nightly_condition in self._deepsky_forecast[1].nightly_conditions:
                             ~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
Error adding entities for domain sensor with platform astroweather
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 743, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 843, in _async_write_ha_state
    state, attr = self._async_generate_attributes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 784, in _async_generate_attributes
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 749, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 501, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/astroweather/sensor.py", line 449, in native_value
    return getattr(self.coordinator.data[SENSOR_NAME], self._sensor, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyastroweatherio/dataclasses.py", line 447, in deepsky_forecast_tomorrow
    for nightly_condition in self._deepsky_forecast[1].nightly_conditions:
                             ~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
mawinkler commented 10 months ago

Crap. First thing found and resolved in the code. I forget to test for the availability of item [1] before accessing it. Currently evaluating why it is missing. I'm continuously testing with five different locations and they all work fine in regards the forecast. But a 6th test location in Chile fails with the same error. Out of curiosity, my I ask for your location?

mawinkler commented 10 months ago

Found it. I will draft a new release tomorrow. Until then change the dependency to pyastroweatherio in manifest.json to

"requirements": [ "pyastroweatherio==0.42.4" ],

kaizersoje commented 10 months ago

Crap. First thing found and resolved in the code. I forget to test for the availability of item [1] before accessing it. Currently evaluating why it is missing. I'm continuously testing with five different locations and they all work fine in regards the forecast. But a 6th test location in Chile fails with the same error. Out of curiosity, my I ask for your location?

I am located in Melbourne, Australia

kaizersoje commented 10 months ago

Found it. I will draft a new release tomorrow. Until then change the dependency to pyastroweatherio in manifest.json to

"requirements": [ "pyastroweatherio==0.42.4" ],

This fixed the issue.

mawinkler commented 9 months ago

Calculating all these moving objects for any global location, time, and timezone sometimes screws my head ;-). Thank you for testing. Will create a release then.