mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 02:24:51 -05:00
Remove name field from NZBGet config flow (#176995)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
]
|
||||
|
||||
|
||||
@@ -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%]",
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user