From 1279922fa84634187660a676e376ee8e5202f0bc Mon Sep 17 00:00:00 2001 From: RogerSelwyn Date: Wed, 29 May 2024 09:25:19 +0100 Subject: [PATCH] maint: Move writing of calendar file outside the thread --- custom_components/o365/utils/filemgmt.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/custom_components/o365/utils/filemgmt.py b/custom_components/o365/utils/filemgmt.py index 0b28431..22690be 100644 --- a/custom_components/o365/utils/filemgmt.py +++ b/custom_components/o365/utils/filemgmt.py @@ -47,6 +47,13 @@ def load_yaml_file(path, item_id, item_schema): return items +def _write_yaml_file(yaml_filepath, cal): + with open(yaml_filepath, "a", encoding="UTF8") as out: + out.write("\n") + yaml.dump([cal], out, default_flow_style=False, encoding="UTF8") + out.close() + + def _get_calendar_info(calendar, track_new_devices): """Convert data from O365 into DEVICE_SCHEMA.""" return YAML_CALENDAR_DEVICE_SCHEMA( @@ -73,10 +80,7 @@ async def async_update_calendar_file(config, calendar, hass, track_new_devices): cal = _get_calendar_info(calendar, track_new_devices) if cal[CONF_CAL_ID] in existing_calendars: return - with open(yaml_filepath, "a", encoding="UTF8") as out: - out.write("\n") - yaml.dump([cal], out, default_flow_style=False, encoding="UTF8") - out.close() + await hass.async_add_executor_job(_write_yaml_file, yaml_filepath, cal) def _get_task_list_info(yaml_task_list, track_new_devices):