Use new reauth helpers in pvpc_hourly_pricing (#128721)

pull/127262/head
epenet 2024-10-19 11:25:00 +02:00 committed by GitHub
parent f17c5bc334
commit 9622a11b2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 9 deletions

View File

@ -9,6 +9,7 @@ from aiopvpc import DEFAULT_POWER_KW, PVPCData
import voluptuous as vol import voluptuous as vol
from homeassistant.config_entries import ( from homeassistant.config_entries import (
SOURCE_REAUTH,
ConfigEntry, ConfigEntry,
ConfigFlow, ConfigFlow,
ConfigFlowResult, ConfigFlowResult,
@ -48,7 +49,6 @@ class TariffSelectorConfigFlow(ConfigFlow, domain=DOMAIN):
_use_api_token: bool = False _use_api_token: bool = False
_api_token: str | None = None _api_token: str | None = None
_api: PVPCData | None = None _api: PVPCData | None = None
_reauth_entry: ConfigEntry | None = None
@staticmethod @staticmethod
@callback @callback
@ -141,12 +141,10 @@ class TariffSelectorConfigFlow(ConfigFlow, domain=DOMAIN):
ATTR_POWER_P3: self._power_p3, ATTR_POWER_P3: self._power_p3,
CONF_API_TOKEN: self._api_token if self._use_api_token else None, CONF_API_TOKEN: self._api_token if self._use_api_token else None,
} }
if self._reauth_entry: if self.source == SOURCE_REAUTH:
self.hass.config_entries.async_update_entry(self._reauth_entry, data=data) return self.async_update_reload_and_abort(
self.hass.async_create_task( self._get_reauth_entry(), data=data
self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
) )
return self.async_abort(reason="reauth_successful")
assert self._name is not None assert self._name is not None
return self.async_create_entry(title=self._name, data=data) return self.async_create_entry(title=self._name, data=data)
@ -155,9 +153,6 @@ class TariffSelectorConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Handle re-authentication with ESIOS Token.""" """Handle re-authentication with ESIOS Token."""
self._reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
self._api_token = entry_data.get(CONF_API_TOKEN) self._api_token = entry_data.get(CONF_API_TOKEN)
self._use_api_token = self._api_token is not None self._use_api_token = self._api_token is not None
self._name = entry_data[CONF_NAME] self._name = entry_data[CONF_NAME]