Use new reauth helpers in trafikverket_train (#128764)

This commit is contained in:
epenet 2024-10-19 14:33:10 +02:00 committed by GitHub
parent 46fa9e6b82
commit fe7328b92e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -126,8 +126,6 @@ class TVTrainConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
entry: ConfigEntry | None
@staticmethod @staticmethod
@callback @callback
def async_get_options_flow( def async_get_options_flow(
@ -140,8 +138,6 @@ class TVTrainConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Handle re-authentication with Trafikverket.""" """Handle re-authentication with Trafikverket."""
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
return await self.async_step_reauth_confirm() return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm( async def async_step_reauth_confirm(
@ -153,26 +149,21 @@ class TVTrainConfigFlow(ConfigFlow, domain=DOMAIN):
if user_input: if user_input:
api_key = user_input[CONF_API_KEY] api_key = user_input[CONF_API_KEY]
assert self.entry is not None reauth_entry = self._get_reauth_entry()
errors = await validate_input( errors = await validate_input(
self.hass, self.hass,
api_key, api_key,
self.entry.data[CONF_FROM], reauth_entry.data[CONF_FROM],
self.entry.data[CONF_TO], reauth_entry.data[CONF_TO],
self.entry.data.get(CONF_TIME), reauth_entry.data.get(CONF_TIME),
self.entry.data[CONF_WEEKDAY], reauth_entry.data[CONF_WEEKDAY],
self.entry.options.get(CONF_FILTER_PRODUCT), reauth_entry.options.get(CONF_FILTER_PRODUCT),
) )
if not errors: if not errors:
self.hass.config_entries.async_update_entry( return self.async_update_reload_and_abort(
self.entry, reauth_entry,
data={ data_updates={CONF_API_KEY: api_key},
**self.entry.data,
CONF_API_KEY: api_key,
},
) )
await self.hass.config_entries.async_reload(self.entry.entry_id)
return self.async_abort(reason="reauth_successful")
return self.async_show_form( return self.async_show_form(
step_id="reauth_confirm", step_id="reauth_confirm",