DarwinsBuddy / WienerNetzeSmartmeter

A home-assistant integration supporting WienerNetze Smartmeters as sensors
121 stars 12 forks source link

IndexError: list index out of range #196

Closed acdcnow closed 7 months ago

acdcnow commented 8 months ago

Hi,

Running ha 2023.11.0 and the latest version of wnsm v1.3.2

Looks like that I do not have an historical data in the wnsm portal hence the error.

Logger: homeassistant.components.sensor Source: helpers/entity_platform.py:573 Integration: Sensor (documentation, issues) First occurred: 06:27:01 (1 occurrences) Last logged: 06:27:01

wnsm: Error on device update! Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 573, in _async_add_entity await entity.async_device_update(warning=False) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 957, in async_device_update await self.async_update() File "/config/custom_components/wnsm/statistics_sensor.py", line 126, in async_update await self._import_historical_data(smartmeter) File "/config/custom_components/wnsm/statistics_sensor.py", line 180, in _import_historical_data _LOGGER.debug(f"Importing statistics from {statistics[0]} to {statistics[-1]}")


IndexError: list index out of range
DarwinsBuddy commented 7 months ago

have to look into it. potentially the API changed

reox commented 7 months ago

I guess the fix for this is easy (haven't tested it though):

if statistics:
     _LOGGER.debug(f"Importing statistics from {statistics[0]} to {statistics[-1]}")
else:
    _LOGGER.debug("No statistics data collected.")

It can apparently happen that the array is empty.