Skip to content

Commit

Permalink
Merge pull request #186 from gjohansson-ST/gj-20241104-6
Browse files Browse the repository at this point in the history
Mod config flow
  • Loading branch information
gjohansson-ST authored Nov 4, 2024
2 parents b0e0447 + d6b20f9 commit e386b16
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions custom_components/sector/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.helpers.selector import (
TextSelector,
TextSelectorConfig,
TextSelectorType,
)

from .const import CONF_PANEL_CODE, CONF_PANEL_ID, DOMAIN

Expand Down Expand Up @@ -35,32 +40,43 @@ async def async_step_user(self, user_input=None):
try:
await api.login()
await api.retrieve_all_data()
except AuthenticationError:
errors["base"] = "authentication_failed"
except Exception as e:
errors["base"] = "unknown_error"
_LOGGER.exception("Unexpected exception during authentication: %s", e)
else:
return self.async_create_entry(
title="Sector Alarm",
title=f"Sector Alarm {panel_id}",
data={
CONF_EMAIL: email,
CONF_PASSWORD: password,
CONF_PANEL_ID: panel_id,
CONF_PANEL_CODE: panel_code,
},
)
except AuthenticationError:
errors["base"] = "authentication_failed"
except Exception as e:
errors["base"] = "unknown_error"
_LOGGER.exception("Unexpected exception during authentication: %s", e)

data_schema = vol.Schema(
{
vol.Required(CONF_EMAIL): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_PANEL_ID): str,
vol.Required(CONF_PANEL_CODE): str,
vol.Required(CONF_EMAIL): TextSelector(
TextSelectorConfig(
type=TextSelectorType.EMAIL, autocomplete="email"
)
),
vol.Required(CONF_PASSWORD): TextSelector(
TextSelectorConfig(
type=TextSelectorType.PASSWORD, autocomplete="current-password"
)
),
vol.Required(CONF_PANEL_ID): TextSelector(),
vol.Required(CONF_PANEL_CODE): TextSelector(),
}
)

return self.async_show_form(
step_id="user",
data_schema=data_schema,
data_schema=self.add_suggested_values_to_schema(
data_schema, user_input or {}
),
errors=errors,
)

0 comments on commit e386b16

Please sign in to comment.