Use hostname as config entry title in SABnzbd (#131604)

This commit is contained in:
Jan-Philipp Benecke 2024-11-26 09:43:39 +01:00 committed by GitHub
parent 60e1fb5d4f
commit 725d49ca9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import logging
from typing import Any
import voluptuous as vol
import yarl
from homeassistant.config_entries import (
SOURCE_RECONFIGURE,
@ -18,6 +19,7 @@ from homeassistant.helpers.selector import (
TextSelectorConfig,
TextSelectorType,
)
from homeassistant.util import slugify
from .const import DOMAIN
from .helpers import get_client
@ -67,8 +69,9 @@ class SABnzbdConfigFlow(ConfigFlow, domain=DOMAIN):
self._get_reconfigure_entry(), data_updates=user_input
)
parsed_url = yarl.URL(user_input[CONF_URL])
return self.async_create_entry(
title=user_input[CONF_API_KEY][:12], data=user_input
title=slugify(parsed_url.host), data=user_input
)
return self.async_show_form(

View File

@ -37,7 +37,7 @@ async def test_create_entry(hass: HomeAssistant, mock_setup_entry: AsyncMock) ->
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "edc3eee7330e"
assert result["title"] == "localhost"
assert result["data"] == {
CONF_API_KEY: "edc3eee7330e4fdda04489e3fbc283d0",
CONF_URL: "http://localhost:8080",
@ -68,7 +68,7 @@ async def test_auth_error(hass: HomeAssistant, sabnzbd: AsyncMock) -> None:
assert "errors" not in result
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "edc3eee7330e"
assert result["title"] == "localhost"
assert result["data"] == {
CONF_API_KEY: "edc3eee7330e4fdda04489e3fbc283d0",
CONF_URL: "http://localhost:8080",