mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Remember Opower utility and username on config flow errors (#148097)
This commit is contained in:
parent
f1698cdb75
commit
fea7dc7eba
@ -26,6 +26,7 @@ from .const import CONF_TOTP_SECRET, CONF_UTILITY, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
STEP_USER_DATA_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_UTILITY): vol.In(get_supported_utility_names()),
|
||||
@ -88,9 +89,15 @@ class OpowerConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
errors = await _validate_login(self.hass, user_input)
|
||||
if not errors:
|
||||
return self._async_create_opower_entry(user_input)
|
||||
|
||||
else:
|
||||
user_input = {}
|
||||
user_input.pop(CONF_PASSWORD, None)
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
||||
step_id="user",
|
||||
data_schema=self.add_suggested_values_to_schema(
|
||||
STEP_USER_DATA_SCHEMA, user_input
|
||||
),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_mfa(
|
||||
|
@ -13,7 +13,7 @@ from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, get_schema_suggested_value
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, name="mock_setup_entry")
|
||||
@ -203,6 +203,15 @@ async def test_form_exceptions(
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": expected_error}
|
||||
# On error, the form should have the previous user input, except password,
|
||||
# as suggested values.
|
||||
data_schema = result2["data_schema"].schema
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, "utility")
|
||||
== "Pacific Gas and Electric Company (PG&E)"
|
||||
)
|
||||
assert get_schema_suggested_value(data_schema, "username") == "test-username"
|
||||
assert get_schema_suggested_value(data_schema, "password") is None
|
||||
assert mock_login.call_count == 1
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user