Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using aiofiles.open() to avoid warning, and replace deprecated aliases #380

Merged
merged 5 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions custom_components/solis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType, HomeAssistantType, ServiceCallType
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import dt as dt_util

from .const import (
Expand All @@ -34,7 +34,7 @@
PLATFORMS = [Platform.SENSOR]


async def async_setup(hass: HomeAssistantType, config: ConfigType):
async def async_setup(hass: HomeAssistant, config: ConfigType):
"""Set up the Solis component from configuration.yaml."""

if "sensor" not in config:
Expand Down Expand Up @@ -87,13 +87,7 @@ async def async_setup_entry(
hass.data[DOMAIN][entry.entry_id] = service

# Forward the setup to the sensor platform.
#hass.async_create_task(
# hass.config_entries.async_forward_entry_setup(entry, component)
# for component in PLATFORMS
#)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
Expand Down
7 changes: 5 additions & 2 deletions custom_components/solis/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
"version": "3.5.2",
"config_flow": true,
"name": "Solis Inverter",
"iot_class": "cloud_push",
"iot_class": "cloud_polling",
"documentation": "https://github.com/hultenvp/solis-sensor/",
"issue_tracker": "https://github.com/hultenvp/solis-sensor/issues",
"dependencies": [],
"codeowners": ["@hultenvp"]
"codeowners": ["@hultenvp"],
"requirements": [
"aiofiles>=23.1.0,<24.0.0"
]
}
11 changes: 9 additions & 2 deletions custom_components/solis/soliscloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from aiohttp import ClientError, ClientSession
import async_timeout
import yaml
import aiofiles

from .ginlong_base import BaseAPI, GinlongData, PortalConfig
from .ginlong_const import *
Expand Down Expand Up @@ -181,9 +182,12 @@ def __init__(self,
self._key_id: str = portal_key_id
self._secret: bytes = portal_secret
self._workarounds = {}

async def load_workarounds(self):
try:
with open('/config/custom_components/solis/workarounds.yaml', 'r') as file:
self._workarounds = yaml.safe_load(file)
async with aiofiles.open('/config/custom_components/solis/workarounds.yaml', 'r') as file:
content = await file.read()
self._workarounds = yaml.safe_load(content)
_LOGGER.debug("workarounds: %s", self._workarounds)
except FileNotFoundError:
pass
Expand Down Expand Up @@ -233,6 +237,9 @@ async def login(self, session: ClientSession) -> bool:
self._session = session
self._inverter_list = None

# Load workarounds
await self._config.load_workarounds()

# Request inverter list
self._inverter_list = await self.fetch_inverter_list(self.config.plant_id)
if len(self._inverter_list)==0:
Expand Down
Loading