diff --git a/custom_components/smartir/__init__.py b/custom_components/smartir/__init__.py index e6499753..c279c519 100644 --- a/custom_components/smartir/__init__.py +++ b/custom_components/smartir/__init__.py @@ -19,7 +19,7 @@ _LOGGER = logging.getLogger(__name__) DOMAIN = 'smartir' -VERSION = '1.17.10' +VERSION = '1.17.11' MANIFEST_URL = ( "https://raw.githubusercontent.com/" "smartHomeHub/SmartIR/{}/" diff --git a/custom_components/smartir/climate.py b/custom_components/smartir/climate.py index 87b9e2dc..6a08f460 100644 --- a/custom_components/smartir/climate.py +++ b/custom_components/smartir/climate.py @@ -1,4 +1,5 @@ import asyncio +import aiofiles import json import logging import os.path @@ -81,14 +82,15 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= "place the file manually in the proper directory.") return - with open(device_json_path) as j: - try: + try: + async with aiofiles.open(device_json_path, mode='r') as j: _LOGGER.debug(f"loading json file {device_json_path}") - device_data = json.load(j) + content = await j.read() + device_data = json.loads(content) _LOGGER.debug(f"{device_json_path} file loaded") - except Exception: - _LOGGER.error("The device Json file is invalid") - return + except Exception: + _LOGGER.error("The device JSON file is invalid") + return async_add_entities([SmartIRClimate( hass, config, device_data diff --git a/custom_components/smartir/fan.py b/custom_components/smartir/fan.py index df386ace..7a8cb942 100644 --- a/custom_components/smartir/fan.py +++ b/custom_components/smartir/fan.py @@ -1,4 +1,5 @@ import asyncio +import aiofiles import json import logging import os.path @@ -74,12 +75,15 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= "place the file manually in the proper directory.") return - with open(device_json_path) as j: - try: - device_data = json.load(j) - except Exception: - _LOGGER.error("The device JSON file is invalid") - return + try: + async with aiofiles.open(device_json_path, mode='r') as j: + _LOGGER.debug(f"loading json file {device_json_path}") + content = await j.read() + device_data = json.loads(content) + _LOGGER.debug(f"{device_json_path} file loaded") + except Exception: + _LOGGER.error("The device JSON file is invalid") + return async_add_entities([SmartIRFan( hass, config, device_data diff --git a/custom_components/smartir/manifest.json b/custom_components/smartir/manifest.json index 5e6e17e9..d1356156 100644 --- a/custom_components/smartir/manifest.json +++ b/custom_components/smartir/manifest.json @@ -6,10 +6,10 @@ "codeowners": ["@smartHomeHub"], "requirements": ["aiofiles>=0.6.0"], "homeassistant": "2024.10.0", - "version": "1.17.10", + "version": "1.17.11", "updater": { - "version": "1.17.10", - "releaseNotes": "-- ClimateEntityFeature enum compatibility", + "version": "1.17.11", + "releaseNotes": "-- Implements asynchronous device file loading", "files": [ "__init__.py", "climate.py", diff --git a/custom_components/smartir/media_player.py b/custom_components/smartir/media_player.py index 278a8402..48a71b00 100644 --- a/custom_components/smartir/media_player.py +++ b/custom_components/smartir/media_player.py @@ -1,4 +1,5 @@ import asyncio +import aiofiles import json import logging import os.path @@ -72,12 +73,15 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= "place the file manually in the proper directory.") return - with open(device_json_path) as j: - try: - device_data = json.load(j) - except Exception: - _LOGGER.error("The device JSON file is invalid") - return + try: + async with aiofiles.open(device_json_path, mode='r') as j: + _LOGGER.debug(f"loading json file {device_json_path}") + content = await j.read() + device_data = json.loads(content) + _LOGGER.debug(f"{device_json_path} file loaded") + except Exception: + _LOGGER.error("The device JSON file is invalid") + return async_add_entities([SmartIRMediaPlayer( hass, config, device_data