1212from custom_components import smaev
1313from custom_components .smaev .config_flow import SmaEvChargerConfigFlow , validate_input
1414
15- from .conftest import CONFIG_DATA , DEVICE_INFO , MockSmaEvCharger
15+ from .conftest import CONFIG_DATA , MockConfigEntry , MockSmaEvCharger
1616
1717
1818async def test_show_form (hass : HomeAssistant ) -> None :
@@ -76,53 +76,58 @@ async def test_step_user_error(hass, error, errors):
7676 assert result ["errors" ] == errors
7777
7878
79- # @patch.object(pysmaev.core, "SmaEvCharger", MockSmaEvCharger)
80- # async def test_options_flow(hass, entry):
81- # """Test config flow options."""
82- # entry.add_to_hass(hass)
83- # result = await hass.config_entries.options.async_init(entry.entry_id)
84-
85- # assert result["type"] == data_entry_flow.FlowResultType.FORM
86- # assert result["step_id"] == "init"
87-
88- # user_input = CONFIG_DATA.copy()
79+ @patch .object (pysmaev .core , "SmaEvCharger" , MockSmaEvCharger )
80+ async def test_step_reconfigure (hass : HomeAssistant , entry : MockSmaEvCharger ):
81+ """Test for reconfigure step."""
82+ entry .add_to_hass (hass )
83+ old_entry_data = entry .data .copy ()
8984
90- # result = await hass.config_entries.options.async_configure(
91- # result["flow_id"], user_input=user_input
92- # )
85+ result = await entry . start_reconfigure_flow ( hass )
86+ assert result ["type" ] == data_entry_flow . FlowResultType . FORM
87+ assert result [ "step_id" ] == "reconfigure"
9388
94- # assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
95- # assert all(value == entry.data[key] for key, value in user_input.items())
89+ result = await hass .config_entries .flow .async_configure (
90+ result ["flow_id" ], user_input = CONFIG_DATA .copy ()
91+ )
92+ assert result ["type" ] == data_entry_flow .FlowResultType .ABORT
93+ assert result ["reason" ] == "reconfigure_successful"
9694
95+ entry = hass .config_entries .async_get_entry (entry .entry_id )
96+ assert entry .data == {** old_entry_data , ** CONFIG_DATA }
9797
98- # @pytest.mark.parametrize(
99- # ("error", "errors"),
100- # [
101- # (pysmaev.exceptions.SmaEvChargerConnectionError, {CONF_BASE: "cannot_connect"}),
102- # (
103- # pysmaev.exceptions.SmaEvChargerAuthenticationError,
104- # {CONF_BASE: "invalid_auth"},
105- # ),
106- # (Exception, {CONF_BASE: "unknown"}),
107- # ],
108- # )
109- # async def test_options_flow_errors(hass, entry, error, errors):
110- # """Test config flow options."""
111- # entry.add_to_hass(hass)
112- # result = await hass.config_entries.options.async_init(entry.entry_id)
11398
114- # assert result["type"] == data_entry_flow.FlowResultType.FORM
115- # assert result["step_id"] == "init"
99+ @pytest .mark .parametrize (
100+ ("error" , "errors" ),
101+ [
102+ (pysmaev .exceptions .SmaEvChargerConnectionError , {CONF_BASE : "cannot_connect" }),
103+ (
104+ pysmaev .exceptions .SmaEvChargerAuthenticationError ,
105+ {CONF_BASE : "invalid_auth" },
106+ ),
107+ (Exception , {CONF_BASE : "unknown" }),
108+ ],
109+ )
110+ async def test_step_reconfigure_error (
111+ hass : HomeAssistant ,
112+ entry : MockConfigEntry ,
113+ error : type [Exception ],
114+ errors : dict [str , str ],
115+ ) -> None :
116+ """Test for error in reconfigure step is handled correctly."""
117+ entry .add_to_hass (hass )
116118
117- # user_input = CONFIG_DATA.copy()
119+ result = await entry .start_reconfigure_flow (hass )
120+ assert result ["type" ] == data_entry_flow .FlowResultType .FORM
121+ assert result ["step_id" ] == "reconfigure"
118122
119- # with patch("pysmaev.core.SmaEvCharger.open", side_effect=error):
120- # result = await hass.config_entries.options.async_configure(
121- # result["flow_id"], user_input=user_input
122- # )
123+ with patch ("pysmaev.core.SmaEvCharger.open" , side_effect = error ):
124+ result = await hass .config_entries .flow .async_configure (
125+ result ["flow_id" ],
126+ CONFIG_DATA .copy (),
127+ )
123128
124- # assert result["type"] == data_entry_flow.FlowResultType.FORM
125- # assert result["errors"] == errors
129+ assert result ["type" ] == data_entry_flow .FlowResultType .FORM
130+ assert result ["errors" ] == errors
126131
127132
128133async def test_validate_connection (hass : HomeAssistant ):
@@ -134,7 +139,7 @@ async def test_validate_connection(hass: HomeAssistant):
134139
135140 assert mock .open .is_called
136141 assert mock .device_info .is_called
137- assert result == ( DEVICE_INFO , {})
142+ assert result == {}
138143
139144
140145@pytest .mark .parametrize (
@@ -155,4 +160,4 @@ async def test_validate_connection_raises_error(hass: HomeAssistant, error, erro
155160 with patch ("pysmaev.core.SmaEvCharger.open" , side_effect = error ):
156161 result = await validate_input (hass , data = data )
157162
158- assert result == ({}, errors )
163+ assert result == errors
0 commit comments