From e52b662be63a967a9e5f65b199ee3d8dcfe3a856 Mon Sep 17 00:00:00 2001 From: Philipp Grimm Date: Fri, 17 May 2024 14:50:57 +0200 Subject: [PATCH] lazy loading for esp3 libs --- changes.md | 1 + custom_components/eltako/gateway.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/changes.md b/changes.md index 0c17f443..12859aa8 100644 --- a/changes.md +++ b/changes.md @@ -2,6 +2,7 @@ ## Version 1.4.4 * Thread sync clean up +* Lazy loading for ESP3 libs to prevent dependency issues ## Version 1.4.3 Compatibility to HA 2024.5 * 🐞 Incompatibility with HA 2024.5 fixed. (Cleaned up event loop synchronization) diff --git a/custom_components/eltako/gateway.py b/custom_components/eltako/gateway.py index db3f267a..e9d5a936 100644 --- a/custom_components/eltako/gateway.py +++ b/custom_components/eltako/gateway.py @@ -23,7 +23,6 @@ from .const import * from . import config_helpers -from esp2_gateway_adapter.esp3_serial_com import ESP3SerialCommunicator async def async_get_base_ids_of_registered_gateway(device_registry: DeviceRegistry) -> list[str]: @@ -129,6 +128,8 @@ def _init_bus(self): if GatewayDeviceType.is_esp2_gateway(self.dev_type): self._bus = RS485SerialInterfaceV2(self.serial_path, baud_rate=self.baud_rate, callback=self._callback_receive_message_from_serial_bus) else: + # lazy import to avoid preloading library + from esp2_gateway_adapter.esp3_serial_com import ESP3SerialCommunicator self._bus = ESP3SerialCommunicator(filename=self.serial_path, callback=self._callback_receive_message_from_serial_bus, esp2_translation_enabled=True) self._bus.set_status_changed_handler(self._fire_connection_state_changed_event)