mawinkler / astroweather

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

Astronomical Sun Next Rising and Setting sensor cannot be loaded #13

Closed samhaa closed 2 years ago

samhaa commented 2 years ago

Running v0.20.9. sensor.astroweather_sun_next_rising_astronomical and sensor.astroweather_sun_next_setting_astronomical hangs when loading integration.

Logger: homeassistant.components.sensor
Source: custom_components/astroweather/sensor.py:322
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 01:12:27 (2 occurrences)
Last logged: 01:12:27

Error adding entities for domain sensor with platform astroweather
Error while setting up astroweather platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 614, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 799, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 532, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 570, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _stringify_state
    if (state := self.state) is None:
  File "/config/custom_components/astroweather/sensor.py", line 322, in state
    return getattr(self.coordinator.data[SENSOR_NAME], self._sensor, None)
  File "/usr/local/lib/python3.9/site-packages/pyastroweatherio/dataclasses.py", line 244, in sun_next_setting_astro
    return self._sun_next_setting_astro.replace(microsecond=0).isoformat()
TypeError: str.replace() takes no keyword arguments

I think this is related to my location as i live in Finland and sun elevation is getting smaller towards summer.

All other sensor are working fine.

state sun.sun=below_horizon; 
next_dawn=2022-05-04T01:11:36.498974+00:00, 
next_dusk=2022-05-04T19:25:15.377582+00:00, 
next_midnight=2022-05-04T22:17:06+00:00, 
next_noon=2022-05-04T10:17:13+00:00, 
next_rising=2022-05-04T02:08:10.195656+00:00, 
next_setting=2022-05-04T18:27:55.950615+00:00, 
elevation=-13.62, azimuth=7.91, rising=True, 
friendly_name=Sun @ 2022-05-04T01:12:25.001091+03:00
mawinkler commented 2 years ago

I identified the problem and will try to fix it in the next few days. Thank you for reporting.

mawinkler commented 2 years ago

Hi, sorry that it took a while. The issue should be fixed with the new release v0.21.0

mawinkler commented 2 years ago

resolved