JonasJoKuJonas / homeassistant-WebUntis

Custom component to access data from Web Untis in Home Assistant
https://community.home-assistant.io/t/webuntis-timetable-in-ha/568273
MIT License
52 stars 12 forks source link

List index out of range #34

Closed rschueler closed 1 year ago

rschueler commented 1 year ago

Since prev. version I am not able to use the component any more. I am getting this error

2022-12-16 20:06:11.415 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry .... for webuntis Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 372, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/webuntis/init.py", line 49, in async_setup_entry await server.async_update() File "/config/custom_components/webuntis/init.py", line 133, in async_update await self._async_status_request() File "/config/custom_components/webuntis/init.py", line 183, in _async_status_request self.next_class = await self._hass.async_add_executor_job(self._next_class) File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/webuntis/init.py", line 292, in _next_class lesson = lesson_list[0] IndexError: list index out of range

JonasJoKuJonas commented 1 year ago

When is the next time there is a school lesson?

JonasJoKuJonas commented 1 year ago

Has anything changed with version v0.3.1?

rschueler commented 1 year ago

It is possible, that the service does not provide any lessons right now, because in the app there´s also only the next day visible and currently there is nothing, because it is weekend.

After upgrading to 0.3.1 the error changed to:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/webuntis/utils/datetime_utils.py", line 47, in _format
    int(obj)  # is this already formatted?
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 372, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/webuntis/__init__.py", line 49, in async_setup_entry
    await server.async_update()
  File "/config/custom_components/webuntis/__init__.py", line 133, in async_update
    await self._async_status_request()
  File "/config/custom_components/webuntis/__init__.py", line 209, in _async_status_request
    self.next_day_json = await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/webuntis/__init__.py", line 366, in _next_day_json
    table = self.session.timetable(start=day, end=day, **timetable_object)
  File "/usr/local/lib/python3.10/site-packages/webuntis/utils/misc.py", line 146, in inner
    result_class, jsonrpc_method, jsonrpc_args = func(self, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/webuntis/session.py", line 220, in timetable
    parameters = self._create_date_param(end, start,
  File "/usr/local/lib/python3.10/site-packages/webuntis/session.py", line 443, in _create_date_param
    json_start = utils.datetime_utils.format_date(start)
  File "/usr/local/lib/python3.10/site-packages/webuntis/utils/datetime_utils.py", line 37, in format_date
    return _format(obj, 'date')
  File "/usr/local/lib/python3.10/site-packages/webuntis/utils/datetime_utils.py", line 49, in _format
    return int(datetime.datetime.strftime(obj, form_string))
TypeError: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'NoneType' object
JonasJoKuJonas commented 1 year ago

It is possible, that the service does not provide any lessons right now, because in the app there´s also only the next day visible and currently there is nothing, because it is weekend.

That is what i was thinking. Perhaps your school is limiting you to only see the next day. I will try to catch the error so it is not making trouble.

JonasJoKuJonas commented 1 year ago

fixed error in v0.3.2