Skip to content

Commit ad6f3a0

Browse files
committed
Fix blocking call inside the event loop #38
1 parent f196864 commit ad6f3a0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

custom_components/python_script/sensor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ async def async_setup_platform(
2424
try:
2525
if "file" in config:
2626
finename = hass.config.path(config["file"])
27-
with open(finename, "rt", encoding="utf-8") as f:
28-
source = f.read()
27+
28+
def sync_file_read() -> str:
29+
with open(finename, "rt", encoding="utf-8") as f:
30+
return f.read()
31+
32+
source = await hass.async_add_executor_job(sync_file_read)
2933
elif "source" in config:
3034
source = config["source"]
3135
else:

0 commit comments

Comments
 (0)