lewisbenge / hass-amber-electric

Home Assistant Component to pull the latest energy prices from Amber Electric
MIT License
27 stars 7 forks source link

IndexError: list index out of range #14

Closed antgeo closed 4 years ago

antgeo commented 4 years ago

Getting the following error running this sensor:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 292, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 451, in _async_add_entity entity.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 290, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 314, in _async_write_ha_state sstate = self.state File "/config/custom_components/amberelectric/sensor.py", line 100, in state return abs(self.calc_amber_price(self.amber_data.data.static_prices.b1.totalfixed_kwh_price, self.amber_data.data.static_prices.b1.loss_factor, current_price[0].wholesale_kwh_price)) IndexError: list index out of range

antgeo commented 4 years ago

Attached the json response from Amber's API amber.txt

lewisbenge commented 4 years ago

Can you please see if the version on the dev branch (https://github.com/lewisbenge/hass-amber-electric/blob/dev/custom_components/amberelectric/ambermodel.py) resolve your issue? On Victorian postcodes it appears the Amber API had not included particular dates in random elements of the response causing null errors. This commit should fix that.

antgeo commented 4 years ago

Resolved. Thanks!