Add late PR improvements to La Marzocco (#108162)

* add Martin's suggestions

* use password description

* fix for reauth + test

* fix invalid_auth test

* Update homeassistant/components/lamarzocco/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Josef Zweck 2024-01-16 19:35:50 +01:00 committed by GitHub
parent b24222bd1d
commit 95ed1ada50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 17 deletions

View File

@ -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)

View File

@ -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%]"
}
}
}
},

View File

@ -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"

View File

@ -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