Skip to content

Commit

Permalink
fix file load blocking call
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-maddin committed Jun 18, 2024
1 parent 4da3277 commit d7ad72a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions custom_components/wattpilot/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Final
import logging
import asyncio
import aiofiles
import yaml
import os

Expand Down Expand Up @@ -42,8 +43,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
entites=[]
try:
_LOGGER.debug("%s - async_setup_entry %s: Reading static yaml configuration", entry.entry_id, platform)
with open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as stream:
yaml_cfg=yaml.safe_load(stream)
async with aiofiles.open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as y:
yaml_cfg=yaml.safe_load(await y.read())
except Exception as e:
_LOGGER.error("%s - async_setup_entry %s: Reading static yaml configuration failed: %s (%s.%s)", entry.entry_id, platform, str(e), e.__class__.__module__, type(e).__name__)
return False
Expand Down
4 changes: 2 additions & 2 deletions custom_components/wattpilot/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"domain": "wattpilot",
"name": "Fronius Wattpilot",
"version": "0.2.1",
"version": "0.2.2",
"config_flow": true,
"documentation": "https://github.com/mk-maddin/wattpilot-HA",
"requirements": ["wattpilot>=0.1","pyyaml>=5.3.0", "importlib_metadata>=4.0.0"],
"requirements": ["wattpilot>=0.1", "pyyaml>=5.3.0", "importlib_metadata>=4.0.0", "aiofiles>=23.2.1"],
"dependencies": ["sensor","switch","select","number","button","diagnostics"],
"codeowners": ["@mk-maddin"],
"iot_class": "local_polling"
Expand Down
5 changes: 3 additions & 2 deletions custom_components/wattpilot/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Final
import logging
import asyncio
import aiofiles
import yaml
import os

Expand Down Expand Up @@ -42,8 +43,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
entites=[]
try:
_LOGGER.debug("%s - async_setup_entry %s: Reading static yaml configuration", entry.entry_id, platform)
with open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as stream:
yaml_cfg=yaml.safe_load(stream)
async with aiofiles.open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as y:
yaml_cfg=yaml.safe_load(await y.read())
except Exception as e:
_LOGGER.error("%s - async_setup_entry %s: Reading static yaml configuration failed: %s (%s.%s)", entry.entry_id, platform, str(e), e.__class__.__module__, type(e).__name__)
return False
Expand Down
5 changes: 3 additions & 2 deletions custom_components/wattpilot/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Final
import logging
import asyncio
import aiofiles
import yaml
import os

Expand Down Expand Up @@ -42,8 +43,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
entites=[]
try:
_LOGGER.debug("%s - async_setup_entry %s: Reading static yaml configuration", entry.entry_id, platform)
with open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as stream:
yaml_cfg=yaml.safe_load(stream)
async with aiofiles.open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as y:
yaml_cfg=yaml.safe_load(await y.read())
except Exception as e:
_LOGGER.error("%s - async_setup_entry %s: Reading static yaml configuration failed: %s (%s.%s)", entry.entry_id, platform, str(e), e.__class__.__module__, type(e).__name__)
return False
Expand Down
5 changes: 3 additions & 2 deletions custom_components/wattpilot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Final
import logging
import asyncio
import aiofiles
import yaml
import os

Expand Down Expand Up @@ -41,8 +42,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
entites=[]
try:
_LOGGER.debug("%s - async_setup_entry %s: Reading static yaml configuration", entry.entry_id, platform)
with open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as stream:
yaml_cfg=yaml.safe_load(stream)
async with aiofiles.open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as y:
yaml_cfg=yaml.safe_load(await y.read())
except Exception as e:
_LOGGER.error("%s - async_setup_entry %s: Reading static yaml configuration failed: %s (%s.%s)", entry.entry_id, platform, str(e), e.__class__.__module__, type(e).__name__)
return False
Expand Down
5 changes: 3 additions & 2 deletions custom_components/wattpilot/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Final
import logging
import asyncio
import aiofiles
import yaml
import os

Expand Down Expand Up @@ -43,8 +44,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
entites=[]
try:
_LOGGER.debug("%s - async_setup_entry %s: Reading static yaml configuration", entry.entry_id, platform)
with open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as stream:
yaml_cfg=yaml.safe_load(stream)
async with aiofiles.open(os.path.dirname(os.path.realpath(__file__))+'/'+platform+'.yaml', 'r') as y:
yaml_cfg=yaml.safe_load(await y.read())
except Exception as e:
_LOGGER.error("%s - async_setup_entry %s: Reading static yaml configuration failed: %s (%s.%s)", entry.entry_id, platform, str(e), e.__class__.__module__, type(e).__name__)
return False
Expand Down

0 comments on commit d7ad72a

Please sign in to comment.