mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use reconfigure helpers in madvr config flow (#128012)
This commit is contained in:
parent
021e7ce49b
commit
3fa460a42a
@ -10,7 +10,6 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
SOURCE_RECONFIGURE,
|
SOURCE_RECONFIGURE,
|
||||||
ConfigEntry,
|
|
||||||
ConfigFlow,
|
ConfigFlow,
|
||||||
ConfigFlowResult,
|
ConfigFlowResult,
|
||||||
)
|
)
|
||||||
@ -37,8 +36,6 @@ class MadVRConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
entry: ConfigEntry
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
@ -49,7 +46,6 @@ class MadVRConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle reconfiguration of the device."""
|
"""Handle reconfiguration of the device."""
|
||||||
self.entry = self._get_reconfigure_entry()
|
|
||||||
return await self.async_step_reconfigure_confirm()
|
return await self.async_step_reconfigure_confirm()
|
||||||
|
|
||||||
async def async_step_reconfigure_confirm(
|
async def async_step_reconfigure_confirm(
|
||||||
@ -80,23 +76,16 @@ class MadVRConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
else:
|
else:
|
||||||
_LOGGER.debug("MAC address found: %s", mac)
|
_LOGGER.debug("MAC address found: %s", mac)
|
||||||
# abort if the detected mac differs from the one in the entry
|
# abort if the detected mac differs from the one in the entry
|
||||||
|
await self.async_set_unique_id(mac)
|
||||||
if self.source == SOURCE_RECONFIGURE:
|
if self.source == SOURCE_RECONFIGURE:
|
||||||
existing_mac = self.entry.unique_id
|
self._abort_if_unique_id_mismatch(reason="set_up_new_device")
|
||||||
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")
|
|
||||||
|
|
||||||
_LOGGER.debug("Reconfiguration done")
|
_LOGGER.debug("Reconfiguration done")
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
entry=self.entry,
|
entry=self._get_reconfigure_entry(),
|
||||||
data={**user_input, CONF_HOST: host, CONF_PORT: port},
|
data={**user_input, CONF_HOST: host, CONF_PORT: port},
|
||||||
reason="reconfigure_successful",
|
|
||||||
)
|
)
|
||||||
# abort if already configured with same mac
|
# abort if already configured with same mac
|
||||||
await self.async_set_unique_id(mac)
|
|
||||||
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
||||||
|
|
||||||
_LOGGER.debug("Configuration successful")
|
_LOGGER.debug("Configuration successful")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user