diff --git a/homeassistant/components/solarlog/config_flow.py b/homeassistant/components/solarlog/config_flow.py index deda2d81779..9f6397bb62e 100644 --- a/homeassistant/components/solarlog/config_flow.py +++ b/homeassistant/components/solarlog/config_flow.py @@ -1,7 +1,7 @@ """Config flow for solarlog integration.""" import logging -from typing import Any +from typing import TYPE_CHECKING, Any from urllib.parse import ParseResult, urlparse from solarlog_cli.solarlog_connector import SolarLogConnector @@ -117,3 +117,31 @@ class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN): return self.async_abort(reason="already_configured") return await self.async_step_user(user_input) + + async def async_step_reconfigure( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Handle a reconfiguration flow initialized by the user.""" + + entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) + + if TYPE_CHECKING: + assert entry is not None + + if user_input is not None: + return self.async_update_reload_and_abort( + entry, + reason="reconfigure_successful", + data={**entry.data, **user_input}, + ) + + return self.async_show_form( + step_id="reconfigure", + data_schema=vol.Schema( + { + vol.Required( + "extended_data", default=entry.data["extended_data"] + ): bool, + } + ), + ) diff --git a/homeassistant/components/solarlog/strings.json b/homeassistant/components/solarlog/strings.json index 255f35114c1..caa14ac01a6 100644 --- a/homeassistant/components/solarlog/strings.json +++ b/homeassistant/components/solarlog/strings.json @@ -11,6 +11,12 @@ "data_description": { "host": "The hostname or IP address of your Solar-Log device." } + }, + "reconfigure": { + "title": "Configure SolarLog", + "data": { + "extended_data": "[%key:component::solarlog::config::step::user::data::extended_data%]" + } } }, "error": { @@ -19,7 +25,8 @@ "unknown": "[%key:common::config_flow::error::unknown%]" }, "abort": { - "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" + "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", + "reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]" } }, "entity": { diff --git a/tests/components/solarlog/test_config_flow.py b/tests/components/solarlog/test_config_flow.py index cb1092a73e3..34da13cdf8f 100644 --- a/tests/components/solarlog/test_config_flow.py +++ b/tests/components/solarlog/test_config_flow.py @@ -188,3 +188,37 @@ async def test_abort_if_already_setup(hass: HomeAssistant, test_connect) -> None assert result["type"] is FlowResultType.CREATE_ENTRY assert result["title"] == "solarlog_test_1_2_3" assert result["data"][CONF_HOST] == "http://2.2.2.2" + + +async def test_reconfigure_flow( + hass: HomeAssistant, mock_setup_entry: AsyncMock +) -> None: + """Test config flow options.""" + entry = MockConfigEntry( + domain=DOMAIN, + title="solarlog_test_1_2_3", + data={ + CONF_HOST: HOST, + "extended_data": False, + }, + ) + entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={ + "source": config_entries.SOURCE_RECONFIGURE, + "entry_id": entry.entry_id, + }, + ) + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "reconfigure" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], {"extended_data": True} + ) + await hass.async_block_till_done() + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "reconfigure_successful" + assert len(mock_setup_entry.mock_calls) == 1