mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add reconfigure flow for Jewish Calendar (#126773)
* Add reconfigure flow for Jewish Calendar * Use async_update_reload_and_abort
This commit is contained in:
parent
f516e538a8
commit
52c358e120
@ -3,7 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
import zoneinfo
|
import zoneinfo
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -87,6 +87,7 @@ class JewishCalendarConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle a config flow for Jewish calendar."""
|
"""Handle a config flow for Jewish calendar."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
_config_entry: ConfigEntry
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
@ -128,6 +129,35 @@ class JewishCalendarConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Import a config entry from configuration.yaml."""
|
"""Import a config entry from configuration.yaml."""
|
||||||
return await self.async_step_user(import_data)
|
return await self.async_step_user(import_data)
|
||||||
|
|
||||||
|
async def async_step_reconfigure(
|
||||||
|
self, _: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle a reconfiguration flow initialized by the user."""
|
||||||
|
config_entry = self.hass.config_entries.async_get_entry(
|
||||||
|
self.context["entry_id"]
|
||||||
|
)
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert config_entry is not None
|
||||||
|
self._config_entry = config_entry
|
||||||
|
return await self.async_step_reconfigure_confirm()
|
||||||
|
|
||||||
|
async def async_step_reconfigure_confirm(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle a reconfiguration flow initialized by the user."""
|
||||||
|
if not user_input:
|
||||||
|
return self.async_show_form(
|
||||||
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
|
_get_data_schema(self.hass),
|
||||||
|
{**self._config_entry.data},
|
||||||
|
),
|
||||||
|
step_id="reconfigure_confirm",
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.async_update_reload_and_abort(
|
||||||
|
self._config_entry, data=user_input, reason="reconfigure_successful"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class JewishCalendarOptionsFlowHandler(OptionsFlowWithConfigEntry):
|
class JewishCalendarOptionsFlowHandler(OptionsFlowWithConfigEntry):
|
||||||
"""Handle Jewish Calendar options."""
|
"""Handle Jewish Calendar options."""
|
||||||
|
@ -14,7 +14,7 @@ from homeassistant.components.jewish_calendar.const import (
|
|||||||
DEFAULT_LANGUAGE,
|
DEFAULT_LANGUAGE,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_RECONFIGURE, SOURCE_USER
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ELEVATION,
|
CONF_ELEVATION,
|
||||||
CONF_LANGUAGE,
|
CONF_LANGUAGE,
|
||||||
@ -164,3 +164,35 @@ async def test_options_reconfigure(
|
|||||||
assert (
|
assert (
|
||||||
mock_config_entry.options[CONF_CANDLE_LIGHT_MINUTES] == DEFAULT_CANDLE_LIGHT + 1
|
mock_config_entry.options[CONF_CANDLE_LIGHT_MINUTES] == DEFAULT_CANDLE_LIGHT + 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_reconfigure(
|
||||||
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
|
"""Test starting a reconfigure flow."""
|
||||||
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# init user flow
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={
|
||||||
|
"source": SOURCE_RECONFIGURE,
|
||||||
|
"entry_id": mock_config_entry.entry_id,
|
||||||
|
},
|
||||||
|
data=mock_config_entry.data,
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "reconfigure_confirm"
|
||||||
|
|
||||||
|
# success
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input={
|
||||||
|
CONF_DIASPORA: not DEFAULT_DIASPORA,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "reconfigure_successful"
|
||||||
|
assert mock_config_entry.data[CONF_DIASPORA] is not DEFAULT_DIASPORA
|
||||||
|
Loading…
x
Reference in New Issue
Block a user