only get accounts data in config flow + failure translation

This commit is contained in:
Yordan Suarez
2022-01-13 17:10:34 -05:00
parent d0070295dc
commit 2b59772be1
2 changed files with 8 additions and 6 deletions

View File

@@ -7,14 +7,14 @@ from homeassistant import config_entries
from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.core import callback from homeassistant.core import callback
from .fplapi import FplApi
from .const import DOMAIN, CONF_USERNAME, CONF_PASSWORD, CONF_NAME from .const import DOMAIN, CONF_USERNAME, CONF_PASSWORD, CONF_NAME
from .fplapi import ( from .fplapi import (
LOGIN_RESULT_OK, LOGIN_RESULT_OK,
LOGIN_RESULT_FAILURE,
LOGIN_RESULT_INVALIDUSER, LOGIN_RESULT_INVALIDUSER,
LOGIN_RESULT_INVALIDPASSWORD, LOGIN_RESULT_INVALIDPASSWORD,
FplApi,
) )
@@ -59,8 +59,9 @@ class FplFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
result = await api.login() result = await api.login()
if result == LOGIN_RESULT_OK: if result == LOGIN_RESULT_OK:
fplData = await api.async_get_data()
accounts = fplData["accounts"] accounts = await api.async_get_open_accounts()
await api.logout()
user_input["accounts"] = accounts user_input["accounts"] = accounts
@@ -72,8 +73,8 @@ class FplFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if result == LOGIN_RESULT_INVALIDPASSWORD: if result == LOGIN_RESULT_INVALIDPASSWORD:
self._errors[CONF_PASSWORD] = "invalid_password" self._errors[CONF_PASSWORD] = "invalid_password"
if result is None: if result == LOGIN_RESULT_FAILURE:
self._errors["base"] = "auth" self._errors["base"] = "failure"
else: else:
self._errors[CONF_NAME] = "name_exists" self._errors[CONF_NAME] = "name_exists"

View File

@@ -13,6 +13,7 @@
} }
}, },
"error": { "error": {
"failure": "An error ocurred, please check the logs",
"auth": "Username/Password is wrong.", "auth": "Username/Password is wrong.",
"name_exists": "Configuration already exists.", "name_exists": "Configuration already exists.",
"invalid_username": "Invalid Email", "invalid_username": "Invalid Email",