Fix bug in AirVisual re-auth (#59685)
parent
1bd2d3c69e
commit
ce3f918c2c
|
@ -135,6 +135,9 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
existing_entry = await self.async_set_unique_id(self._geo_id)
|
||||
if existing_entry:
|
||||
self.hass.config_entries.async_update_entry(existing_entry, data=user_input)
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_reload(existing_entry.entry_id)
|
||||
)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
|
||||
return self.async_create_entry(
|
||||
|
@ -231,7 +234,7 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="reauth_confirm", data_schema=API_KEY_DATA_SCHEMA
|
||||
)
|
||||
|
||||
conf = {CONF_API_KEY: user_input[CONF_API_KEY], **self._entry_data_for_reauth}
|
||||
conf = {**self._entry_data_for_reauth, CONF_API_KEY: user_input[CONF_API_KEY]}
|
||||
|
||||
return await self._async_finish_geography(
|
||||
conf, self._entry_data_for_reauth[CONF_INTEGRATION_TYPE]
|
||||
|
|
|
@ -355,16 +355,19 @@ async def test_step_reauth(hass):
|
|||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
new_api_key = "defgh67890"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.airvisual.async_setup_entry", return_value=True
|
||||
), patch("pyairvisual.air_quality.AirQuality.nearest_city", return_value=True):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={CONF_API_KEY: "defgh67890"}
|
||||
result["flow_id"], user_input={CONF_API_KEY: new_api_key}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
|
||||
assert len(hass.config_entries.async_entries()) == 1
|
||||
assert hass.config_entries.async_entries()[0].data[CONF_API_KEY] == new_api_key
|
||||
|
||||
|
||||
async def test_step_user(hass):
|
||||
|
|
Loading…
Reference in New Issue