From 67b2c2eddee5a7a0e718c9cceed5bafe9bf0769d Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Mon, 8 Dec 2025 12:06:06 +0100 Subject: [PATCH] Updated ics_calendar --- custom_components/ics_calendar/__init__.py | 2 +- custom_components/ics_calendar/calendar.py | 17 +++++------ .../ics_calendar/calendardata.py | 10 ++++--- custom_components/ics_calendar/config_flow.py | 28 +++++++++---------- custom_components/ics_calendar/const.py | 2 +- custom_components/ics_calendar/manifest.json | 2 +- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/custom_components/ics_calendar/__init__.py b/custom_components/ics_calendar/__init__.py index b7b6866..ecbef0e 100644 --- a/custom_components/ics_calendar/__init__.py +++ b/custom_components/ics_calendar/__init__.py @@ -203,7 +203,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = full_data - await hass.config_entries.async_forward_entry_setups(entry, ["calendar"]) + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True diff --git a/custom_components/ics_calendar/calendar.py b/custom_components/ics_calendar/calendar.py index 5d33ad7..37569f9 100644 --- a/custom_components/ics_calendar/calendar.py +++ b/custom_components/ics_calendar/calendar.py @@ -286,18 +286,15 @@ class ICSCalendarData: # pylint: disable=R0902 minutes=device_data[CONF_DOWNLOAD_INTERVAL] ), }, - ) - - self._calendar_data.set_headers( + ).headers( device_data[CONF_USERNAME], device_data[CONF_PASSWORD], device_data[CONF_USER_AGENT], device_data[CONF_ACCEPT_HEADER], ) - if device_data.get(CONF_SET_TIMEOUT): - self._calendar_data.set_timeout( - device_data[CONF_CONNECTION_TIMEOUT] + self._calendar_data.timeout( + device_data.get(CONF_CONNECTION_TIMEOUT) ) async def async_get_events( @@ -313,7 +310,9 @@ class ICSCalendarData: # pylint: disable=R0902 event_list: list[ParserEvent] = [] if await self._calendar_data.download_calendar(): _LOGGER.debug("%s: Setting calendar content", self.name) - self.parser.set_content(self._calendar_data.get()) + await self._hass.async_add_executor_job( + lambda: self.parser.set_content(self._calendar_data.get()) + ) try: event_list = self.parser.get_event_list( start=start_date, @@ -345,7 +344,9 @@ class ICSCalendarData: # pylint: disable=R0902 parser_event: ParserEvent | None = None if await self._calendar_data.download_calendar(): _LOGGER.debug("%s: Setting calendar content", self.name) - self.parser.set_content(self._calendar_data.get()) + await self._hass.async_add_executor_job( + lambda: self.parser.set_content(self._calendar_data.get()) + ) try: parser_event: ParserEvent | None = self.parser.get_current_event( include_all_day=self.include_all_day, diff --git a/custom_components/ics_calendar/calendardata.py b/custom_components/ics_calendar/calendardata.py index 0364814..28d49e4 100644 --- a/custom_components/ics_calendar/calendardata.py +++ b/custom_components/ics_calendar/calendardata.py @@ -91,7 +91,7 @@ class CalendarData: # pylint: disable=R0902 """ return self._calendar_data - def set_headers( + def headers( self, user_name: str, password: str, @@ -124,14 +124,17 @@ class CalendarData: # pylint: disable=R0902 self._headers.append(("User-agent", user_agent)) if accept_header != "": self._headers.append(("Accept", accept_header)) + return self - def set_timeout(self, connection_timeout: float): + def timeout(self, connection_timeout: float | None): """Set the connection timeout. :param connection_timeout: The timeout value in seconds. :type connection_timeout: float """ - self.connection_timeout = connection_timeout + if connection_timeout: + self.connection_timeout = connection_timeout + return self def _decode_data(self, data): return data.replace("\0", "") @@ -202,7 +205,6 @@ class CalendarData: # pylint: disable=R0902 def _get_month_year(self, url: str, month: int, year: int) -> int: (month, url) = self._get_year_as_months(url, month) - print(f"month: {month}\n") month_match = re.search("\\{month([-+])([0-9]+)\\}", url) if month_match: if month_match.group(1) == "-": diff --git a/custom_components/ics_calendar/config_flow.py b/custom_components/ics_calendar/config_flow.py index af16ac3..59a16e6 100644 --- a/custom_components/ics_calendar/config_flow.py +++ b/custom_components/ics_calendar/config_flow.py @@ -286,14 +286,14 @@ class ICSCalendarConfigFlow(ConfigFlow, domain=DOMAIN): errors = {} if user_input is not None: - if not errors: - self.data.update(user_input) - if user_input.get(CONF_SET_TIMEOUT, False): - return await self.async_step_timeout_opts() - return self.async_create_entry( - title=self.data[CONF_NAME], - data=self.data, - ) + # if not errors: + self.data.update(user_input) + if user_input.get(CONF_SET_TIMEOUT, False): + return await self.async_step_timeout_opts() + return self.async_create_entry( + title=self.data[CONF_NAME], + data=self.data, + ) return self.async_show_form( step_id="adv_connect_opts", @@ -308,12 +308,12 @@ class ICSCalendarConfigFlow(ConfigFlow, domain=DOMAIN): errors = {} if user_input is not None: - if not errors: - self.data.update(user_input) - return self.async_create_entry( - title=self.data[CONF_NAME], - data=self.data, - ) + # if not errors: + self.data.update(user_input) + return self.async_create_entry( + title=self.data[CONF_NAME], + data=self.data, + ) return self.async_show_form( step_id="timeout_opts", diff --git a/custom_components/ics_calendar/const.py b/custom_components/ics_calendar/const.py index 74d1416..c8d3455 100644 --- a/custom_components/ics_calendar/const.py +++ b/custom_components/ics_calendar/const.py @@ -1,6 +1,6 @@ """Constants for ics_calendar platform.""" -VERSION = "5.1.3" +VERSION = "5.1.5" DOMAIN = "ics_calendar" CONF_DEVICE_ID = "device_id" diff --git a/custom_components/ics_calendar/manifest.json b/custom_components/ics_calendar/manifest.json index b2636cd..c3f9cce 100644 --- a/custom_components/ics_calendar/manifest.json +++ b/custom_components/ics_calendar/manifest.json @@ -9,5 +9,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/franc6/ics_calendar/issues", "requirements": ["icalendar~=6.1","python-dateutil>=2.9.0.post0","pytz>=2024.1","recurring_ical_events~=3.5,>=3.5.2","ics==0.7.2","arrow","httpx_auth>=0.22.0,<=0.23.1"], - "version": "5.1.3" + "version": "5.1.5" }