openHASP-custom-component
openHASP-custom-component copied to clipboard
Fix blocking open() calls by offloading file I/O to async_add_executo…
…r_job
In __init__.py, direct open() calls were being made on the Home Assistant event loop, leading to “Detected blocking call to open()” warnings and potential performance issues.
To address this:
- Moved the reading of
pages_schema.jsonout of the constructor and intoasync_added_to_hass, wrapping the file read withhass.async_add_executor_job(). - Introduced small synchronous helper functions (
_sync_read_json,_sync_read_text, etc.) for file I/O. These are called insideasync_add_executor_job(), preventing the main loop from blocking. - Updated
async_load_pageto use the same pattern for JSON or text lines, validating JSON data against the pre-loaded schema. - Ensures compliance with Home Assistant’s async guidelines and avoids blocking the event loop with disk I/O.
- Improves overall responsiveness and prevents related warnings in the HA logs.
FYI - This change for me allows HA to restart much faster than before.
This had already been addressed through an executer task (I have no warnings)
Also too many unrelated changes