Fix reauth for Alexa Devices (#152128)

pull/152138/head
Simone Chemelli 2025-09-11 22:26:47 +02:00 committed by GitHub
parent ae70ca7cba
commit 4985f9a5a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 40 additions and 6 deletions

View File

@ -107,7 +107,9 @@ class AmazonDevicesConfigFlow(ConfigFlow, domain=DOMAIN):
if user_input is not None:
try:
await validate_input(self.hass, {**reauth_entry.data, **user_input})
data = await validate_input(
self.hass, {**reauth_entry.data, **user_input}
)
except CannotConnect:
errors["base"] = "cannot_connect"
except (CannotAuthenticate, TypeError):
@ -119,8 +121,9 @@ class AmazonDevicesConfigFlow(ConfigFlow, domain=DOMAIN):
reauth_entry,
data={
CONF_USERNAME: entry_data[CONF_USERNAME],
CONF_PASSWORD: entry_data[CONF_PASSWORD],
CONF_PASSWORD: user_input[CONF_PASSWORD],
CONF_CODE: user_input[CONF_CODE],
CONF_LOGIN_DATA: data,
},
)

View File

@ -45,6 +45,7 @@ def mock_amazon_devices_client() -> Generator[AsyncMock]:
client = mock_client.return_value
client.login_mode_interactive.return_value = {
"customer_info": {"user_id": TEST_USERNAME},
CONF_SITE: "https://www.amazon.com",
}
client.get_devices_data.return_value = {
TEST_SERIAL_NUMBER: deepcopy(TEST_DEVICE)

View File

@ -9,7 +9,11 @@ from aioamazondevices.exceptions import (
)
import pytest
from homeassistant.components.alexa_devices.const import CONF_LOGIN_DATA, DOMAIN
from homeassistant.components.alexa_devices.const import (
CONF_LOGIN_DATA,
CONF_SITE,
DOMAIN,
)
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_CODE, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
@ -48,6 +52,7 @@ async def test_full_flow(
CONF_PASSWORD: TEST_PASSWORD,
CONF_LOGIN_DATA: {
"customer_info": {"user_id": TEST_USERNAME},
CONF_SITE: "https://www.amazon.com",
},
}
assert result["result"].unique_id == TEST_USERNAME
@ -158,6 +163,16 @@ async def test_reauth_successful(
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
assert mock_config_entry.data == {
CONF_CODE: "000000",
CONF_USERNAME: TEST_USERNAME,
CONF_PASSWORD: "other_fake_password",
CONF_LOGIN_DATA: {
"customer_info": {"user_id": TEST_USERNAME},
CONF_SITE: "https://www.amazon.com",
},
}
@pytest.mark.parametrize(
("side_effect", "error"),
@ -206,8 +221,15 @@ async def test_reauth_not_successful(
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
assert mock_config_entry.data[CONF_PASSWORD] == "fake_password"
assert mock_config_entry.data[CONF_CODE] == "111111"
assert mock_config_entry.data == {
CONF_CODE: "111111",
CONF_USERNAME: TEST_USERNAME,
CONF_PASSWORD: "fake_password",
CONF_LOGIN_DATA: {
"customer_info": {"user_id": TEST_USERNAME},
CONF_SITE: "https://www.amazon.com",
},
}
async def test_reconfigure_successful(
@ -240,7 +262,14 @@ async def test_reconfigure_successful(
assert reconfigure_result["reason"] == "reconfigure_successful"
# changed entry
assert mock_config_entry.data[CONF_PASSWORD] == new_password
assert mock_config_entry.data == {
CONF_USERNAME: TEST_USERNAME,
CONF_PASSWORD: new_password,
CONF_LOGIN_DATA: {
"customer_info": {"user_id": TEST_USERNAME},
CONF_SITE: "https://www.amazon.com",
},
}
@pytest.mark.parametrize(
@ -297,5 +326,6 @@ async def test_reconfigure_fails(
CONF_PASSWORD: TEST_PASSWORD,
CONF_LOGIN_DATA: {
"customer_info": {"user_id": TEST_USERNAME},
CONF_SITE: "https://www.amazon.com",
},
}