Skip to content
Snippets Groups Projects
Unverified Commit 3fa460a4 authored by epenet's avatar epenet Committed by GitHub
Browse files

Use reconfigure helpers in madvr config flow (#128012)

parent 021e7ce4
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,6 @@ import voluptuous as vol
from homeassistant.config_entries import (
SOURCE_RECONFIGURE,
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
)
......@@ -37,8 +36,6 @@ class MadVRConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1
entry: ConfigEntry
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
......@@ -49,7 +46,6 @@ class MadVRConfigFlow(ConfigFlow, domain=DOMAIN):
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle reconfiguration of the device."""
self.entry = self._get_reconfigure_entry()
return await self.async_step_reconfigure_confirm()
async def async_step_reconfigure_confirm(
......@@ -80,23 +76,16 @@ class MadVRConfigFlow(ConfigFlow, domain=DOMAIN):
else:
_LOGGER.debug("MAC address found: %s", mac)
# abort if the detected mac differs from the one in the entry
await self.async_set_unique_id(mac)
if self.source == SOURCE_RECONFIGURE:
existing_mac = self.entry.unique_id
if existing_mac != mac:
_LOGGER.debug(
"MAC address changed from %s to %s", existing_mac, mac
)
# abort
return self.async_abort(reason="set_up_new_device")
self._abort_if_unique_id_mismatch(reason="set_up_new_device")
_LOGGER.debug("Reconfiguration done")
return self.async_update_reload_and_abort(
entry=self.entry,
entry=self._get_reconfigure_entry(),
data={**user_input, CONF_HOST: host, CONF_PORT: port},
reason="reconfigure_successful",
)
# abort if already configured with same mac
await self.async_set_unique_id(mac)
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
_LOGGER.debug("Configuration successful")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment