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:
Simone Chemelli
2025-04-30 12:26:20 +03:00
committed by GitHub
parent a8bee20aa3
commit 441bca5bda
2 changed files with 12 additions and 10 deletions

View File

@@ -24,6 +24,7 @@ from homeassistant.const import (
CONF_METHOD, CONF_METHOD,
CONF_MODEL, CONF_MODEL,
CONF_NAME, CONF_NAME,
CONF_PIN,
CONF_PORT, CONF_PORT,
CONF_TOKEN, CONF_TOKEN,
) )
@@ -314,7 +315,7 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
if user_input is not None: if user_input is not None:
if ( if (
(pin := user_input.get("pin")) (pin := user_input.get(CONF_PIN))
and (token := await self._authenticator.try_pin(pin)) and (token := await self._authenticator.try_pin(pin))
and (session_id := await self._authenticator.get_session_id_and_close()) and (session_id := await self._authenticator.get_session_id_and_close())
): ):
@@ -333,7 +334,7 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
step_id="encrypted_pairing", step_id="encrypted_pairing",
errors=errors, errors=errors,
description_placeholders={"device": self._title}, description_placeholders={"device": self._title},
data_schema=vol.Schema({vol.Required("pin"): str}), data_schema=vol.Schema({vol.Required(CONF_PIN): str}),
) )
@callback @callback
@@ -596,7 +597,7 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
if user_input is not None: if user_input is not None:
if ( if (
(pin := user_input.get("pin")) (pin := user_input.get(CONF_PIN))
and (token := await self._authenticator.try_pin(pin)) and (token := await self._authenticator.try_pin(pin))
and (session_id := await self._authenticator.get_session_id_and_close()) 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", step_id="reauth_confirm_encrypted",
errors=errors, errors=errors,
description_placeholders={"device": self._title}, description_placeholders={"device": self._title},
data_schema=vol.Schema({vol.Required("pin"): str}), data_schema=vol.Schema({vol.Required(CONF_PIN): str}),
) )

View File

@@ -41,6 +41,7 @@ from homeassistant.const import (
CONF_METHOD, CONF_METHOD,
CONF_MODEL, CONF_MODEL,
CONF_NAME, CONF_NAME,
CONF_PIN,
CONF_PORT, CONF_PORT,
CONF_TOKEN, CONF_TOKEN,
) )
@@ -324,13 +325,13 @@ async def test_user_encrypted_websocket(
assert result2["step_id"] == "encrypted_pairing" assert result2["step_id"] == "encrypted_pairing"
result3 = await hass.config_entries.flow.async_configure( 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["step_id"] == "encrypted_pairing"
assert result3["errors"] == {"base": "invalid_pin"} assert result3["errors"] == {"base": "invalid_pin"}
result4 = await hass.config_entries.flow.async_configure( 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 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" assert result2["step_id"] == "encrypted_pairing"
result3 = await hass.config_entries.flow.async_configure( 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["step_id"] == "encrypted_pairing"
assert result3["errors"] == {"base": "invalid_pin"} assert result3["errors"] == {"base": "invalid_pin"}
result4 = await hass.config_entries.flow.async_configure( 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 assert result4["type"] is FlowResultType.CREATE_ENTRY
@@ -1947,14 +1948,14 @@ async def test_form_reauth_encrypted(hass: HomeAssistant) -> None:
# Invalid PIN # Invalid PIN
result = await hass.config_entries.flow.async_configure( 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["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm_encrypted" assert result["step_id"] == "reauth_confirm_encrypted"
# Valid PIN # Valid PIN
result = await hass.config_entries.flow.async_configure( 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() await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT