Updated ics_calendar

This commit is contained in:
2025-12-08 12:06:06 +01:00
parent db9b8a73d3
commit 67b2c2edde
6 changed files with 32 additions and 29 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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) == "-":

View File

@@ -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",

View File

@@ -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"

View File

@@ -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"
}