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
8 changed files with 15 additions and 49 deletions
|
@ -108,6 +108,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||||
entity_entry: er.RegistryEntry,
|
entity_entry: er.RegistryEntry,
|
||||||
) -> dict[str, Any] | None:
|
) -> dict[str, Any] | None:
|
||||||
"""Update unique ID of entity entry."""
|
"""Update unique ID of entity entry."""
|
||||||
|
if CONF_NAME not in config_entry.data:
|
||||||
|
return None
|
||||||
match = re.search(
|
match = re.search(
|
||||||
f"{config_entry.data[CONF_HOST]}-{config_entry.data[CONF_NAME]} (?P<name>.+)",
|
f"{config_entry.data[CONF_HOST]}-{config_entry.data[CONF_NAME]} (?P<name>.+)",
|
||||||
entity_entry.unique_id,
|
entity_entry.unique_id,
|
||||||
|
|
|
@ -9,7 +9,6 @@ import voluptuous as vol
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_NAME,
|
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
|
@ -34,7 +33,6 @@ from .errors import AuthenticationError, CannotConnect, UnknownError
|
||||||
|
|
||||||
DATA_SCHEMA = vol.Schema(
|
DATA_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_NAME, default=DEFAULT_NAME): str,
|
|
||||||
vol.Required(CONF_HOST): str,
|
vol.Required(CONF_HOST): str,
|
||||||
vol.Optional(CONF_USERNAME): str,
|
vol.Optional(CONF_USERNAME): str,
|
||||||
vol.Optional(CONF_PASSWORD): 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]
|
and entry.data[CONF_PORT] == user_input[CONF_PORT]
|
||||||
):
|
):
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
if entry.data[CONF_NAME] == user_input[CONF_NAME]:
|
|
||||||
errors[CONF_NAME] = "name_exists"
|
|
||||||
break
|
|
||||||
try:
|
try:
|
||||||
await get_api(self.hass, user_input)
|
await get_api(self.hass, user_input)
|
||||||
|
|
||||||
|
@ -84,7 +79,8 @@ class TransmissionFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input[CONF_NAME], data=user_input
|
title=DEFAULT_NAME,
|
||||||
|
data=user_input,
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
|
|
|
@ -8,7 +8,7 @@ from transmission_rpc.torrent import Torrent
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
@ -35,54 +35,45 @@ async def async_setup_entry(
|
||||||
coordinator: TransmissionDataUpdateCoordinator = hass.data[DOMAIN][
|
coordinator: TransmissionDataUpdateCoordinator = hass.data[DOMAIN][
|
||||||
config_entry.entry_id
|
config_entry.entry_id
|
||||||
]
|
]
|
||||||
name: str = config_entry.data[CONF_NAME]
|
|
||||||
|
|
||||||
dev = [
|
dev = [
|
||||||
TransmissionSpeedSensor(
|
TransmissionSpeedSensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
name,
|
|
||||||
"download_speed",
|
"download_speed",
|
||||||
"download",
|
"download",
|
||||||
),
|
),
|
||||||
TransmissionSpeedSensor(
|
TransmissionSpeedSensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
name,
|
|
||||||
"upload_speed",
|
"upload_speed",
|
||||||
"upload",
|
"upload",
|
||||||
),
|
),
|
||||||
TransmissionStatusSensor(
|
TransmissionStatusSensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
name,
|
|
||||||
"transmission_status",
|
"transmission_status",
|
||||||
"status",
|
"status",
|
||||||
),
|
),
|
||||||
TransmissionTorrentsSensor(
|
TransmissionTorrentsSensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
name,
|
|
||||||
"active_torrents",
|
"active_torrents",
|
||||||
"active_torrents",
|
"active_torrents",
|
||||||
),
|
),
|
||||||
TransmissionTorrentsSensor(
|
TransmissionTorrentsSensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
name,
|
|
||||||
"paused_torrents",
|
"paused_torrents",
|
||||||
"paused_torrents",
|
"paused_torrents",
|
||||||
),
|
),
|
||||||
TransmissionTorrentsSensor(
|
TransmissionTorrentsSensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
name,
|
|
||||||
"total_torrents",
|
"total_torrents",
|
||||||
"total_torrents",
|
"total_torrents",
|
||||||
),
|
),
|
||||||
TransmissionTorrentsSensor(
|
TransmissionTorrentsSensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
name,
|
|
||||||
"completed_torrents",
|
"completed_torrents",
|
||||||
"completed_torrents",
|
"completed_torrents",
|
||||||
),
|
),
|
||||||
TransmissionTorrentsSensor(
|
TransmissionTorrentsSensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
name,
|
|
||||||
"started_torrents",
|
"started_torrents",
|
||||||
"started_torrents",
|
"started_torrents",
|
||||||
),
|
),
|
||||||
|
@ -102,7 +93,6 @@ class TransmissionSensor(
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: TransmissionDataUpdateCoordinator,
|
coordinator: TransmissionDataUpdateCoordinator,
|
||||||
client_name: str,
|
|
||||||
sensor_translation_key: str,
|
sensor_translation_key: str,
|
||||||
key: str,
|
key: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -115,7 +105,6 @@ class TransmissionSensor(
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
|
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
|
||||||
manufacturer="Transmission",
|
manufacturer="Transmission",
|
||||||
name=client_name,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
"user": {
|
"user": {
|
||||||
"title": "Set up Transmission Client",
|
"title": "Set up Transmission Client",
|
||||||
"data": {
|
"data": {
|
||||||
"name": "[%key:common::config_flow::data::name%]",
|
|
||||||
"host": "[%key:common::config_flow::data::host%]",
|
"host": "[%key:common::config_flow::data::host%]",
|
||||||
"username": "[%key:common::config_flow::data::username%]",
|
"username": "[%key:common::config_flow::data::username%]",
|
||||||
"password": "[%key:common::config_flow::data::password%]",
|
"password": "[%key:common::config_flow::data::password%]",
|
||||||
|
@ -20,7 +19,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"name_exists": "Name already exists",
|
|
||||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
"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.components.switch import SwitchEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_NAME
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
@ -27,11 +26,10 @@ async def async_setup_entry(
|
||||||
coordinator: TransmissionDataUpdateCoordinator = hass.data[DOMAIN][
|
coordinator: TransmissionDataUpdateCoordinator = hass.data[DOMAIN][
|
||||||
config_entry.entry_id
|
config_entry.entry_id
|
||||||
]
|
]
|
||||||
name: str = config_entry.data[CONF_NAME]
|
|
||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
for switch_type, switch_name in SWITCH_TYPES.items():
|
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)
|
async_add_entities(dev, True)
|
||||||
|
|
||||||
|
@ -49,7 +47,6 @@ class TransmissionSwitch(
|
||||||
switch_type: str,
|
switch_type: str,
|
||||||
switch_name: str,
|
switch_name: str,
|
||||||
coordinator: TransmissionDataUpdateCoordinator,
|
coordinator: TransmissionDataUpdateCoordinator,
|
||||||
client_name: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the Transmission switch."""
|
"""Initialize the Transmission switch."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
@ -61,7 +58,6 @@ class TransmissionSwitch(
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
|
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
|
||||||
manufacturer="Transmission",
|
manufacturer="Transmission",
|
||||||
name=client_name,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
"""Tests for Transmission."""
|
"""Tests for Transmission."""
|
||||||
|
|
||||||
MOCK_CONFIG_DATA = {
|
OLD_MOCK_CONFIG_DATA = {
|
||||||
"name": "Transmission",
|
"name": "Transmission",
|
||||||
"host": "0.0.0.0",
|
"host": "0.0.0.0",
|
||||||
"username": "user",
|
"username": "user",
|
||||||
"password": "pass",
|
"password": "pass",
|
||||||
"port": 9091,
|
"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"
|
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:
|
async def test_options(hass: HomeAssistant) -> None:
|
||||||
"""Test updating options."""
|
"""Test updating options."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
|
|
|
@ -16,7 +16,7 @@ from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
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
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ async def test_migrate_unique_id(
|
||||||
new_unique_id: str,
|
new_unique_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id migration."""
|
"""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)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
entity: er.RegistryEntry = entity_registry.async_get_or_create(
|
entity: er.RegistryEntry = entity_registry.async_get_or_create(
|
||||||
|
|
Loading…
Add table
Reference in a new issue