Skip to content
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: 8 additions & 4 deletions homeassistant/components/solaredge/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""The solaredge component."""
"""The solaredge integration."""
from __future__ import annotations

from typing import Any

import voluptuous as vol

from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_NAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import HomeAssistantType

from .const import CONF_SITE_ID, DEFAULT_NAME, DOMAIN

Expand All @@ -25,7 +29,7 @@
)


async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool:
"""Platform setup, do nothing."""
if DOMAIN not in config:
return True
Expand All @@ -38,7 +42,7 @@ async def async_setup(hass, config):
return True


async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Load the saved entities."""
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
Expand Down
26 changes: 14 additions & 12 deletions homeassistant/components/solaredge/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Config flow for the SolarEdge platform."""
from __future__ import annotations

from typing import Any

from requests.exceptions import ConnectTimeout, HTTPError
import solaredge
import voluptuous as vol
Expand Down Expand Up @@ -30,13 +34,11 @@ def __init__(self) -> None:
"""Initialize the config flow."""
self._errors = {}

def _site_in_configuration_exists(self, site_id) -> bool:
def _site_in_configuration_exists(self, site_id: str) -> bool:
"""Return True if site_id exists in configuration."""
if site_id in solaredge_entries(self.hass):
return True
return False
return site_id in solaredge_entries(self.hass)

def _check_site(self, site_id, api_key) -> bool:
def _check_site(self, site_id: str, api_key: str) -> bool:
"""Check if we can connect to the soleredge api service."""
api = solaredge.Solaredge(api_key)
try:
Expand All @@ -52,7 +54,9 @@ def _check_site(self, site_id, api_key) -> bool:
return False
return True

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> dict[str, Any]:
"""Step when user initializes a integration."""
self._errors = {}
if user_input is not None:
Expand All @@ -71,11 +75,7 @@ async def async_step_user(self, user_input=None):
)

else:
user_input = {}
user_input[CONF_NAME] = DEFAULT_NAME
user_input[CONF_SITE_ID] = ""
user_input[CONF_API_KEY] = ""

user_input = {CONF_NAME: DEFAULT_NAME, CONF_SITE_ID: "", CONF_API_KEY: ""}
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
Expand All @@ -90,7 +90,9 @@ async def async_step_user(self, user_input=None):
errors=self._errors,
)

async def async_step_import(self, user_input=None):
async def async_step_import(
self, user_input: dict[str, Any] | None = None
) -> dict[str, Any]:
"""Import a config entry."""
if self._site_in_configuration_exists(user_input[CONF_SITE_ID]):
return self.async_abort(reason="already_configured")
Expand Down
Loading