From 8ec99c127572e9c1e2a507eecc8b7b52669048b7 Mon Sep 17 00:00:00 2001 From: Martin <32802427+mstu01@users.noreply.github.com> Date: Sun, 26 Jul 2026 22:33:28 +0200 Subject: [PATCH] Remove name field from NZBGet config flow (#176995) --- .../components/nzbget/config_flow.py | 5 --- homeassistant/components/nzbget/const.py | 1 - homeassistant/components/nzbget/sensor.py | 7 +++- homeassistant/components/nzbget/strings.json | 1 - homeassistant/components/nzbget/switch.py | 2 +- tests/components/nzbget/__init__.py | 1 - tests/components/nzbget/test_sensor.py | 37 +++++++++++++++++- tests/components/nzbget/test_switch.py | 39 ++++++++++++++++++- 8 files changed, 81 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/nzbget/config_flow.py b/homeassistant/components/nzbget/config_flow.py index 961e252f252d..39b0d5a0eaec 100644 --- a/homeassistant/components/nzbget/config_flow.py +++ b/homeassistant/components/nzbget/config_flow.py @@ -8,7 +8,6 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.const import ( CONF_HOST, - CONF_NAME, CONF_PASSWORD, CONF_PORT, CONF_SSL, @@ -19,7 +18,6 @@ from homeassistant.data_entry_flow import SectionConfig, section from .const import ( CONF_MORE_OPTIONS, - DEFAULT_NAME, DEFAULT_PORT, DEFAULT_SSL, DEFAULT_VERIFY_SSL, @@ -81,9 +79,6 @@ class NZBGetConfigFlow(ConfigFlow, domain=DOMAIN): data_schema = vol.Schema( { vol.Required(CONF_HOST): str, - # Name field is no longer allowed in config flow schemas - # pylint: disable-next=home-assistant-config-flow-name-field - vol.Optional(CONF_NAME, default=DEFAULT_NAME): str, vol.Optional(CONF_USERNAME): str, vol.Optional(CONF_PASSWORD): str, vol.Optional(CONF_PORT, default=DEFAULT_PORT): int, diff --git a/homeassistant/components/nzbget/const.py b/homeassistant/components/nzbget/const.py index 238ed437b93e..84a0dba2930a 100644 --- a/homeassistant/components/nzbget/const.py +++ b/homeassistant/components/nzbget/const.py @@ -7,7 +7,6 @@ ATTR_SPEED = "speed" # Defaults CONF_MORE_OPTIONS = "more_options" -DEFAULT_NAME = "NZBGet" DEFAULT_PORT = 6789 DEFAULT_SPEED_LIMIT = 1000 # 1 Megabyte/Sec DEFAULT_SSL = False diff --git a/homeassistant/components/nzbget/sensor.py b/homeassistant/components/nzbget/sensor.py index a083e9918f79..61d5f0426f18 100644 --- a/homeassistant/components/nzbget/sensor.py +++ b/homeassistant/components/nzbget/sensor.py @@ -95,7 +95,12 @@ async def async_setup_entry( """Set up NZBGet sensor based on a config entry.""" coordinator = entry.runtime_data entities = [ - NZBGetSensor(coordinator, entry.entry_id, entry.data[CONF_NAME], description) + NZBGetSensor( + coordinator, + entry.entry_id, + entry.data.get(CONF_NAME, entry.title), + description, + ) for description in SENSOR_TYPES ] diff --git a/homeassistant/components/nzbget/strings.json b/homeassistant/components/nzbget/strings.json index 76698efec222..94d04c9c2c38 100644 --- a/homeassistant/components/nzbget/strings.json +++ b/homeassistant/components/nzbget/strings.json @@ -11,7 +11,6 @@ "user": { "data": { "host": "[%key:common::config_flow::data::host%]", - "name": "[%key:common::config_flow::data::name%]", "password": "[%key:common::config_flow::data::password%]", "port": "[%key:common::config_flow::data::port%]", "ssl": "[%key:common::config_flow::data::ssl%]", diff --git a/homeassistant/components/nzbget/switch.py b/homeassistant/components/nzbget/switch.py index 909ff03c3f1c..b2e42fe5a5a8 100644 --- a/homeassistant/components/nzbget/switch.py +++ b/homeassistant/components/nzbget/switch.py @@ -23,7 +23,7 @@ async def async_setup_entry( NZBGetDownloadSwitch( coordinator, entry.entry_id, - entry.data[CONF_NAME], + entry.data.get(CONF_NAME, entry.title), ), ] diff --git a/tests/components/nzbget/__init__.py b/tests/components/nzbget/__init__.py index fe5bb01a99ec..2e4dd0dee1be 100644 --- a/tests/components/nzbget/__init__.py +++ b/tests/components/nzbget/__init__.py @@ -31,7 +31,6 @@ ENTRY_OPTIONS = {CONF_SCAN_INTERVAL: 5} USER_INPUT = { CONF_HOST: "10.10.10.30", - CONF_NAME: "NZBGet", CONF_PASSWORD: "", CONF_PORT: 6789, CONF_SSL: False, diff --git a/tests/components/nzbget/test_sensor.py b/tests/components/nzbget/test_sensor.py index 62ff0c1f59f0..ac5ee1fda3da 100644 --- a/tests/components/nzbget/test_sensor.py +++ b/tests/components/nzbget/test_sensor.py @@ -5,9 +5,16 @@ from unittest.mock import patch import pytest +from homeassistant.components.nzbget.const import DOMAIN from homeassistant.components.sensor import SensorDeviceClass from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, + CONF_HOST, + CONF_PASSWORD, + CONF_PORT, + CONF_SSL, + CONF_USERNAME, + CONF_VERIFY_SSL, UnitOfDataRate, UnitOfInformation, ) @@ -15,7 +22,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.util import dt as dt_util -from . import init_integration +from . import ENTRY_OPTIONS, init_integration + +from tests.common import MockConfigEntry @pytest.mark.usefixtures("nzbget_api") @@ -86,3 +95,29 @@ async def test_sensors(hass: HomeAssistant, entity_registry: er.EntityRegistry) assert state assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2] assert state.state == data[1] + + +@pytest.mark.usefixtures("nzbget_api") +async def test_sensor_name_from_entry_title(hass: HomeAssistant) -> None: + """Test sensors are named from the entry title when no legacy name is stored.""" + entry = MockConfigEntry( + domain=DOMAIN, + title="10.10.10.30", + data={ + CONF_HOST: "10.10.10.30", + CONF_PASSWORD: "", + CONF_PORT: 6789, + CONF_SSL: False, + CONF_USERNAME: "", + CONF_VERIFY_SSL: False, + }, + options=ENTRY_OPTIONS, + ) + entry.add_to_hass(hass) + + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + state = hass.states.get("sensor.10_10_10_30_speed") + assert state + assert state.name == "10.10.10.30 Speed" diff --git a/tests/components/nzbget/test_switch.py b/tests/components/nzbget/test_switch.py index afb88a7be826..ca88c4f91b28 100644 --- a/tests/components/nzbget/test_switch.py +++ b/tests/components/nzbget/test_switch.py @@ -2,9 +2,18 @@ from unittest.mock import MagicMock +import pytest + +from homeassistant.components.nzbget.const import DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, + CONF_HOST, + CONF_PASSWORD, + CONF_PORT, + CONF_SSL, + CONF_USERNAME, + CONF_VERIFY_SSL, SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_OFF, @@ -14,7 +23,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.helpers.entity_component import async_update_entity -from . import init_integration +from . import ENTRY_OPTIONS, init_integration + +from tests.common import MockConfigEntry async def test_download_switch( @@ -71,3 +82,29 @@ async def test_download_switch_services( blocking=True, ) instance.resumedownload.assert_called_once() + + +@pytest.mark.usefixtures("nzbget_api") +async def test_switch_name_from_entry_title(hass: HomeAssistant) -> None: + """Test the switch is named from the entry title when no legacy name is stored.""" + entry = MockConfigEntry( + domain=DOMAIN, + title="10.10.10.30", + data={ + CONF_HOST: "10.10.10.30", + CONF_PASSWORD: "", + CONF_PORT: 6789, + CONF_SSL: False, + CONF_USERNAME: "", + CONF_VERIFY_SSL: False, + }, + options=ENTRY_OPTIONS, + ) + entry.add_to_hass(hass) + + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + state = hass.states.get("switch.10_10_10_30_download") + assert state + assert state.name == "10.10.10.30 Download"