From 21db2d1102b37f8f6326ced484755e0641a133fe Mon Sep 17 00:00:00 2001 From: Julian De Vita Date: Wed, 22 Apr 2026 21:22:03 -0400 Subject: [PATCH] fix: run carrier detection load() in executor to avoid blocking event loop Offload the blocking filesystem I/O (scandir, read_text, open) in CarrierDetector.load() to the executor via hass.async_add_executor_job, preventing HA from logging blocking call warnings. Also removes the lazy-load fallback in detect() to ensure load() is never called synchronously from the event loop. Fixes #84 --- custom_components/parcelapp/carrier_detection.py | 3 --- custom_components/parcelapp/services.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/custom_components/parcelapp/carrier_detection.py b/custom_components/parcelapp/carrier_detection.py index a5e88d2..1838e96 100644 --- a/custom_components/parcelapp/carrier_detection.py +++ b/custom_components/parcelapp/carrier_detection.py @@ -342,9 +342,6 @@ def detect(self, tracking_number: str) -> list[CarrierMatch]: Returns matches sorted by confidence (highest first). """ - if not self._loaded: - self.load() - results: list[CarrierMatch] = [] for pattern in self._patterns: diff --git a/custom_components/parcelapp/services.py b/custom_components/parcelapp/services.py index d4e7913..49b4d5e 100644 --- a/custom_components/parcelapp/services.py +++ b/custom_components/parcelapp/services.py @@ -243,7 +243,7 @@ async def async_register_services(hass: HomeAssistant): session = async_get_clientsession(hass) detector = CarrierDetector() - detector.load() + await hass.async_add_executor_job(detector.load) async def async_add_parcel(call: ServiceCall): """Add a parcel to ParcelApp using the official API."""