Skip to content

Commit ac1e4b0

Browse files
authored
Merge pull request #227 from benschumacher/blocking_call_issue
Fix for blocking call issue
2 parents 00eb492 + 58169f5 commit ac1e4b0

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

custom_components/zha_toolkit/default.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
from __future__ import annotations
2+
13
import importlib
24
import logging
35
import sys
6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from types import ModuleType
410

511
LOGGER = logging.getLogger(__name__)
612

@@ -27,13 +33,18 @@ async def default(app, listener, ieee, cmd, data, service, params, event_data):
2733
module_name = cmd[0]
2834
cmd = cmd[1]
2935

30-
LOGGER.debug(
31-
f"Trying to import {package_name}.{module_name} to call {cmd}"
32-
)
33-
m = importlib.import_module(f".{module_name}", package=package_name)
36+
def _reload_command_module() -> ModuleType:
37+
LOGGER.debug(
38+
f"Trying to import {package_name}.{module_name} to call {cmd}"
39+
)
40+
m = importlib.import_module(f".{module_name}", package=package_name)
3441

35-
importlib.reload(m)
42+
importlib.reload(m)
43+
return m
3644

45+
m = await listener.hass.async_add_import_executor_job(
46+
_reload_command_module
47+
)
3748
# Get handler (cmd) in loaded module.
3849
handler = getattr(m, cmd)
3950
# Call the handler

0 commit comments

Comments
 (0)