Fanart - IndexError: list index out of range
Closed this issue · 3 comments
Describe the Bug
Index out of bounds error
The Error
hass[2263]: 2020-05-13 09:57:10 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up radarr_upcoming_media platform for sensor
hass[2263]: Traceback (most recent call last):
hass[2263]: File "/opt/Homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform
hass[2263]: await asyncio.gather(*pending)
hass[2263]: File "/opt/Homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities
hass[2263]: await asyncio.gather(*tasks)
hass[2263]: File "/opt/Homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 445, in _async_add_entity
hass[2263]: entity.async_write_ha_state()
hass[2263]: File "/opt/Homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 297, in async_write_ha_state
hass[2263]: self._async_write_ha_state() # type: ignore
hass[2263]: File "/opt/Homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 324, in _async_write_ha_state
hass[2263]: attr.update(self.device_state_attributes or {})
hass[2263]: File "/home/groot/Documents/Home_Assistant/custom_components/radarr_upcoming_media/sensor.py", line 121, in device_state_attributes
hass[2263]: if '.jpg' in movie['images'][1]:
hass[2263]: IndexError: list index out of range
Indicate if you followed all steps in the troubleshooting doc
Yes
What data does the sensor display if any?
Displays nothing because sensor fails to be setup during Home Assistant staring procedure
Does the default Home Assistant Radarr component work for you?
Yes
Home Assistant Version
0.109.4
Additional Context
Not every movie from radarr returns more than one image url. Need an array length check or use first element as default. Tested the below code change and the sensor functions normally
From:
if '.jpg' in movie['images'][1]: card_item['fanart'] = movie['images'][1]
To:
if '.jpg' in movie['images'][0]: card_item['fanart'] = movie['images'][0]
Could you try the latest release ( 0.3.2 ) and let me know if this is still an issue?
Issue #12 ended up being a duplicate of this issue, but confirmed the fix was working.
Works good!