mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Use new reauth helpers in philips_js (#128714)
This commit is contained in:
parent
dd8f1800df
commit
0c04373b79
@ -9,7 +9,12 @@ from typing import Any
|
|||||||
from haphilipsjs import ConnectionFailure, PairingFailure, PhilipsTV
|
from haphilipsjs import ConnectionFailure, PairingFailure, PhilipsTV
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_REAUTH,
|
||||||
|
ConfigEntry,
|
||||||
|
ConfigFlow,
|
||||||
|
ConfigFlowResult,
|
||||||
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_API_VERSION,
|
CONF_API_VERSION,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -75,18 +80,13 @@ class PhilipsJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self._current: dict[str, Any] = {}
|
self._current: dict[str, Any] = {}
|
||||||
self._hub: PhilipsTV | None = None
|
self._hub: PhilipsTV | None = None
|
||||||
self._pair_state: Any = None
|
self._pair_state: Any = None
|
||||||
self._entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
async def _async_create_current(self) -> ConfigFlowResult:
|
async def _async_create_current(self) -> ConfigFlowResult:
|
||||||
system = self._current[CONF_SYSTEM]
|
system = self._current[CONF_SYSTEM]
|
||||||
if self._entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self._entry, data=self._entry.data | self._current
|
self._get_reauth_entry(), data_updates=self._current
|
||||||
)
|
)
|
||||||
self.hass.async_create_task(
|
|
||||||
self.hass.config_entries.async_reload(self._entry.entry_id)
|
|
||||||
)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=f"{system['name']} ({system['serialnumber']})",
|
title=f"{system['name']} ({system['serialnumber']})",
|
||||||
@ -150,7 +150,6 @@ class PhilipsJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle configuration by re-auth."""
|
"""Handle configuration by re-auth."""
|
||||||
self._entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
|
||||||
self._current[CONF_HOST] = entry_data[CONF_HOST]
|
self._current[CONF_HOST] = entry_data[CONF_HOST]
|
||||||
self._current[CONF_API_VERSION] = entry_data[CONF_API_VERSION]
|
self._current[CONF_API_VERSION] = entry_data[CONF_API_VERSION]
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
@ -175,7 +174,7 @@ class PhilipsJSConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
else:
|
else:
|
||||||
if serialnumber := hub.system.get("serialnumber"):
|
if serialnumber := hub.system.get("serialnumber"):
|
||||||
await self.async_set_unique_id(serialnumber)
|
await self.async_set_unique_id(serialnumber)
|
||||||
if self._entry is None:
|
if self.source != SOURCE_REAUTH:
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
self._current[CONF_SYSTEM] = hub.system
|
self._current[CONF_SYSTEM] = hub.system
|
||||||
|
Loading…
x
Reference in New Issue
Block a user