Skip to content

Commit

Permalink
Persist user and host
Browse files Browse the repository at this point in the history
  • Loading branch information
iMicknl committed Aug 9, 2024
1 parent 2cc5c29 commit 27fa6d4
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions custom_components/sagemcom_fast/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,28 @@
from .const import CONF_ENCRYPTION_METHOD, DOMAIN, LOGGER
from .options_flow import OptionsFlow

DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_HOST): str,
vol.Optional(CONF_USERNAME): str,
vol.Optional(CONF_PASSWORD): str,
vol.Required(CONF_SSL, default=False): bool,
vol.Required(CONF_VERIFY_SSL, default=False): bool,
}
)


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Sagemcom."""

VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL

_host: str | None = None
_username: str | None = None

async def async_validate_input(self, user_input):
"""Validate user credentials."""
username = user_input.get(CONF_USERNAME) or ""
self._username = user_input.get(CONF_USERNAME) or ""
password = user_input.get(CONF_PASSWORD) or ""
host = user_input[CONF_HOST]
self._host = user_input[CONF_HOST]
ssl = user_input[CONF_SSL]

session = async_get_clientsession(self.hass, user_input[CONF_VERIFY_SSL])

client = SagemcomClient(
host=host,
username=username,
host=self._host,
username=self._username,
password=password,
session=session,
ssl=ssl,
Expand All @@ -68,7 +61,7 @@ async def async_validate_input(self, user_input):
await client.logout()

return self.async_create_entry(
title=host,
title=self._host,
data=user_input,
)

Expand Down Expand Up @@ -102,7 +95,17 @@ async def async_step_user(self, user_input=None):
LOGGER.exception(exception)

return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
step_id="user",
data_schema=vol.Schema(
{
vol.Required(CONF_HOST, default=self._host): str,
vol.Optional(CONF_USERNAME, default=self._username): str,
vol.Optional(CONF_PASSWORD): str,
vol.Required(CONF_SSL, default=False): bool,
vol.Required(CONF_VERIFY_SSL, default=False): bool,
}
),
errors=errors,
)

@staticmethod
Expand Down

0 comments on commit 27fa6d4

Please sign in to comment.