diff --git a/homeassistant/components/lamarzocco/config_flow.py b/homeassistant/components/lamarzocco/config_flow.py index b2f097b818b..7c63532104f 100644 --- a/homeassistant/components/lamarzocco/config_flow.py +++ b/homeassistant/components/lamarzocco/config_flow.py @@ -56,7 +56,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.debug("Server rejected login credentials") errors["base"] = "invalid_auth" except RequestNotSuccessful as exc: - _LOGGER.exception("Error connecting to server: %s", str(exc)) + _LOGGER.error("Error connecting to server: %s", exc) errors["base"] = "cannot_connect" else: if not self._machines: @@ -65,7 +65,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN): if not errors: if self.reauth_entry: self.hass.config_entries.async_update_entry( - self.reauth_entry, data=user_input + self.reauth_entry, data=data ) await self.hass.config_entries.async_reload( self.reauth_entry.entry_id @@ -146,11 +146,20 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN): self.reauth_entry = self.hass.config_entries.async_get_entry( self.context["entry_id"] ) - return self.async_show_form( - step_id="user", - data_schema=vol.Schema( - { - vol.Required(CONF_PASSWORD): str, - } - ), - ) + return await self.async_step_reauth_confirm() + + async def async_step_reauth_confirm( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: + """Dialog that informs the user that reauth is required.""" + if not user_input: + return self.async_show_form( + step_id="reauth_confirm", + data_schema=vol.Schema( + { + vol.Required(CONF_PASSWORD): str, + } + ), + ) + + return await self.async_step_user(user_input) diff --git a/homeassistant/components/lamarzocco/strings.json b/homeassistant/components/lamarzocco/strings.json index e3490270172..01bd3860825 100644 --- a/homeassistant/components/lamarzocco/strings.json +++ b/homeassistant/components/lamarzocco/strings.json @@ -8,9 +8,7 @@ "error": { "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "no_machines": "No machines found in account", - "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", - "machine_not_found": "The configured machine was not found in your account. Did you login to the correct account?", - "unknown": "[%key:common::config_flow::error::unknown%]" + "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]" }, "step": { "user": { @@ -32,6 +30,15 @@ "data_description": { "host": "Local IP address of the machine" } + }, + "reauth_confirm": { + "description": "Re-authentication required. Please enter your password again.", + "data": { + "password": "[%key:common::config_flow::data::password%]" + }, + "data_description": { + "password": "[%key:component::lamarzocco::config::step::user::data_description::password%]" + } } } }, diff --git a/tests/components/lamarzocco/test_config_flow.py b/tests/components/lamarzocco/test_config_flow.py index 703a1e9d36e..e8500ee427d 100644 --- a/tests/components/lamarzocco/test_config_flow.py +++ b/tests/components/lamarzocco/test_config_flow.py @@ -6,11 +6,11 @@ from lmcloud.exceptions import AuthFail, RequestNotSuccessful from homeassistant import config_entries from homeassistant.components.lamarzocco.const import CONF_MACHINE, DOMAIN from homeassistant.config_entries import SOURCE_REAUTH -from homeassistant.const import CONF_HOST +from homeassistant.const import CONF_HOST, CONF_PASSWORD from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResult, FlowResultType -from . import PASSWORD_SELECTION, USER_INPUT +from . import USER_INPUT from tests.common import MockConfigEntry @@ -224,12 +224,16 @@ async def test_reauth_flow( data=mock_config_entry.data, ) + assert result["type"] == FlowResultType.FORM + assert result["step_id"] == "reauth_confirm" + result2 = await hass.config_entries.flow.async_configure( result["flow_id"], - PASSWORD_SELECTION, + {CONF_PASSWORD: "new_password"}, ) assert result2["type"] == FlowResultType.ABORT await hass.async_block_till_done() assert result2["reason"] == "reauth_successful" assert len(mock_lamarzocco.get_all_machines.mock_calls) == 1 + assert mock_config_entry.data[CONF_PASSWORD] == "new_password" diff --git a/tests/components/lamarzocco/test_init.py b/tests/components/lamarzocco/test_init.py index 1302961cfc0..91243c76eaf 100644 --- a/tests/components/lamarzocco/test_init.py +++ b/tests/components/lamarzocco/test_init.py @@ -62,7 +62,7 @@ async def test_invalid_auth( assert len(flows) == 1 flow = flows[0] - assert flow.get("step_id") == "user" + assert flow.get("step_id") == "reauth_confirm" assert flow.get("handler") == DOMAIN assert "context" in flow