Skip to content

Commit

Permalink
Fixed Detected blocking call to open inside the event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sdahl1234 committed Jun 6, 2024
1 parent e8abf07 commit 9b80db5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions custom_components/adano/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ async def GetSchedule(self, daynumber: int) -> str:
async def file_exits(self):
"""Do file exists."""
try:
f = open(self.filepath, encoding="utf-8")
f = await self.hass.async_add_executor_job(
open, self.filepath, "r", -1, "utf-8"
)
f.close()
f.close()
except FileNotFoundError:
# save a new file
Expand All @@ -164,9 +167,13 @@ async def save_data(self, append: bool):
"""Save data."""
try:
if append:
cfile = open(self.filepath, "w", encoding="utf-8")
cfile = await self.hass.async_add_executor_job(
open, self.filepath, "w", -1, "utf-8"
)
else:
cfile = open(self.filepath, "a", encoding="utf-8")
cfile = await self.hass.async_add_executor_job(
open, self.filepath, "a", -1, "utf-8"
)
ocrdata = json.dumps(self.jdata)
self.data_handler.get_device(self.devicesn).Schedule.SavedData = self.jdata
cfile.write(ocrdata)
Expand All @@ -177,7 +184,9 @@ async def save_data(self, append: bool):
async def load_data(self):
"""Load data."""
try:
cfile = open(self.filepath, encoding="utf-8")
cfile = await self.hass.async_add_executor_job(
open, self.filepath, "r", -1, "utf-8"
)
ocrdata = cfile.read()
cfile.close()
_LOGGER.debug(f"ocrdata: {ocrdata}") # noqa: G004
Expand Down
4 changes: 2 additions & 2 deletions custom_components/adano/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def __init__(
def latitude(self) -> float | None:
"""Return latitude value of the device."""
val = self._data_handler.get_device(self._sn).devicedata["data"].get("lat")
return val
return val # noqa: RET504

@property
def longitude(self) -> float | None:
"""Return longitude value of the device."""
val = self._data_handler.get_device(self._sn).devicedata["data"].get("lng")
return val
return val # noqa: RET504

@property
def source_type(self) -> Literal["gps"]:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/adano/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"integration_type": "device",
"iot_class": "cloud_push",
"config_flow": true,
"version": "1.0.13"
"version": "1.0.14"
}

0 comments on commit 9b80db5

Please sign in to comment.