franc6 / ics_calendar

Provides an ICS (icalendar) platform for the Home Assistant calendar
Apache License 2.0
153 stars 23 forks source link

Calendar Update Failed #193

Open JayWll opened 4 days ago

JayWll commented 4 days ago

Home Assistant Setup Please indicate your version of HA and how it is installed.

Version: 2024.11.2

Installation Type (put an X between the square brackets for your HA): [x] Home Assistant OS [] Home Assistant Supervised [] Home Assistant Container [] Home Assistant Core

Hardware platform: [x] ARM [] x86-64

Describe the bug One of my calendars that had previously been working has been consistently failing over the past few days. No events are visible in the calendar. Other calendars managed through ics_calendar are not experiencing any issue. I assime therefore this must be related to some content/event on the calendar itself, but I can't figure out what that could be. The error from the home assistant logs is below, although I've truncated both the ValueError lines as they're each several thousand characters long.

Validating the ical file through https://icalendar.org/validator.html results in no errors found.

I'm using ics_calendar version 5.0.4 installed through HACS.

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/icalendar/parser.py", line 326, in parts
    validate_token(name)
  File "/usr/local/lib/python3.12/site-packages/icalendar/parser.py", line 115, in validate_token
    raise ValueError(name)
ValueError: 䕂䥇㩎䍖䱁久䅄൒嘊剅䥓乏㈺〮਍剐䑏䑉樺祡汷⽬捩污਍䅎䕍场

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 944, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1304, in async_device_update
    await hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ics_calendar/calendar.py", line 209, in update
    self.data.update()
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 184, in wrapper
    result = method(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ics_calendar/calendar.py", line 329, in update
    self.parser.set_content(self._calendar_data.get())
  File "/config/custom_components/ics_calendar/parsers/parser_rie.py", line 33, in set_content
    self._calendar = Calendar.from_ical(content)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/icalendar/cal.py", line 354, in from_ical
    name, params, vals = line.parts()
                         ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/icalendar/parser.py", line 340, in parts
    raise ValueError(
ValueError: Content line could not be parsed into parts: '䕂䥇㩎䍖䱁久䅄൒嘊剅
JayWll commented 5 hours ago

After much exploration, I managed to track the problem down to the problematic calendar event, and I eventually figured out that its description included the Unicode character for a non breaking space \u00a0.

I was able to replace it with a regular space and all is now well. I'm not sure what ics_calendar's expected behaviour should be.

franc6 commented 1 hour ago

My expectation is that it would work. :)

I might be able to work around it, but when I have the chance, I’ll see if I can reproduce it with something small and submit a bit report to the parser. As long as it was UTF-8 encoded correctly, it should be allowed, IMO.