mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
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:
parent
f4787d469a
commit
9a0837593a
@ -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
|
||||
)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user