youdroid / home-assistant-sickchill

🎥 SickChill component to feed Upcoming Media Card.
3 stars 3 forks source link

Update for sensor.medusa fails: KeyError: '81' #11

Closed ghost closed 4 years ago

ghost commented 4 years ago

I'm using this addon with Medusa which has the same API as Sickchill, however, one TV show is crashing the sensor.

According to the log it's this one causing the issue, but I'm not sure yet why: https://thetvdb.com/series/disney-animated-shorts ?indexername=tvdb&seriesid=78988

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 278, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 471, in async_device_update
    await self.hass.async_add_executor_job(self.update)  # type: ignore
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/sickchill/sensor.py", line 122, in update
    last_season = all_season_show['data'][str(nb_seasons)]
KeyError: '81'

Edit: Seems to me that the sensor does't handle dates/years as season numbering. Since your doing a len() it's counting instead to 81 instead of using '2003' or whatever is the 81'st season.

ghost commented 4 years ago

Quick and dirty hack that seems to work if season numbers differ from the default numbering:

                try:
                    last_season = all_season_show['data'][str(nb_seasons)]
                except:
                    last_season = all_season_show['data'][list(all_season_show['data'])[nb_seasons]]
youdroid commented 4 years ago

Hi!

Thanks for your feedback, and I'm sorry for the problem. Thank you for your first analysis, and detail of the ticket. I think I have all the elements to reproduce and fix the bug. I'll take a look at your fix.

I will come back to you with a new release which fixes the bug.

Have a nice day

youdroid commented 4 years ago

I added your TV show to my sickchill app with hopes of reproducing your bug. But unfortunately I have no error on my side.

The TV show does not appear in HA because it does not have an airdate from the sickchill APIs.

Does the problem only appear with Medusa? I think

ghost commented 4 years ago

Strange, I thought the v1 API of medusa is identical to sickchill and all the other forks... Are you using TVDBv2 as a source? I find it very strange if sickchill would rewrite the season-information coming from the site...

As long as this isn't an issue for you feel free to close the issue :)

youdroid commented 4 years ago

In the end, I also have this error on this TV series. To correct this, I did an API call to retrieve the list of seasons and get the latest. That way I would no longer have an error with the size of the array I recovered before.