Updated ics_calendar to restore compatibility with HA

This commit is contained in:
2025-05-08 10:02:22 +02:00
parent fef90d5a78
commit ca599eab7a
21 changed files with 1329 additions and 234 deletions

View File

@@ -1,39 +1,14 @@
"""Provide ICalendarParser class."""
import importlib
from datetime import datetime
from typing import Optional
from homeassistant.components.calendar import CalendarEvent
from .filter import Filter
from .parserevent import ParserEvent
class ICalendarParser:
"""Provide interface for various parser classes.
The class provides a static method , get_instace, to get a parser instance.
The non static methods allow this class to act as an "interface" for the
parser classes.
"""
@staticmethod
def get_class(parser: str):
"""Get the class of the requested parser."""
parser_module_name = ".parsers.parser_" + parser
parser = "Parser" + parser.upper()
try:
module = importlib.import_module(parser_module_name, __package__)
return getattr(module, parser)
except ImportError:
return None
@staticmethod
def get_instance(parser: str, *args):
"""Get an instance of the requested parser."""
parser_cls = ICalendarParser.get_class(parser)
if parser_cls is not None:
return parser_cls(*args)
return None
"""Provide interface for various parser classes."""
def set_content(self, content: str):
"""Parse content into a calendar object.
@@ -57,7 +32,7 @@ class ICalendarParser:
end: datetime,
include_all_day: bool,
offset_hours: int = 0,
) -> list[CalendarEvent]:
) -> list[ParserEvent]:
"""Get a list of events.
Gets the events from start to end, including or excluding all day
@@ -71,7 +46,7 @@ class ICalendarParser:
:param offset_hours the number of hours to offset the event
:type offset_hours int
:returns a list of events, or an empty list
:rtype list[CalendarEvent]
:rtype list[ParserEvent]
"""
def get_current_event(
@@ -80,7 +55,7 @@ class ICalendarParser:
now: datetime,
days: int,
offset_hours: int = 0,
) -> Optional[CalendarEvent]:
) -> Optional[ParserEvent]:
"""Get the current or next event.
Gets the current event, or the next upcoming event with in the
@@ -93,5 +68,5 @@ class ICalendarParser:
:type days int
:param offset_hours the number of hours to offset the event
:type offset_hours int
:returns a CalendarEvent or None
:returns a ParserEvent or None
"""