Skip to content

IndexError on 'Soft reset' / 'Restablecer' button when no consumption data is available #320

Description

@alnavasa

Description

Pressing the Restablecer (Soft reset) button on the device throws an unhandled IndexError when consumptions_daily_sum is empty.

This happens in installs where Datadis hasn't returned consumption data yet — for example, when contracts lookup fails (contracts update failed or no contracts found in the provided account) and the user tries to recover by hitting Restablecer.

Setup

  • Home Assistant Core: 2026.4.4
  • HAOS: 17.2
  • edata: 2025.11.3

Stack trace

File "/config/custom_components/edata/entity.py", line 78, in async_press
    await self._action()
File "/config/custom_components/edata/coordinator.py", line 754, in async_soft_reset
    if not await self.check_statistics_integrity():
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/edata/coordinator.py", line 317, in check_statistics_integrity
    self._edata.data["consumptions_daily_sum"][0]["datetime"]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

The UI surfaces this as the toast: No se pudo realizar la acción button/press. list index out of range.

Steps to reproduce

  1. Install edata.
  2. Configure Datadis credentials such that the account returns no contracts (e.g., NIF authorization not yet propagated).
  3. Wait for the integration to log contracts update failed or no contracts found in the provided account.
  4. Press the Restablecer button on the edata device.

Expected behavior

check_statistics_integrity() should handle the empty-list case gracefully (skip the integrity check, or return early with a meaningful log line) instead of raising IndexError. Bonus: the button itself could show a friendlier "no data to reset" message in the toast.

Suggested fix

Guard the access at coordinator.py:317:

daily_sum = self._edata.data.get("consumptions_daily_sum") or []
if not daily_sum:
    _LOGGER.warning("No consumption data yet; skipping integrity check")
    return True  # or False, depending on intended semantics
first_dt = daily_sum[0]["datetime"]

Notes

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions