mampfes / hacs_waste_collection_schedule

Home Assistant integration framework for (garbage collection) schedules
MIT License
1.04k stars 649 forks source link

[Bug]: ICS source fail: 'NoneType' object has no attribute 'calendar_title' #2896

Open f-zappa opened 19 hours ago

f-zappa commented 19 hours ago

I Have A Problem With:

The integration in general

What's Your Problem

Integration stopped working after updating to most recent version. Rolling back to previous version did not help. If I try to disable my existing configuration and create a new one, setup fails right after selecting any source of ics type (before I even choose a specific source).

Source (if relevant)

individual google calendar

Logs

# when activating my existing configuration:

2024-10-22 13:13:34.458 INFO (MainThread) [homeassistant.components.calendar] Setting up waste_collection_schedule.calendar
2024-10-22 13:13:34.458 ERROR (MainThread) [homeassistant.components.calendar] Error while setting up waste_collection_schedule platform for calendar
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/waste_collection_schedule/calendar.py", line 165, in async_setup_entry
    entities = create_calendar_entries([shell], coordinator=coordinator)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/waste_collection_schedule/calendar.py", line 129, in create_calendar_entries
    dedicated_calendar_types = shell.get_dedicated_calendar_types()
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_dedicated_calendar_types'
2024-10-22 13:13:34.459 INFO (MainThread) [homeassistant.components.sensor] Setting up waste_collection_schedule.sensor
2024-10-22 13:13:34.459 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up waste_collection_schedule platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/waste_collection_schedule/sensor.py", line 76, in async_setup_entry
    _LOGGER.debug("Adding sensors for %s", coordinator.shell.calendar_title)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'calendar_title'
2024-10-22 13:14:01.924 INFO (MainThread) [custom_components.opnsense.coordinator] Updating Data

2024-10-22 13:14:10.679 DEBUG (MainThread) [custom_components.waste_collection_schedule.init_ui] Setting up entry 01J7NTTTRSVANGSQ2NS2N5VKFS, with data {'name': 'ics', 'args': {'method': 'GET', 'title_template': '{{date.summary}}', 'version': 2, 'verify_ssl': True, 'headers': {}, 'url': 'https://calendar.google.com/calendar/ical/XXXXX%40group.calendar.google.com/public/basic.ics'}} and options {'calendar_title': 'Abfall', 'separator': ', ', 'fetch_time': '01:00', 'random_fetch_time_offset': 60, 'day_switch_time': '10:00', 'customize_select': ['Papiermuell', 'Biomuell', 'Gelber Sack'], 'customize': {'Restmülltonne': {'show': True, 'icon': 'mdi:delete'}, 'Papiermuell': {'show': True, 'icon': 'mdi:newspaper-variant-multiple'}, 'Biomuell': {'show': True, 'icon': 'mdi:leaf'}, 'Gelber Sack': {'show': True, 'icon': 'mdi:recycle'}}, 'sensors': [{'details_format': 'generic', 'skip': False, 'additional': True, 'name': 'Papiertonne', 'count': 1, 'leadtime': 60, 'value_template': '{% if value.daysTo == 0 %}heute{% elif value.daysTo == 1 %}morgen{% else %}-{% endif %}', 'types': ['Papiermuell']}, {'name': 'Restmüll', 'details_format': 'generic', 'count': 1, 'leadtime': 60, 'value_template': '{% if value.daysTo == 0 %}heute{% elif value.daysTo == 1 %}morgen{% else %}-{% endif %}', 'add_days_to': True, 'types': ['Restmülltonne']}, {'name': 'Gelbe Tonne', 'details_format': 'generic', 'count': 1, 'leadtime': 60, 'value_template': '{% if value.daysTo == 0 %}heute{% elif value.daysTo == 1 %}morgen{% else %}-{% endif %}', 'add_days_to': True, 'types': ['Gelber Sack']}, {'name': 'Biomüll', 'details_format': 'generic', 'count': 1, 'leadtime': 60, 'value_template': '{% if value.daysTo == 0 %}heute{% elif value.daysTo == 1 %}morgen{% else %}-{% endif %}', 'add_days_to': True, 'types': ['Biomuell']}]}
2024-10-22 13:14:10.690 ERROR (SyncWorker_2) [custom_components.waste_collection_schedule.waste_collection_schedule.source_shell] source not found: ics
2024-10-22 13:14:10.691 DEBUG (MainThread) [custom_components.waste_collection_schedule.wcs_coordinator] Finished fetching waste_collection_schedule data in 0.000 seconds (success: True)
2024-10-22 13:14:10.691 INFO (MainThread) [homeassistant.components.calendar] Setting up waste_collection_schedule.calendar
2024-10-22 13:14:10.692 ERROR (MainThread) [homeassistant.components.calendar] Error while setting up waste_collection_schedule platform for calendar
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/waste_collection_schedule/calendar.py", line 165, in async_setup_entry
    entities = create_calendar_entries([shell], coordinator=coordinator)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/waste_collection_schedule/calendar.py", line 129, in create_calendar_entries
    dedicated_calendar_types = shell.get_dedicated_calendar_types()
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_dedicated_calendar_types'
2024-10-22 13:14:10.692 INFO (MainThread) [homeassistant.components.sensor] Setting up waste_collection_schedule.sensor
2024-10-22 13:14:10.692 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up waste_collection_schedule platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/waste_collection_schedule/sensor.py", line 76, in async_setup_entry
    _LOGGER.debug("Adding sensors for %s", coordinator.shell.calendar_title)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'calendar_title'

