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.core import callback
from .fplapi import FplApi
from .const import DOMAIN, CONF_USERNAME, CONF_PASSWORD, CONF_NAME
from .fplapi import (
LOGIN_RESULT_OK,
LOGIN_RESULT_FAILURE,
LOGIN_RESULT_INVALIDUSER,
LOGIN_RESULT_INVALIDPASSWORD,
FplApi,
)
@@ -59,8 +59,9 @@ class FplFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
result = await api.login()
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
@@ -72,8 +73,8 @@ class FplFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if result == LOGIN_RESULT_INVALIDPASSWORD:
self._errors[CONF_PASSWORD] = "invalid_password"
if result is None:
self._errors["base"] = "auth"
if result == LOGIN_RESULT_FAILURE:
self._errors["base"] = "failure"
else:
self._errors[CONF_NAME] = "name_exists"