Skip to content

Commit

Permalink
maint: Move writing of calendar file outside the thread
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed May 29, 2024
1 parent b6adf69 commit 1279922
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions custom_components/o365/utils/filemgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down

0 comments on commit 1279922

Please sign in to comment.