Improve test coverage and add comment for loading in executor for remote calendar (#140807)

Improve calendar loading by executing in a separate thread and add test for CalendarParseError
This commit is contained in:
Thomas55555 2025-03-17 17:38:40 +01:00 committed by GitHub
parent f4787d469a
commit 9a0837593a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -56,6 +56,9 @@ class RemoteCalendarDataUpdateCoordinator(DataUpdateCoordinator[Calendar]):
translation_placeholders={"err": str(err)},
) from err
try:
# calendar_from_ics will dynamically load packages
# the first time it is called, so we need to do it
# in a separate thread to avoid blocking the event loop
return await self.hass.async_add_executor_job(
IcsCalendarStream.calendar_from_ics, res.text
)

View File

@ -71,3 +71,16 @@ async def test_update_failed(
respx.get(CALENDER_URL).mock(side_effect=side_effect)
await setup_integration(hass, config_entry)
assert config_entry.state is ConfigEntryState.SETUP_RETRY
@respx.mock
async def test_calendar_parse_error(
hass: HomeAssistant,
config_entry: MockConfigEntry,
) -> None:
"""Test CalendarParseError using respx."""
respx.get(CALENDER_URL).mock(
return_value=Response(status_code=200, text="not a calendar")
)
await setup_integration(hass, config_entry)
assert config_entry.state is ConfigEntryState.SETUP_RETRY