Skip to content
Open
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
5 changes: 3 additions & 2 deletions custom_components/saj_esolar_air/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ def get_data(
if "error" in plant_info:
raise UnknownError(plant_info["error"])

if plant_info.get("status") != "success":
if len(plant_info) == 0:
_LOGGER.exception("Unexpected response: %s", plant_info)
raise UnknownError
return cast(ESolarResponse, plant_info)

return plant_info
30 changes: 12 additions & 18 deletions custom_components/saj_esolar_air/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

import requests
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.const import CONF_REGION, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv

Expand All @@ -20,7 +18,7 @@
CONF_PV_GRID_DATA,
DOMAIN,
)
from .esolar import esolar_web_autenticate, web_get_plant
from .esolar import esolar_web_authenticate, web_get_plant_list

CONF_TITLE = "SAJ eSolar"

Expand All @@ -43,10 +41,10 @@ def __init__(self) -> None:
self.plant_list: dict[str, Any] = {}

def auth_and_get_solar_plants(self, region: str, username: str, password: str) -> bool:
"""Download and list availablse inverters."""
"""Download and list available inverters."""
try:
session = esolar_web_autenticate(region, username, password)
self.plant_list = web_get_plant(region, session).get("plantList")
session = esolar_web_authenticate(region, username, password)
self.plant_list = web_get_plant_list(region, session)
except requests.exceptions.HTTPError:
_LOGGER.error("Login: HTTPError")
return False
Expand Down Expand Up @@ -82,13 +80,13 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1

def __init__(self):
"""Set up the the config flow."""
"""Set up the config flow."""
self.sites = {}
self.data = {}

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
):
"""Handle the initial step. Username and password."""
if user_input is None:
return self.async_show_form(
Expand All @@ -107,7 +105,7 @@ async def async_step_user(
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
self.sites = [site["plantname"] for site in info["plant_list"]]
self.sites = [site["plantName"] for site in info["plant_list"]]
if len(self.sites) == 1:
return self.async_create_entry(
title=CONF_TITLE,
Expand All @@ -129,7 +127,7 @@ async def async_step_user(

async def async_step_sites(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
):
"""Handle the second step. Select which sites to use."""

errors = {}
Expand Down Expand Up @@ -159,21 +157,17 @@ async def async_step_sites(
@callback
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
) -> config_entries.OptionsFlow:
) -> OptionsFlowHandler:
"""Create the options flow."""
return OptionsFlowHandler(config_entry)
return OptionsFlowHandler()


class OptionsFlowHandler(config_entries.OptionsFlow):
"""Handle a options flow for eSolar."""

def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize options flow."""
self.config_entry = config_entry

async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
):
"""Manage the options."""
if user_input is not None:
user_input.update(
Expand All @@ -196,7 +190,7 @@ async def async_step_init(
vol.Required(
CONF_PV_GRID_DATA,
default=self.config_entry.options.get(CONF_PV_GRID_DATA),
): bool,
): bool
}
),
)
Expand Down
Loading