JaccoR / hass-entso-e

Integration for Home Assistant to fetch day ahead energy prices from European countries via ENTSO-e Transparency Platform
Apache License 2.0
184 stars 31 forks source link

ValueError: min() iterable argument is empty #158

Closed olafz closed 2 months ago

olafz commented 5 months ago

Since two days, the update for the ENTSO-E day-ahead prices fails with a ValueError: min() iterable argument is empty. See the stack-trace below for the full error.

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:941

Update for sensor.entso_e_average_electricity_price_today fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 941, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1289, in async_device_update
    await self.async_update()
  File "/config/custom_components/entsoe/sensor.py", line 134, in async_update
    self._attr_extra_state_attributes = {x: self.coordinator.processed_data()[x] for x in self.coordinator.processed_data() if x not in invalid_keys and x not in existing_entities}
                                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/entsoe/coordinator.py", line 171, in processed_data
    "min_price": self.get_min_price(filtered_hourprices),
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/entsoe/coordinator.py", line 213, in get_min_price
    return min(hourprices.values())
           ^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: min() iterable argument is empty
olafz commented 5 months ago

Some extra debugging info:

WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open inside the event loop by custom integration 'entsoe' at custom_components/entsoe/coordinator.py, line 97: yesterday = pd.Timestamp.now(tz=str(time_zone)).replace(hour=0, minute=0, second=0) - pd.Timedelta(days = 1) (offender: /usr/local/lib/python3.12/site-packages/pytz/__init__.py, line 108: return open(filename, 'rb')), please create a bug report at https://github.com/JaccoR/hass-entso-e/issues

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component
    result = await _async_setup_component(hass, domain, config)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 447, in _async_setup_component
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/setup.py", line 449, in <genexpr>
    create_eager_task(
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 37, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 742, in async_setup_locked
    await self.async_setup(hass, integration=integration)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/entsoe/__init__.py", line 33, in async_setup_entry
    await entsoe_coordinator.async_config_entry_first_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 277, in async_config_entry_first_refresh
    await self._async_refresh(
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/entsoe/coordinator.py", line 97, in _async_update_data
    yesterday = pd.Timestamp.now(tz=str(time_zone)).replace(hour=0, minute=0, second=0) - pd.Timedelta(days = 1)
qwerk commented 5 months ago

Just to inform, I have the same issue. Also since two days.

AJKoster commented 5 months ago

Same error here...

Fidelity88 commented 5 months ago

Same here since about 2 or 3 days. It works if I completely add it again. But then reappears a day later

SjaakPeer commented 5 months ago

Same here, with fully updated HA: Attributes of "Average electricity price today" appear to be stuck on the data of a few day's back.

Fidelity88 commented 5 months ago

This workaround fixed my issue for now: https://github.com/JaccoR/hass-entso-e/issues/155#issuecomment-2155882331

SjaakPeer commented 5 months ago

This workaround fixed my issue for now: #155 (comment)

Yes, fixed the issue..... for now.....

Roeland54 commented 2 months ago

v0.4.0 is released this version contains fixes that solve a lot of warnings and known issues. This issue is probably also solved. Please update to the latest version. Closing this issue for now. If you still have issue please feel free to open a new issue.