diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index d87f75939f5..f448fa27a46 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Mapping -from typing import TYPE_CHECKING, Any, Final +from typing import Any, Final from aioshelly.block_device import BlockDevice from aioshelly.common import ConnectionOptions, get_info @@ -146,7 +146,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN): port: int = DEFAULT_HTTP_PORT info: dict[str, Any] = {} device_info: dict[str, Any] = {} - entry: ConfigEntry | None = None + entry: ConfigEntry async def async_step_user( self, user_input: dict[str, Any] | None = None @@ -356,7 +356,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle configuration by re-auth.""" - self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) + self.entry = self._get_reauth_entry() return await self.async_step_reauth_confirm() async def async_step_reauth_confirm( @@ -364,7 +364,6 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN): ) -> ConfigFlowResult: """Dialog that informs the user that reauth is required.""" errors: dict[str, str] = {} - assert self.entry is not None host = self.entry.data[CONF_HOST] port = get_http_port(self.entry.data) @@ -403,14 +402,9 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle a reconfiguration flow initialized by the user.""" - entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) - - if TYPE_CHECKING: - assert entry is not None - - self.host = entry.data[CONF_HOST] - self.port = entry.data.get(CONF_PORT, DEFAULT_HTTP_PORT) - self.entry = entry + self.host = entry_data[CONF_HOST] + self.port = entry_data.get(CONF_PORT, DEFAULT_HTTP_PORT) + self.entry = self._get_reconfigure_entry() return await self.async_step_reconfigure_confirm() @@ -420,9 +414,6 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a reconfiguration flow initialized by the user.""" errors = {} - if TYPE_CHECKING: - assert self.entry is not None - if user_input is not None: host = user_input[CONF_HOST] port = user_input.get(CONF_PORT, DEFAULT_HTTP_PORT)