mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Use OptionsFlowWithReload in roborock (#149118)
This commit is contained in:
parent
0d42b24467
commit
1b8f3348b0
@ -43,8 +43,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
async def async_setup_entry(hass: HomeAssistant, entry: RoborockConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: RoborockConfigEntry) -> bool:
|
||||||
"""Set up roborock from a config entry."""
|
"""Set up roborock from a config entry."""
|
||||||
|
|
||||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
|
||||||
|
|
||||||
user_data = UserData.from_dict(entry.data[CONF_USER_DATA])
|
user_data = UserData.from_dict(entry.data[CONF_USER_DATA])
|
||||||
api_client = RoborockApiClient(
|
api_client = RoborockApiClient(
|
||||||
entry.data[CONF_USERNAME],
|
entry.data[CONF_USERNAME],
|
||||||
@ -336,12 +334,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: RoborockConfigEntry) ->
|
|||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
|
|
||||||
async def update_listener(hass: HomeAssistant, entry: RoborockConfigEntry) -> None:
|
|
||||||
"""Handle options update."""
|
|
||||||
# Reload entry to update data
|
|
||||||
await hass.config_entries.async_reload(entry.entry_id)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_remove_entry(hass: HomeAssistant, entry: RoborockConfigEntry) -> None:
|
async def async_remove_entry(hass: HomeAssistant, entry: RoborockConfigEntry) -> None:
|
||||||
"""Handle removal of an entry."""
|
"""Handle removal of an entry."""
|
||||||
await async_remove_map_storage(hass, entry.entry_id)
|
await async_remove_map_storage(hass, entry.entry_id)
|
||||||
|
@ -23,7 +23,7 @@ from homeassistant.config_entries import (
|
|||||||
SOURCE_REAUTH,
|
SOURCE_REAUTH,
|
||||||
ConfigFlow,
|
ConfigFlow,
|
||||||
ConfigFlowResult,
|
ConfigFlowResult,
|
||||||
OptionsFlow,
|
OptionsFlowWithReload,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_USERNAME
|
from homeassistant.const import CONF_USERNAME
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
@ -124,14 +124,9 @@ class RoborockFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
if self.source == SOURCE_REAUTH:
|
if self.source == SOURCE_REAUTH:
|
||||||
self._abort_if_unique_id_mismatch(reason="wrong_account")
|
self._abort_if_unique_id_mismatch(reason="wrong_account")
|
||||||
reauth_entry = self._get_reauth_entry()
|
reauth_entry = self._get_reauth_entry()
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
reauth_entry,
|
reauth_entry, data_updates={CONF_USER_DATA: user_data.as_dict()}
|
||||||
data={
|
|
||||||
**reauth_entry.data,
|
|
||||||
CONF_USER_DATA: user_data.as_dict(),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
self._abort_if_unique_id_configured(error="already_configured_account")
|
self._abort_if_unique_id_configured(error="already_configured_account")
|
||||||
return self._create_entry(self._client, self._username, user_data)
|
return self._create_entry(self._client, self._username, user_data)
|
||||||
|
|
||||||
@ -202,7 +197,7 @@ class RoborockFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
return RoborockOptionsFlowHandler(config_entry)
|
return RoborockOptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
|
|
||||||
class RoborockOptionsFlowHandler(OptionsFlow):
|
class RoborockOptionsFlowHandler(OptionsFlowWithReload):
|
||||||
"""Handle an option flow for Roborock."""
|
"""Handle an option flow for Roborock."""
|
||||||
|
|
||||||
def __init__(self, config_entry: RoborockConfigEntry) -> None:
|
def __init__(self, config_entry: RoborockConfigEntry) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user