mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Remove name from Transmission config flow (#102216)
* Remove name key from Transmission * Remove name variable completely * remove name error from strings * Change entry title to default name
This commit is contained in:
parent
54ba376b4b
commit
a2bc2bf8a0
@ -108,6 +108,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
entity_entry: er.RegistryEntry,
|
||||
) -> dict[str, Any] | None:
|
||||
"""Update unique ID of entity entry."""
|
||||
if CONF_NAME not in config_entry.data:
|
||||
return None
|
||||
match = re.search(
|
||||
f"{config_entry.data[CONF_HOST]}-{config_entry.data[CONF_NAME]} (?P<name>.+)",
|
||||
entity_entry.unique_id,
|
||||
|
@ -9,7 +9,6 @@ import voluptuous as vol
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_SCAN_INTERVAL,
|
||||
@ -34,7 +33,6 @@ from .errors import AuthenticationError, CannotConnect, UnknownError
|
||||
|
||||
DATA_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_NAME, default=DEFAULT_NAME): str,
|
||||
vol.Required(CONF_HOST): str,
|
||||
vol.Optional(CONF_USERNAME): str,
|
||||
vol.Optional(CONF_PASSWORD): str,
|
||||
@ -70,9 +68,6 @@ class TransmissionFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
and entry.data[CONF_PORT] == user_input[CONF_PORT]
|
||||
):
|
||||
return self.async_abort(reason="already_configured")
|
||||
if entry.data[CONF_NAME] == user_input[CONF_NAME]:
|
||||
errors[CONF_NAME] = "name_exists"
|
||||
break
|
||||
try:
|
||||
await get_api(self.hass, user_input)
|
||||
|
||||
@ -84,7 +79,8 @@ class TransmissionFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
if not errors:
|
||||
return self.async_create_entry(
|
||||
title=user_input[CONF_NAME], data=user_input
|
||||
title=DEFAULT_NAME,
|
||||
data=user_input,
|
||||
)
|
||||
|
||||
return self.async_show_form(
|
||||
|
@ -8,7 +8,7 @@ from transmission_rpc.torrent import Torrent
|
||||
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, STATE_IDLE, UnitOfDataRate
|
||||
from homeassistant.const import STATE_IDLE, UnitOfDataRate
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@ -35,54 +35,45 @@ async def async_setup_entry(
|
||||
coordinator: TransmissionDataUpdateCoordinator = hass.data[DOMAIN][
|
||||
config_entry.entry_id
|
||||
]
|
||||
name: str = config_entry.data[CONF_NAME]
|
||||
|
||||
dev = [
|
||||
TransmissionSpeedSensor(
|
||||
coordinator,
|
||||
name,
|
||||
"download_speed",
|
||||
"download",
|
||||
),
|
||||
TransmissionSpeedSensor(
|
||||
coordinator,
|
||||
name,
|
||||
"upload_speed",
|
||||
"upload",
|
||||
),
|
||||
TransmissionStatusSensor(
|
||||
coordinator,
|
||||
name,
|
||||
"transmission_status",
|
||||
"status",
|
||||
),
|
||||
TransmissionTorrentsSensor(
|
||||
coordinator,
|
||||
name,
|
||||
"active_torrents",
|
||||
"active_torrents",
|
||||
),
|
||||
TransmissionTorrentsSensor(
|
||||
coordinator,
|
||||
name,
|
||||
"paused_torrents",
|
||||
"paused_torrents",
|
||||
),
|
||||
TransmissionTorrentsSensor(
|
||||
coordinator,
|
||||
name,
|
||||
"total_torrents",
|
||||
"total_torrents",
|
||||
),
|
||||
TransmissionTorrentsSensor(
|
||||
coordinator,
|
||||
name,
|
||||
"completed_torrents",
|
||||
"completed_torrents",
|
||||
),
|
||||
TransmissionTorrentsSensor(
|
||||
coordinator,
|
||||
name,
|
||||
"started_torrents",
|
||||
"started_torrents",
|
||||
),
|
||||
@ -102,7 +93,6 @@ class TransmissionSensor(
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: TransmissionDataUpdateCoordinator,
|
||||
client_name: str,
|
||||
sensor_translation_key: str,
|
||||
key: str,
|
||||
) -> None:
|
||||
@ -115,7 +105,6 @@ class TransmissionSensor(
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
|
||||
manufacturer="Transmission",
|
||||
name=client_name,
|
||||
)
|
||||
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
"user": {
|
||||
"title": "Set up Transmission Client",
|
||||
"data": {
|
||||
"name": "[%key:common::config_flow::data::name%]",
|
||||
"host": "[%key:common::config_flow::data::host%]",
|
||||
"username": "[%key:common::config_flow::data::username%]",
|
||||
"password": "[%key:common::config_flow::data::password%]",
|
||||
@ -20,7 +19,6 @@
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"name_exists": "Name already exists",
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
},
|
||||
|
@ -5,7 +5,6 @@ from typing import Any
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@ -27,11 +26,10 @@ async def async_setup_entry(
|
||||
coordinator: TransmissionDataUpdateCoordinator = hass.data[DOMAIN][
|
||||
config_entry.entry_id
|
||||
]
|
||||
name: str = config_entry.data[CONF_NAME]
|
||||
|
||||
dev = []
|
||||
for switch_type, switch_name in SWITCH_TYPES.items():
|
||||
dev.append(TransmissionSwitch(switch_type, switch_name, coordinator, name))
|
||||
dev.append(TransmissionSwitch(switch_type, switch_name, coordinator))
|
||||
|
||||
async_add_entities(dev, True)
|
||||
|
||||
@ -49,7 +47,6 @@ class TransmissionSwitch(
|
||||
switch_type: str,
|
||||
switch_name: str,
|
||||
coordinator: TransmissionDataUpdateCoordinator,
|
||||
client_name: str,
|
||||
) -> None:
|
||||
"""Initialize the Transmission switch."""
|
||||
super().__init__(coordinator)
|
||||
@ -61,7 +58,6 @@ class TransmissionSwitch(
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
|
||||
manufacturer="Transmission",
|
||||
name=client_name,
|
||||
)
|
||||
|
||||
@property
|
||||
|
@ -1,9 +1,15 @@
|
||||
"""Tests for Transmission."""
|
||||
|
||||
MOCK_CONFIG_DATA = {
|
||||
OLD_MOCK_CONFIG_DATA = {
|
||||
"name": "Transmission",
|
||||
"host": "0.0.0.0",
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
"port": 9091,
|
||||
}
|
||||
MOCK_CONFIG_DATA = {
|
||||
"host": "0.0.0.0",
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
"port": 9091,
|
||||
}
|
||||
|
@ -71,27 +71,6 @@ async def test_device_already_configured(
|
||||
assert result2["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_name_already_configured(hass: HomeAssistant) -> None:
|
||||
"""Test name is already configured."""
|
||||
entry = MockConfigEntry(
|
||||
domain=transmission.DOMAIN,
|
||||
data=MOCK_CONFIG_DATA,
|
||||
options={"scan_interval": 120},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
mock_entry = MOCK_CONFIG_DATA.copy()
|
||||
mock_entry["host"] = "1.1.1.1"
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
transmission.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data=mock_entry,
|
||||
)
|
||||
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["errors"] == {"name": "name_exists"}
|
||||
|
||||
|
||||
async def test_options(hass: HomeAssistant) -> None:
|
||||
"""Test updating options."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -16,7 +16,7 @@ from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import MOCK_CONFIG_DATA
|
||||
from . import MOCK_CONFIG_DATA, OLD_MOCK_CONFIG_DATA
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@ -139,7 +139,7 @@ async def test_migrate_unique_id(
|
||||
new_unique_id: str,
|
||||
) -> None:
|
||||
"""Test unique id migration."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_DATA, entry_id="1234")
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=OLD_MOCK_CONFIG_DATA, entry_id="1234")
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
entity: er.RegistryEntry = entity_registry.async_get_or_create(
|
||||
|
Loading…
x
Reference in New Issue
Block a user