From 2b59772be1d9238cb0a5a474380d37b39e68b7ea Mon Sep 17 00:00:00 2001 From: Yordan Suarez Date: Thu, 13 Jan 2022 17:10:34 -0500 Subject: [PATCH] only get accounts data in config flow + failure translation --- custom_components/fpl/config_flow.py | 13 +++++++------ custom_components/fpl/translations/en.json | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/custom_components/fpl/config_flow.py b/custom_components/fpl/config_flow.py index 538088e..707ee6d 100644 --- a/custom_components/fpl/config_flow.py +++ b/custom_components/fpl/config_flow.py @@ -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" diff --git a/custom_components/fpl/translations/en.json b/custom_components/fpl/translations/en.json index 8bcd4d0..0d954f4 100644 --- a/custom_components/fpl/translations/en.json +++ b/custom_components/fpl/translations/en.json @@ -13,6 +13,7 @@ } }, "error": { + "failure": "An error ocurred, please check the logs", "auth": "Username/Password is wrong.", "name_exists": "Configuration already exists.", "invalid_username": "Invalid Email",