mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Use new reauth helpers in samsungtv (#128729)
This commit is contained in:
parent
ed9f40fc4c
commit
f17c5bc334
@ -10,7 +10,7 @@ from urllib.parse import urlparse
|
||||
import getmac
|
||||
|
||||
from homeassistant.components import ssdp
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MAC,
|
||||
@ -36,7 +36,6 @@ from .const import (
|
||||
CONF_SESSION_ID,
|
||||
CONF_SSDP_MAIN_TV_AGENT_LOCATION,
|
||||
CONF_SSDP_RENDERING_CONTROL_LOCATION,
|
||||
DOMAIN,
|
||||
ENTRY_RELOAD_COOLDOWN,
|
||||
LEGACY_PORT,
|
||||
LOGGER,
|
||||
@ -135,16 +134,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: SamsungTVConfigEntry) ->
|
||||
def _access_denied() -> None:
|
||||
"""Access denied callback."""
|
||||
LOGGER.debug("Access denied in getting remote object")
|
||||
hass.create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={
|
||||
"source": SOURCE_REAUTH,
|
||||
"entry_id": entry.entry_id,
|
||||
},
|
||||
data=entry.data,
|
||||
)
|
||||
)
|
||||
entry.async_start_reauth(hass)
|
||||
|
||||
bridge.register_reauth_callback(_access_denied)
|
||||
|
||||
|
@ -105,7 +105,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize flow."""
|
||||
self._reauth_entry: ConfigEntry | None = None
|
||||
self._host: str = ""
|
||||
self._mac: str | None = None
|
||||
self._udn: str | None = None
|
||||
@ -529,9 +528,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle configuration by re-auth."""
|
||||
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
if entry_data.get(CONF_MODEL) and entry_data.get(CONF_NAME):
|
||||
self._title = f"{entry_data[CONF_NAME]} ({entry_data[CONF_MODEL]})"
|
||||
else:
|
||||
@ -543,22 +539,23 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
) -> ConfigFlowResult:
|
||||
"""Confirm reauth."""
|
||||
errors = {}
|
||||
assert self._reauth_entry
|
||||
method = self._reauth_entry.data[CONF_METHOD]
|
||||
|
||||
reauth_entry = self._get_reauth_entry()
|
||||
method = reauth_entry.data[CONF_METHOD]
|
||||
if user_input is not None:
|
||||
if method == METHOD_ENCRYPTED_WEBSOCKET:
|
||||
return await self.async_step_reauth_confirm_encrypted()
|
||||
bridge = SamsungTVBridge.get_bridge(
|
||||
self.hass,
|
||||
method,
|
||||
self._reauth_entry.data[CONF_HOST],
|
||||
reauth_entry.data[CONF_HOST],
|
||||
)
|
||||
result = await bridge.async_try_connect()
|
||||
if result == RESULT_SUCCESS:
|
||||
new_data = dict(self._reauth_entry.data)
|
||||
new_data = dict(reauth_entry.data)
|
||||
new_data[CONF_TOKEN] = bridge.token
|
||||
return self.async_update_reload_and_abort(
|
||||
self._reauth_entry,
|
||||
reauth_entry,
|
||||
data=new_data,
|
||||
)
|
||||
if result not in (RESULT_AUTH_MISSING, RESULT_CANNOT_CONNECT):
|
||||
@ -587,8 +584,9 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
) -> ConfigFlowResult:
|
||||
"""Confirm reauth (encrypted method)."""
|
||||
errors = {}
|
||||
assert self._reauth_entry
|
||||
await self._async_start_encrypted_pairing(self._reauth_entry.data[CONF_HOST])
|
||||
|
||||
reauth_entry = self._get_reauth_entry()
|
||||
await self._async_start_encrypted_pairing(reauth_entry.data[CONF_HOST])
|
||||
assert self._authenticator is not None
|
||||
|
||||
if user_input is not None:
|
||||
@ -598,9 +596,8 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
and (session_id := await self._authenticator.get_session_id_and_close())
|
||||
):
|
||||
return self.async_update_reload_and_abort(
|
||||
self._reauth_entry,
|
||||
data={
|
||||
**self._reauth_entry.data,
|
||||
reauth_entry,
|
||||
data_updates={
|
||||
CONF_TOKEN: token,
|
||||
CONF_SESSION_ID: session_id,
|
||||
},
|
||||
|
@ -7,7 +7,8 @@ from homeassistant.components.device_automation import DeviceAutomationType
|
||||
from homeassistant.components.device_automation.exceptions import (
|
||||
InvalidDeviceAutomationConfig,
|
||||
)
|
||||
from homeassistant.components.samsungtv import DOMAIN, device_trigger
|
||||
from homeassistant.components.samsungtv import device_trigger
|
||||
from homeassistant.components.samsungtv.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
@ -5,7 +5,7 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import automation
|
||||
from homeassistant.components.samsungtv import DOMAIN
|
||||
from homeassistant.components.samsungtv.const import DOMAIN
|
||||
from homeassistant.const import SERVICE_RELOAD, SERVICE_TURN_ON
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
Loading…
x
Reference in New Issue
Block a user