# when creating a new configuration, after picking any .ics type source in the config flow:

2024-10-22 13:19:42.508 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 477, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 559, in _handle
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 210, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 370, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 417, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 520, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/waste_collection_schedule/config_flow.py", line 405, in async_step_source
    return await self.async_step_args()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/waste_collection_schedule/config_flow.py", line 676, in async_step_args
    schema, module = await self.__get_arg_schema(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/waste_collection_schedule/config_flow.py", line 484, in __get_arg_schema
    module = await self.hass.async_add_executor_job(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/source/ics.py", line 15, in <module>
    from waste_collection_schedule.service.ICS import ICS
  File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/service/ICS.py", line 7, in <module>
    from icalevents import icalevents
  File "/usr/local/lib/python3.12/site-packages/icalevents/icalevents.py", line 3, in <module>
    from .icalparser import parse_events, Event
  File "/usr/local/lib/python3.12/site-packages/icalevents/icalparser.py", line 18, in <module>
    from icalendar.windows_to_olson import WINDOWS_TO_OLSON
ModuleNotFoundError: No module named 'icalendar.windows_to_olson'

Relevant Configuration

# excerpt from core.config_entries

      {
        "created_at": "2024-09-13T13:58:16.601078+00:00",
        "data": {
          "name": "ics",
          "args": {
            "method": "GET",
            "title_template": "{{date.summary}}",
            "version": 2,
            "verify_ssl": true,
            "headers": {},
            "url": "https://calendar.google.com/calendar/ical/XXXXX%40group.calendar.google.com/public/basic.ics"
          }
        },
        "discovery_keys": {},
        "disabled_by": null,
        "domain": "waste_collection_schedule",
        "entry_id": "01J7NTTTRSVANGSQ2NS2N5VKFS",
        "minor_version": 3,
        "modified_at": "2024-10-19T11:55:52.885001+00:00",
        "options": {
          "calendar_title": "Abfall",
          "separator": ", ",
          "fetch_time": "01:00",
          "random_fetch_time_offset": 60,
          "day_switch_time": "10:00",
          "customize_select": [
            "Papiermuell",
            "Biomuell",
            "Gelber Sack"
          ],
          "customize": {
            "Restmülltonne": {
              "show": true,
              "icon": "mdi:delete"
            },
            "Papiermuell": {
              "show": true,
              "icon": "mdi:newspaper-variant-multiple"
            },
            "Biomuell": {
              "show": true,
              "icon": "mdi:leaf"
            },
            "Gelber Sack": {
              "show": true,
              "icon": "mdi:recycle"
            }
          },
          "sensors": [
            {
              "details_format": "generic",
              "skip": false,
              "additional": true,
              "name": "Papiertonne",
              "count": 1,
              "leadtime": 60,
              "value_template": "{% if value.daysTo == 0 %}heute{% elif value.daysTo == 1 %}morgen{% else %}-{% endif %}",
              "types": [
                "Papiermuell"
              ]
            },
            {
              "name": "Restmüll",
              "details_format": "generic",
              "count": 1,
              "leadtime": 60,
              "value_template": "{% if value.daysTo == 0 %}heute{% elif value.daysTo == 1 %}morgen{% else %}-{% endif %}",
              "add_days_to": true,
              "types": [
                "Restmülltonne"
              ]
            },
            {
              "name": "Gelbe Tonne",
              "details_format": "generic",
              "count": 1,
              "leadtime": 60,
              "value_template": "{% if value.daysTo == 0 %}heute{% elif value.daysTo == 1 %}morgen{% else %}-{% endif %}",
              "add_days_to": true,
              "types": [
                "Gelber Sack"
              ]
            },
            {
              "name": "Biomüll",
              "details_format": "generic",
              "count": 1,
              "leadtime": 60,
              "value_template": "{% if value.daysTo == 0 %}heute{% elif value.daysTo == 1 %}morgen{% else %}-{% endif %}",
              "add_days_to": true,
              "types": [
                "Biomuell"
              ]
            }
          ]
        },
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "title": "ICS",
        "unique_id": "ics{\"method\": \"GET\", \"title_template\": \"{{date.summary}}\", \"version\": 2, \"verify_ssl\": true, \"headers\": {}, \"url\": \"https://calendar.google.com/calendar/ical/XXXXX%40group.calendar.google.com/public/basic.ics\"}",
        "version": 2
      },

Checklist Source Error

Checklist Sensor Error

Required

jschanz commented 11 hours ago

Hello everyone,

Since the update to the latest version (2.3.0), the calendar is no longer working for me either. With version 2.3.0, all entities are no longer available. A rollback to 2.2.0 does restore the entities, but the ICS calendar itself is no longer available.

Reloading the calendar in the GUI after downgrade from 2.3.0 to 2.2.0 results in the following error message:

2024-10-22 21:14:36.248 ERROR (SyncWorker_9) [custom_components.waste_collection_schedule.waste_collection_schedule.source_shell] source not found: ics
2024-10-22 21:14:36.250 INFO (MainThread) [homeassistant.components.calendar] Setting up waste_collection_schedule.calendar
2024-10-22 21:14:36.250 ERROR (MainThread) [homeassistant.components.calendar] Error while setting up waste_collection_schedule platform for calendar
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/waste_collection_schedule/calendar.py", line 154, in async_setup_entry
    entities = create_calendar_entries([shell], coordinator=coordinator)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/waste_collection_schedule/calendar.py", line 120, in create_calendar_entries
    dedicated_calendar_types = shell.get_dedicated_calendar_types()
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_dedicated_calendar_types'
2024-10-22 21:14:36.251 INFO (MainThread) [homeassistant.components.sensor] Setting up waste_collection_schedule.sensor
2024-10-22 21:14:36.251 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up waste_collection_schedule platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/waste_collection_schedule/sensor.py", line 76, in async_setup_entry
    _LOGGER.debug("Adding sensors for %s", coordinator.shell.calendar_title)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'calendar_title'

With version 2.3.0, I received an HTTP 500 error for every calendar activity, along with the error message described above in the log. After an upgrade to Home Assistant 2024.10.3, the error has disappeared, and the integration, including the entities, can be loaded again. For me, the problem seems to be resolved for now. Maybe this information will help.