mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 14:47:38 +00:00
Use CONF_PIN in SamsungTv config flow (#143621)
* Use CONF_PIN in SamsunTv config flow * Adjust tests --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
a8bee20aa3
commit
441bca5bda
@ -24,6 +24,7 @@ from homeassistant.const import (
|
||||
CONF_METHOD,
|
||||
CONF_MODEL,
|
||||
CONF_NAME,
|
||||
CONF_PIN,
|
||||
CONF_PORT,
|
||||
CONF_TOKEN,
|
||||
)
|
||||
@ -314,7 +315,7 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
if user_input is not None:
|
||||
if (
|
||||
(pin := user_input.get("pin"))
|
||||
(pin := user_input.get(CONF_PIN))
|
||||
and (token := await self._authenticator.try_pin(pin))
|
||||
and (session_id := await self._authenticator.get_session_id_and_close())
|
||||
):
|
||||
@ -333,7 +334,7 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
step_id="encrypted_pairing",
|
||||
errors=errors,
|
||||
description_placeholders={"device": self._title},
|
||||
data_schema=vol.Schema({vol.Required("pin"): str}),
|
||||
data_schema=vol.Schema({vol.Required(CONF_PIN): str}),
|
||||
)
|
||||
|
||||
@callback
|
||||
@ -596,7 +597,7 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
if user_input is not None:
|
||||
if (
|
||||
(pin := user_input.get("pin"))
|
||||
(pin := user_input.get(CONF_PIN))
|
||||
and (token := await self._authenticator.try_pin(pin))
|
||||
and (session_id := await self._authenticator.get_session_id_and_close())
|
||||
):
|
||||
@ -615,5 +616,5 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
step_id="reauth_confirm_encrypted",
|
||||
errors=errors,
|
||||
description_placeholders={"device": self._title},
|
||||
data_schema=vol.Schema({vol.Required("pin"): str}),
|
||||
data_schema=vol.Schema({vol.Required(CONF_PIN): str}),
|
||||
)
|
||||
|
@ -41,6 +41,7 @@ from homeassistant.const import (
|
||||
CONF_METHOD,
|
||||
CONF_MODEL,
|
||||
CONF_NAME,
|
||||
CONF_PIN,
|
||||
CONF_PORT,
|
||||
CONF_TOKEN,
|
||||
)
|
||||
@ -324,13 +325,13 @@ async def test_user_encrypted_websocket(
|
||||
assert result2["step_id"] == "encrypted_pairing"
|
||||
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"], user_input={"pin": "invalid"}
|
||||
result2["flow_id"], user_input={CONF_PIN: "invalid"}
|
||||
)
|
||||
assert result3["step_id"] == "encrypted_pairing"
|
||||
assert result3["errors"] == {"base": "invalid_pin"}
|
||||
|
||||
result4 = await hass.config_entries.flow.async_configure(
|
||||
result3["flow_id"], user_input={"pin": "1234"}
|
||||
result3["flow_id"], user_input={CONF_PIN: "1234"}
|
||||
)
|
||||
|
||||
assert result4["type"] is FlowResultType.CREATE_ENTRY
|
||||
@ -728,13 +729,13 @@ async def test_ssdp_encrypted_websocket_success_populates_mac_address_and_ssdp_l
|
||||
assert result2["step_id"] == "encrypted_pairing"
|
||||
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"], user_input={"pin": "invalid"}
|
||||
result2["flow_id"], user_input={CONF_PIN: "invalid"}
|
||||
)
|
||||
assert result3["step_id"] == "encrypted_pairing"
|
||||
assert result3["errors"] == {"base": "invalid_pin"}
|
||||
|
||||
result4 = await hass.config_entries.flow.async_configure(
|
||||
result3["flow_id"], user_input={"pin": "1234"}
|
||||
result3["flow_id"], user_input={CONF_PIN: "1234"}
|
||||
)
|
||||
|
||||
assert result4["type"] is FlowResultType.CREATE_ENTRY
|
||||
@ -1947,14 +1948,14 @@ async def test_form_reauth_encrypted(hass: HomeAssistant) -> None:
|
||||
|
||||
# Invalid PIN
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={"pin": "invalid"}
|
||||
result["flow_id"], user_input={CONF_PIN: "invalid"}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm_encrypted"
|
||||
|
||||
# Valid PIN
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={"pin": "1234"}
|
||||
result["flow_id"], user_input={CONF_PIN: "1234"}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
|
Loading…
x
Reference in New Issue
Block a user