Use new reauth helpers in philips_js (#128714)

This commit is contained in:
epenet 2024-10-19 10:15:59 +02:00 committed by GitHub
parent dd8f1800df
commit 0c04373b79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,7 +9,12 @@ from typing import Any
from haphilipsjs import ConnectionFailure, PairingFailure, PhilipsTV
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 (
CONF_API_VERSION,
CONF_HOST,
@ -75,18 +80,13 @@ class PhilipsJSConfigFlow(ConfigFlow, domain=DOMAIN):
self._current: dict[str, Any] = {}
self._hub: PhilipsTV | None = None
self._pair_state: Any = None
self._entry: ConfigEntry | None = None
async def _async_create_current(self) -> ConfigFlowResult:
system = self._current[CONF_SYSTEM]
if self._entry:
self.hass.config_entries.async_update_entry(
self._entry, data=self._entry.data | self._current
if self.source == SOURCE_REAUTH:
return self.async_update_reload_and_abort(
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(
title=f"{system['name']} ({system['serialnumber']})",
@ -150,7 +150,6 @@ class PhilipsJSConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""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_API_VERSION] = entry_data[CONF_API_VERSION]
return await self.async_step_user()
@ -175,7 +174,7 @@ class PhilipsJSConfigFlow(ConfigFlow, domain=DOMAIN):
else:
if serialnumber := hub.system.get("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._current[CONF_SYSTEM] = hub.system