From 9b80db5cb6a0bc19975cb726f103754927a98bc6 Mon Sep 17 00:00:00 2001 From: Sdahl1234 Date: Thu, 6 Jun 2024 14:58:54 +0200 Subject: [PATCH] Fixed Detected blocking call to open inside the event loop --- custom_components/adano/__init__.py | 17 +++++++++++++---- custom_components/adano/device_tracker.py | 4 ++-- custom_components/adano/manifest.json | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/custom_components/adano/__init__.py b/custom_components/adano/__init__.py index 217ee8e..a9fd8bc 100644 --- a/custom_components/adano/__init__.py +++ b/custom_components/adano/__init__.py @@ -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 @@ -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) @@ -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 diff --git a/custom_components/adano/device_tracker.py b/custom_components/adano/device_tracker.py index d88b7d2..68b6ec2 100644 --- a/custom_components/adano/device_tracker.py +++ b/custom_components/adano/device_tracker.py @@ -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"]: diff --git a/custom_components/adano/manifest.json b/custom_components/adano/manifest.json index 27f4356..c63e1f4 100644 --- a/custom_components/adano/manifest.json +++ b/custom_components/adano/manifest.json @@ -8,5 +8,5 @@ "integration_type": "device", "iot_class": "cloud_push", "config_flow": true, - "version": "1.0.13" + "version": "1.0.14" } \ No newline at end of file