Skip to content

Commit b7ad97a

Browse files
authored
Merge pull request #16 from junkfix/junkfix-patch-1
fix blocking error
2 parents 810c4e6 + 4964855 commit b7ad97a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

custom_components/config_editor/__init__.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ def drec(r, s):
6666
content = ''
6767
res = 'Loaded'
6868
try:
69-
with open(fullpath, encoding="utf-8") as fdesc:
70-
content = fdesc.read()
69+
def read():
70+
with open(fullpath, encoding="utf-8") as fdesc:
71+
return fdesc.read()
72+
content = await hass.async_add_executor_job(read)
7173
except:
7274
res = 'Reading Failed'
7375
_LOGGER.exception("Reading failed: %s", fullpath)
@@ -96,12 +98,16 @@ def drec(r, s):
9698
gid = 0
9799
with AtomicWriter(fullpath, overwrite=True).open() as fdesc:
98100
fdesc.write(content)
99-
with open(fullpath, 'a') as fdesc:
100-
try:
101-
os.fchmod(fdesc.fileno(), mode)
102-
os.fchown(fdesc.fileno(), uid, gid)
103-
except:
104-
pass
101+
102+
def permi():
103+
with open(fullpath, 'a') as fdesc:
104+
try:
105+
os.fchmod(fdesc.fileno(), mode)
106+
os.fchown(fdesc.fileno(), uid, gid)
107+
except:
108+
pass
109+
await hass.async_add_executor_job(permi)
110+
105111
except:
106112
res = "Saving Failed"
107113
_LOGGER.exception(res+": %s", fullpath)

0 commit comments

Comments
 (0)