mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use _get_reauth/reconfigure_entry in lamarzocco (#127298)
This commit is contained in:
parent
5ed7efb01d
commit
3f7c6055d4
@ -15,6 +15,8 @@ from homeassistant.components.bluetooth import (
|
|||||||
async_discovered_service_info,
|
async_discovered_service_info,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_REAUTH,
|
||||||
|
SOURCE_RECONFIGURE,
|
||||||
ConfigEntry,
|
ConfigEntry,
|
||||||
ConfigFlow,
|
ConfigFlow,
|
||||||
ConfigFlowResult,
|
ConfigFlowResult,
|
||||||
@ -52,11 +54,11 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 2
|
VERSION = 2
|
||||||
|
|
||||||
|
reauth_entry: ConfigEntry
|
||||||
|
reconfigure_entry: ConfigEntry
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize the config flow."""
|
"""Initialize the config flow."""
|
||||||
|
|
||||||
self.reauth_entry: ConfigEntry | None = None
|
|
||||||
self.reconfigure_entry: ConfigEntry | None = None
|
|
||||||
self._config: dict[str, Any] = {}
|
self._config: dict[str, Any] = {}
|
||||||
self._fleet: dict[str, LaMarzoccoDeviceInfo] = {}
|
self._fleet: dict[str, LaMarzoccoDeviceInfo] = {}
|
||||||
self._discovered: dict[str, str] = {}
|
self._discovered: dict[str, str] = {}
|
||||||
@ -70,7 +72,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
if user_input:
|
if user_input:
|
||||||
data: dict[str, Any] = {}
|
data: dict[str, Any] = {}
|
||||||
if self.reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
data = dict(self.reauth_entry.data)
|
data = dict(self.reauth_entry.data)
|
||||||
data = {
|
data = {
|
||||||
**data,
|
**data,
|
||||||
@ -95,7 +97,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
errors["base"] = "no_machines"
|
errors["base"] = "no_machines"
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
if self.reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self.reauth_entry, data=data, reason="reauth_successful"
|
self.reauth_entry, data=data, reason="reauth_successful"
|
||||||
)
|
)
|
||||||
@ -134,7 +136,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
if user_input:
|
if user_input:
|
||||||
if not self._discovered:
|
if not self._discovered:
|
||||||
serial_number = user_input[CONF_MACHINE]
|
serial_number = user_input[CONF_MACHINE]
|
||||||
if self.reconfigure_entry is None:
|
if self.source != SOURCE_RECONFIGURE:
|
||||||
await self.async_set_unique_id(serial_number)
|
await self.async_set_unique_id(serial_number)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
else:
|
else:
|
||||||
@ -154,7 +156,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self._config[CONF_HOST] = user_input[CONF_HOST]
|
self._config[CONF_HOST] = user_input[CONF_HOST]
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
if self.reconfigure_entry:
|
if self.source == SOURCE_RECONFIGURE:
|
||||||
for service_info in async_discovered_service_info(self.hass):
|
for service_info in async_discovered_service_info(self.hass):
|
||||||
self._discovered[service_info.name] = service_info.address
|
self._discovered[service_info.name] = service_info.address
|
||||||
|
|
||||||
@ -204,8 +206,6 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle Bluetooth device selection."""
|
"""Handle Bluetooth device selection."""
|
||||||
|
|
||||||
assert self.reconfigure_entry
|
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self.reconfigure_entry,
|
self.reconfigure_entry,
|
||||||
@ -266,9 +266,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""Perform reauth upon an API authentication error."""
|
||||||
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
self.reauth_entry = self._get_reauth_entry()
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
@ -291,17 +289,13 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Perform reconfiguration of the config entry."""
|
"""Perform reconfiguration of the config entry."""
|
||||||
self.reconfigure_entry = self.hass.config_entries.async_get_entry(
|
self.reconfigure_entry = self._get_reconfigure_entry()
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
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(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Confirm reconfiguration of the device."""
|
"""Confirm reconfiguration of the device."""
|
||||||
assert self.reconfigure_entry
|
|
||||||
|
|
||||||
if not user_input:
|
if not user_input:
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reconfigure_confirm",
|
step_id="reconfigure_confirm",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user