KoljaWindeler / ics

Integration that displays the next event of an ics link (support reoccuring events)
51 stars 12 forks source link

Error in check_fix_rrule (AttributeError: 'str' object has no attribute 'items') #36

Open liegri opened 2 years ago

liegri commented 2 years ago

Hi,

I just wanted to try this integration, but sadly I'm getting the following error repeatedly.

Log:

2021-10-16 17:29:19 ERROR (MainThread) [custom_components.ics.sensor] 
============= ICS Integration Error ================
2021-10-16 17:29:19 ERROR (MainThread) [custom_components.ics.sensor] unfortunately ICS hit an error, please open a ticket at
2021-10-16 17:29:19 ERROR (MainThread) [custom_components.ics.sensor] https://github.com/KoljaWindeler/ics/issues
2021-10-16 17:29:19 ERROR (MainThread) [custom_components.ics.sensor] and paste the following output:
2021-10-16 17:29:19 ERROR (MainThread) [custom_components.ics.sensor] Traceback (most recent call last):
  File "/config/custom_components/ics/sensor.py", line 173, in get_data
    _LOGGER.debug(f"fixed {self.check_fix_rrule(cal)} RRule dates")
  File "/config/custom_components/ics/sensor.py", line 152, in check_fix_rrule
    if("UNTIL" in event["RRULE"]):
  File "/usr/local/lib/python3.9/site-packages/icalendar/caselessdict.py", line 91, in __eq__
    return self is other or dict(self.items()) == dict(other.items())
AttributeError: 'str' object has no attribute 'items'

Integration details:

HASS details:

Let me know if I can provide you with any further details.

I hope you can fix this issue soon, thank you in advance :)

liegri commented 2 years ago

After some debugging I found out that event["RRULE"] was an array for one of my calendar events.

This quick and very dirty fix is now working for me (changes at == START OF FIX ==):

# inside custom_components/isc/sensor.py, check_fix_rrule
for event in calendar.walk('vevent'):
    if("RRULE" in event):
        # == START OF FIX ==
        if(isinstance(event["RRULE"], list):
            event["RRULE"] = event["RRULE"][0]
        # == END OF FIX ==
        if("UNTIL" in event["RRULE"]):
            # ...

Sadly (as of right now) I have no idea how this can be handled correctly, otherwise I would have created a PR. But maybe my findings help you solve the bug.

KoljaWindeler commented 2 years ago

Hmm this seems to be an issue with the underlaying iCalendar .. would you open your ticket there? Also: I'd totally accept that pull request. ..