mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
Use unique_id in Plex config entries (#32489)
This commit is contained in:
parent
81f99efda1
commit
1615a5ee81
@ -116,6 +116,11 @@ async def async_setup_entry(hass, entry):
|
||||
"""Set up Plex from a config entry."""
|
||||
server_config = entry.data[PLEX_SERVER_CONFIG]
|
||||
|
||||
if entry.unique_id is None:
|
||||
hass.config_entries.async_update_entry(
|
||||
entry, unique_id=entry.data[CONF_SERVER_IDENTIFIER]
|
||||
)
|
||||
|
||||
if MP_DOMAIN not in entry.options:
|
||||
options = dict(entry.options)
|
||||
options.setdefault(
|
||||
|
@ -125,12 +125,8 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
server_id = plex_server.machine_identifier
|
||||
|
||||
for entry in self._async_current_entries():
|
||||
if entry.data[CONF_SERVER_IDENTIFIER] == server_id:
|
||||
_LOGGER.debug(
|
||||
"Plex server already configured: %s", entry.data[CONF_SERVER]
|
||||
)
|
||||
return self.async_abort(reason="already_configured")
|
||||
await self.async_set_unique_id(server_id)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
url = plex_server.url_in_use
|
||||
token = server_config.get(CONF_TOKEN)
|
||||
|
@ -383,8 +383,6 @@ async def test_already_configured(hass):
|
||||
|
||||
mock_plex_server = MockPlexServer()
|
||||
|
||||
flow = init_config_flow(hass)
|
||||
flow.context = {"source": "import"}
|
||||
MockConfigEntry(
|
||||
domain=config_flow.DOMAIN,
|
||||
data={
|
||||
@ -393,6 +391,7 @@ async def test_already_configured(hass):
|
||||
config_flow.CONF_SERVER_IDENTIFIER
|
||||
],
|
||||
},
|
||||
unique_id=MOCK_SERVERS[0][config_flow.CONF_SERVER_IDENTIFIER],
|
||||
).add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
@ -400,11 +399,13 @@ async def test_already_configured(hass):
|
||||
), asynctest.patch("plexauth.PlexAuth.initiate_auth"), asynctest.patch(
|
||||
"plexauth.PlexAuth.token", return_value=MOCK_TOKEN
|
||||
):
|
||||
result = await flow.async_step_import(
|
||||
{
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
context={"source": "import"},
|
||||
data={
|
||||
CONF_TOKEN: MOCK_TOKEN,
|
||||
CONF_URL: f"http://{MOCK_SERVERS[0][CONF_HOST]}:{MOCK_SERVERS[0][CONF_PORT]}",
|
||||
}
|
||||
},
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
Loading…
Reference in New Issue
Block a user