Use reauth helpers in intellifire (#128646)
This commit is contained in:
parent
e0a14cdeea
commit
bf9b35d670
1 changed files with 5 additions and 18 deletions
|
@ -14,7 +14,7 @@ from intellifire4py.model import IntelliFireCommonFireplaceData
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.dhcp import DhcpServiceInfo
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_HOST,
|
||||
|
@ -79,7 +79,6 @@ class IntelliFireConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self._dhcp_discovered_serial: str = "" # used only in discovery mode
|
||||
self._discovered_host: DiscoveredHostInfo
|
||||
self._dhcp_mode = False
|
||||
self._is_reauth = False
|
||||
|
||||
self._not_configured_hosts: list[DiscoveredHostInfo] = []
|
||||
self._reauth_needed: DiscoveredHostInfo
|
||||
|
@ -182,14 +181,6 @@ class IntelliFireConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
# If there is a single fireplace configure it
|
||||
if len(available_fireplaces) == 1:
|
||||
if self._is_reauth:
|
||||
reauth_entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
return await self._async_create_config_entry_from_common_data(
|
||||
fireplace=available_fireplaces[0], existing_entry=reauth_entry
|
||||
)
|
||||
|
||||
return await self._async_create_config_entry_from_common_data(
|
||||
fireplace=available_fireplaces[0]
|
||||
)
|
||||
|
@ -207,9 +198,7 @@ class IntelliFireConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
)
|
||||
|
||||
async def _async_create_config_entry_from_common_data(
|
||||
self,
|
||||
fireplace: IntelliFireCommonFireplaceData,
|
||||
existing_entry: ConfigEntry | None = None,
|
||||
self, fireplace: IntelliFireCommonFireplaceData
|
||||
) -> ConfigFlowResult:
|
||||
"""Construct a config entry based on an object of IntelliFireCommonFireplaceData."""
|
||||
|
||||
|
@ -226,9 +215,9 @@ class IntelliFireConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
options = {CONF_READ_MODE: API_MODE_LOCAL, CONF_CONTROL_MODE: API_MODE_LOCAL}
|
||||
|
||||
if existing_entry:
|
||||
if self.source == SOURCE_REAUTH:
|
||||
return self.async_update_reload_and_abort(
|
||||
existing_entry, data=data, options=options
|
||||
self._get_reauth_entry(), data=data, options=options
|
||||
)
|
||||
return self.async_create_entry(
|
||||
title=f"Fireplace {fireplace.serial}", data=data, options=options
|
||||
|
@ -239,11 +228,9 @@ class IntelliFireConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
) -> ConfigFlowResult:
|
||||
"""Perform reauth upon an API authentication error."""
|
||||
LOGGER.debug("STEP: reauth")
|
||||
self._is_reauth = True
|
||||
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
||||
|
||||
# populate the expected vars
|
||||
self._dhcp_discovered_serial = entry.data[CONF_SERIAL] # type: ignore[union-attr]
|
||||
self._dhcp_discovered_serial = self._get_reauth_entry().data[CONF_SERIAL]
|
||||
|
||||
placeholders = {"serial": self._dhcp_discovered_serial}
|
||||
self.context["title_placeholders"] = placeholders
|
||||
|
|
Loading…
Add table
Reference in a new issue