mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Improve SamsungTV config flow type hints (#144820)
This commit is contained in:
parent
55b9dee448
commit
d197debbc0
@ -109,9 +109,11 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
VERSION = 2
|
VERSION = 2
|
||||||
MINOR_VERSION = 2
|
MINOR_VERSION = 2
|
||||||
|
|
||||||
|
_host: str
|
||||||
|
_bridge: SamsungTVBridge
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize flow."""
|
"""Initialize flow."""
|
||||||
self._host: str = ""
|
|
||||||
self._mac: str | None = None
|
self._mac: str | None = None
|
||||||
self._udn: str | None = None
|
self._udn: str | None = None
|
||||||
self._upnp_udn: str | None = None
|
self._upnp_udn: str | None = None
|
||||||
@ -124,13 +126,11 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self._name: str | None = None
|
self._name: str | None = None
|
||||||
self._title: str = ""
|
self._title: str = ""
|
||||||
self._id: int | None = None
|
self._id: int | None = None
|
||||||
self._bridge: SamsungTVBridge | None = None
|
|
||||||
self._device_info: dict[str, Any] | None = None
|
self._device_info: dict[str, Any] | None = None
|
||||||
self._authenticator: SamsungTVEncryptedWSAsyncAuthenticator | None = None
|
self._authenticator: SamsungTVEncryptedWSAsyncAuthenticator | None = None
|
||||||
|
|
||||||
def _base_config_entry(self) -> dict[str, Any]:
|
def _base_config_entry(self) -> dict[str, Any]:
|
||||||
"""Generate the base config entry without the method."""
|
"""Generate the base config entry without the method."""
|
||||||
assert self._bridge is not None
|
|
||||||
return {
|
return {
|
||||||
CONF_HOST: self._host,
|
CONF_HOST: self._host,
|
||||||
CONF_MAC: self._mac,
|
CONF_MAC: self._mac,
|
||||||
@ -144,7 +144,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
def _get_entry_from_bridge(self) -> ConfigFlowResult:
|
def _get_entry_from_bridge(self) -> ConfigFlowResult:
|
||||||
"""Get device entry."""
|
"""Get device entry."""
|
||||||
assert self._bridge
|
|
||||||
data = self._base_config_entry()
|
data = self._base_config_entry()
|
||||||
if self._bridge.token:
|
if self._bridge.token:
|
||||||
data[CONF_TOKEN] = self._bridge.token
|
data[CONF_TOKEN] = self._bridge.token
|
||||||
@ -164,7 +163,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, raise_on_progress: bool = True
|
self, raise_on_progress: bool = True
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set the unique id from the udn."""
|
"""Set the unique id from the udn."""
|
||||||
assert self._host is not None
|
|
||||||
# Set the unique id without raising on progress in case
|
# Set the unique id without raising on progress in case
|
||||||
# there are two SSDP flows with for each ST
|
# there are two SSDP flows with for each ST
|
||||||
await self.async_set_unique_id(self._udn, raise_on_progress=False)
|
await self.async_set_unique_id(self._udn, raise_on_progress=False)
|
||||||
@ -270,7 +268,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
if await self._async_set_name_host_from_input(user_input):
|
if await self._async_set_name_host_from_input(user_input):
|
||||||
await self._async_create_bridge()
|
await self._async_create_bridge()
|
||||||
assert self._bridge
|
|
||||||
self._async_abort_entries_match({CONF_HOST: self._host})
|
self._async_abort_entries_match({CONF_HOST: self._host})
|
||||||
if self._bridge.method != METHOD_LEGACY:
|
if self._bridge.method != METHOD_LEGACY:
|
||||||
# Legacy bridge does not provide device info
|
# Legacy bridge does not provide device info
|
||||||
@ -290,7 +287,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a pairing by accepting the message on the TV."""
|
"""Handle a pairing by accepting the message on the TV."""
|
||||||
assert self._bridge is not None
|
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
result = await self._bridge.async_try_connect()
|
result = await self._bridge.async_try_connect()
|
||||||
@ -312,7 +308,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a encrypted pairing."""
|
"""Handle a encrypted pairing."""
|
||||||
assert self._host is not None
|
|
||||||
await self._async_start_encrypted_pairing(self._host)
|
await self._async_start_encrypted_pairing(self._host)
|
||||||
assert self._authenticator is not None
|
assert self._authenticator is not None
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
@ -427,7 +422,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
@callback
|
@callback
|
||||||
def _async_start_discovery_with_mac_address(self) -> None:
|
def _async_start_discovery_with_mac_address(self) -> None:
|
||||||
"""Start discovery."""
|
"""Start discovery."""
|
||||||
assert self._host is not None
|
|
||||||
if (entry := self._async_update_existing_matching_entry()) and entry.unique_id:
|
if (entry := self._async_update_existing_matching_entry()) and entry.unique_id:
|
||||||
# If we have the unique id and the mac we abort
|
# If we have the unique id and the mac we abort
|
||||||
# as we do not need anything else
|
# as we do not need anything else
|
||||||
@ -525,7 +519,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle user-confirmation of discovered node."""
|
"""Handle user-confirmation of discovered node."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
await self._async_create_bridge()
|
await self._async_create_bridge()
|
||||||
assert self._bridge
|
|
||||||
if self._bridge.method == METHOD_ENCRYPTED_WEBSOCKET:
|
if self._bridge.method == METHOD_ENCRYPTED_WEBSOCKET:
|
||||||
return await self.async_step_encrypted_pairing()
|
return await self.async_step_encrypted_pairing()
|
||||||
return await self.async_step_pairing({})
|
return await self.async_step_pairing({})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user