Skip to content

Commit

Permalink
Simplify config_flow and only check auth
Browse files Browse the repository at this point in the history
  • Loading branch information
amosyuen committed Feb 14, 2022
1 parent 0c3ce6c commit 6da9806
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
28 changes: 8 additions & 20 deletions custom_components/tplink_deco/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def _async_test_credentials(hass: HomeAssistant, data: dict[str:Any]):
"""Return true if credentials is valid."""
try:
api = create_api(hass, data)
await api.async_list_clients()
await api.async_login()
return {}
except asyncio.TimeoutError:
return {"base": "timeout_connect"}
Expand Down Expand Up @@ -80,23 +80,17 @@ async def async_step_user(self, user_input=None):
title=user_input[CONF_HOST], data=user_input
)

return await self._show_config_form(user_input)

@staticmethod
@callback
def async_get_options_flow(config_entry: ConfigEntry):
return TplinkDecoOptionsFlowHandler(config_entry)

async def _show_config_form(
self, user_input: dict[str:Any]
): # pylint: disable=unused-argument
"""Show the configuration form to edit location data."""
return self.async_show_form(
step_id="user",
data_schema=_get_schema(user_input),
errors=self._errors,
)

@staticmethod
@callback
def async_get_options_flow(config_entry: ConfigEntry):
return TplinkDecoOptionsFlowHandler(config_entry)


class TplinkDecoOptionsFlowHandler(config_entries.OptionsFlow):
"""Config flow options handler for tplink_deco."""
Expand All @@ -107,13 +101,7 @@ def __init__(self, config_entry: ConfigEntry):
self.data = dict(config_entry.data)
self._errors = {}

async def async_step_init(
self, user_input: dict[str:Any] = None
): # pylint: disable=unused-argument
"""Manage the options."""
return await self.async_step_user()

async def async_step_user(self, user_input: dict[str:Any] = None):
async def async_step_init(self, user_input: dict[str:Any] = None):
"""Handle a flow initialized by the user."""
self._errors = {}

Expand All @@ -127,7 +115,7 @@ async def async_step_user(self, user_input: dict[str:Any] = None):
)

return self.async_show_form(
step_id="user",
step_id="init",
data_schema=_get_schema(self.data),
errors=self._errors,
)
2 changes: 1 addition & 1 deletion custom_components/tplink_deco/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"options": {
"step": {
"user": {
"init": {
"title": "TP-Link Deco",
"description": "Use the credentials for the admin web portal. See https://github.com/amosyuen/ha-tplink-deco",
"data": {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tplink_deco/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"options": {
"step": {
"user": {
"init": {
"title": "TP-Link Deco",
"description": "Use the credentials for the admin web portal. See https://github.com/amosyuen/ha-tplink-deco",
"data": {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tplink_deco/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"options": {
"step": {
"user": {
"init": {
"title": "TP-Link Deco",
"data": {
"username": "Identifiant",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tplink_deco/translations/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"options": {
"step": {
"user": {
"init": {
"title": "TP-Link Deco",
"data": {
"username": "Brukernavn",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tplink_deco/translations/pt_br.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"options": {
"step": {
"user": {
"init": {
"title": "TP-Link Deco",
"description": "Use as credenciais para o portal da Web do administrador. Veja https://github.com/amosyuen/ha-tplink-deco",
"data": {
Expand Down

0 comments on commit 6da9806

Please sign in to comment.