|
|
@@ -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
|