From d197debbc04f2886f917abe55c32b3fe9ab6d576 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 13 May 2025 14:02:07 +0200 Subject: [PATCH] Improve SamsungTV config flow type hints (#144820) --- homeassistant/components/samsungtv/config_flow.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/samsungtv/config_flow.py b/homeassistant/components/samsungtv/config_flow.py index 806a4db4bf6..c7406cc740f 100644 --- a/homeassistant/components/samsungtv/config_flow.py +++ b/homeassistant/components/samsungtv/config_flow.py @@ -109,9 +109,11 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 2 MINOR_VERSION = 2 + _host: str + _bridge: SamsungTVBridge + def __init__(self) -> None: """Initialize flow.""" - self._host: str = "" self._mac: str | None = None self._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._title: str = "" self._id: int | None = None - self._bridge: SamsungTVBridge | None = None self._device_info: dict[str, Any] | None = None self._authenticator: SamsungTVEncryptedWSAsyncAuthenticator | None = None def _base_config_entry(self) -> dict[str, Any]: """Generate the base config entry without the method.""" - assert self._bridge is not None return { CONF_HOST: self._host, CONF_MAC: self._mac, @@ -144,7 +144,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN): def _get_entry_from_bridge(self) -> ConfigFlowResult: """Get device entry.""" - assert self._bridge data = self._base_config_entry() if self._bridge.token: data[CONF_TOKEN] = self._bridge.token @@ -164,7 +163,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN): self, raise_on_progress: bool = True ) -> None: """Set the unique id from the udn.""" - assert self._host is not None # Set the unique id without raising on progress in case # there are two SSDP flows with for each ST 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 await self._async_set_name_host_from_input(user_input): await self._async_create_bridge() - assert self._bridge self._async_abort_entries_match({CONF_HOST: self._host}) if self._bridge.method != METHOD_LEGACY: # Legacy bridge does not provide device info @@ -290,7 +287,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN): self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: """Handle a pairing by accepting the message on the TV.""" - assert self._bridge is not None errors: dict[str, str] = {} if user_input is not None: result = await self._bridge.async_try_connect() @@ -312,7 +308,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN): self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: """Handle a encrypted pairing.""" - assert self._host is not None await self._async_start_encrypted_pairing(self._host) assert self._authenticator is not None errors: dict[str, str] = {} @@ -427,7 +422,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN): @callback def _async_start_discovery_with_mac_address(self) -> None: """Start discovery.""" - assert self._host is not None if (entry := self._async_update_existing_matching_entry()) and entry.unique_id: # If we have the unique id and the mac we abort # as we do not need anything else @@ -525,7 +519,6 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN): """Handle user-confirmation of discovered node.""" if user_input is not None: await self._async_create_bridge() - assert self._bridge if self._bridge.method == METHOD_ENCRYPTED_WEBSOCKET: return await self.async_step_encrypted_pairing() return await self.async_step_pairing({})