Skip to content

Commit 14173bd

Browse files
chemelli74frenck
authored andcommitted
Fix reauth for Alexa Devices (home-assistant#152128)
1 parent d2e7537 commit 14173bd

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

homeassistant/components/alexa_devices/config_flow.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ async def async_step_reauth_confirm(
107107

108108
if user_input is not None:
109109
try:
110-
await validate_input(self.hass, {**reauth_entry.data, **user_input})
110+
data = await validate_input(
111+
self.hass, {**reauth_entry.data, **user_input}
112+
)
111113
except CannotConnect:
112114
errors["base"] = "cannot_connect"
113115
except (CannotAuthenticate, TypeError):
@@ -119,8 +121,9 @@ async def async_step_reauth_confirm(
119121
reauth_entry,
120122
data={
121123
CONF_USERNAME: entry_data[CONF_USERNAME],
122-
CONF_PASSWORD: entry_data[CONF_PASSWORD],
124+
CONF_PASSWORD: user_input[CONF_PASSWORD],
123125
CONF_CODE: user_input[CONF_CODE],
126+
CONF_LOGIN_DATA: data,
124127
},
125128
)
126129

tests/components/alexa_devices/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def mock_amazon_devices_client() -> Generator[AsyncMock]:
4545
client = mock_client.return_value
4646
client.login_mode_interactive.return_value = {
4747
"customer_info": {"user_id": TEST_USERNAME},
48+
CONF_SITE: "https://www.amazon.com",
4849
}
4950
client.get_devices_data.return_value = {
5051
TEST_SERIAL_NUMBER: AmazonDevice(

tests/components/alexa_devices/test_config_flow.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
)
1010
import pytest
1111

12-
from homeassistant.components.alexa_devices.const import CONF_LOGIN_DATA, DOMAIN
12+
from homeassistant.components.alexa_devices.const import (
13+
CONF_LOGIN_DATA,
14+
CONF_SITE,
15+
DOMAIN,
16+
)
1317
from homeassistant.config_entries import SOURCE_USER
1418
from homeassistant.const import CONF_CODE, CONF_PASSWORD, CONF_USERNAME
1519
from homeassistant.core import HomeAssistant
@@ -48,6 +52,7 @@ async def test_full_flow(
4852
CONF_PASSWORD: TEST_PASSWORD,
4953
CONF_LOGIN_DATA: {
5054
"customer_info": {"user_id": TEST_USERNAME},
55+
CONF_SITE: "https://www.amazon.com",
5156
},
5257
}
5358
assert result["result"].unique_id == TEST_USERNAME
@@ -158,6 +163,16 @@ async def test_reauth_successful(
158163
assert result["type"] is FlowResultType.ABORT
159164
assert result["reason"] == "reauth_successful"
160165

166+
assert mock_config_entry.data == {
167+
CONF_CODE: "000000",
168+
CONF_USERNAME: TEST_USERNAME,
169+
CONF_PASSWORD: "other_fake_password",
170+
CONF_LOGIN_DATA: {
171+
"customer_info": {"user_id": TEST_USERNAME},
172+
CONF_SITE: "https://www.amazon.com",
173+
},
174+
}
175+
161176

162177
@pytest.mark.parametrize(
163178
("side_effect", "error"),
@@ -206,8 +221,15 @@ async def test_reauth_not_successful(
206221

207222
assert result["type"] is FlowResultType.ABORT
208223
assert result["reason"] == "reauth_successful"
209-
assert mock_config_entry.data[CONF_PASSWORD] == "fake_password"
210-
assert mock_config_entry.data[CONF_CODE] == "111111"
224+
assert mock_config_entry.data == {
225+
CONF_CODE: "111111",
226+
CONF_USERNAME: TEST_USERNAME,
227+
CONF_PASSWORD: "fake_password",
228+
CONF_LOGIN_DATA: {
229+
"customer_info": {"user_id": TEST_USERNAME},
230+
CONF_SITE: "https://www.amazon.com",
231+
},
232+
}
211233

212234

213235
async def test_reconfigure_successful(
@@ -240,7 +262,14 @@ async def test_reconfigure_successful(
240262
assert reconfigure_result["reason"] == "reconfigure_successful"
241263

242264
# changed entry
243-
assert mock_config_entry.data[CONF_PASSWORD] == new_password
265+
assert mock_config_entry.data == {
266+
CONF_USERNAME: TEST_USERNAME,
267+
CONF_PASSWORD: new_password,
268+
CONF_LOGIN_DATA: {
269+
"customer_info": {"user_id": TEST_USERNAME},
270+
CONF_SITE: "https://www.amazon.com",
271+
},
272+
}
244273

245274

246275
@pytest.mark.parametrize(
@@ -297,5 +326,6 @@ async def test_reconfigure_fails(
297326
CONF_PASSWORD: TEST_PASSWORD,
298327
CONF_LOGIN_DATA: {
299328
"customer_info": {"user_id": TEST_USERNAME},
329+
CONF_SITE: "https://www.amazon.com",
300330
},
301331
}

0 commit comments

Comments
 (0)