From bc665a1368f688bcf4acd35a1ecbd9a609d2e93d Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 26 Sep 2023 19:58:47 +0200 Subject: [PATCH] Remove setting name in AnthemAV config flow (#99148) --- homeassistant/components/anthemav/config_flow.py | 11 ++++------- homeassistant/components/anthemav/media_player.py | 4 ++-- tests/components/anthemav/conftest.py | 4 ++-- tests/components/anthemav/test_config_flow.py | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/anthemav/config_flow.py b/homeassistant/components/anthemav/config_flow.py index 23694654eb3..e75c67cb2c5 100644 --- a/homeassistant/components/anthemav/config_flow.py +++ b/homeassistant/components/anthemav/config_flow.py @@ -9,8 +9,8 @@ from anthemav.connection import Connection from anthemav.device_error import DeviceError import voluptuous as vol -from homeassistant import config_entries -from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_PORT +from homeassistant.config_entries import ConfigFlow +from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT from homeassistant.data_entry_flow import FlowResult import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import format_mac @@ -43,7 +43,7 @@ async def connect_device(user_input: dict[str, Any]) -> Connection: return avr -class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): +class AnthemAVConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for Anthem A/V Receivers.""" VERSION = 1 @@ -57,9 +57,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="user", data_schema=STEP_USER_DATA_SCHEMA ) - if CONF_NAME not in user_input: - user_input[CONF_NAME] = DEFAULT_NAME - errors = {} avr: Connection | None = None @@ -84,7 +81,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): user_input[CONF_MODEL] = avr.protocol.model await self.async_set_unique_id(user_input[CONF_MAC]) self._abort_if_unique_id_configured() - return self.async_create_entry(title=user_input[CONF_NAME], data=user_input) + return self.async_create_entry(title=DEFAULT_NAME, data=user_input) finally: if avr is not None: avr.close() diff --git a/homeassistant/components/anthemav/media_player.py b/homeassistant/components/anthemav/media_player.py index 4056a34995a..91f8536d348 100644 --- a/homeassistant/components/anthemav/media_player.py +++ b/homeassistant/components/anthemav/media_player.py @@ -13,7 +13,7 @@ from homeassistant.components.media_player import ( MediaPlayerState, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_MAC, CONF_NAME +from homeassistant.const import CONF_MAC from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -30,7 +30,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up entry.""" - name = config_entry.data[CONF_NAME] + name = config_entry.title mac_address = config_entry.data[CONF_MAC] model = config_entry.data[CONF_MODEL] diff --git a/tests/components/anthemav/conftest.py b/tests/components/anthemav/conftest.py index 89dba9563d1..7797f08872f 100644 --- a/tests/components/anthemav/conftest.py +++ b/tests/components/anthemav/conftest.py @@ -5,7 +5,7 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest from homeassistant.components.anthemav.const import CONF_MODEL, DOMAIN -from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_PORT +from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -55,10 +55,10 @@ def mock_config_entry() -> MockConfigEntry: """Return the default mocked config entry.""" return MockConfigEntry( domain=DOMAIN, + title="Anthem AV", data={ CONF_HOST: "1.1.1.1", CONF_PORT: 14999, - CONF_NAME: "Anthem AV", CONF_MAC: "00:00:00:00:00:01", CONF_MODEL: "MRX 520", }, diff --git a/tests/components/anthemav/test_config_flow.py b/tests/components/anthemav/test_config_flow.py index e62fb4ba52c..caa76006976 100644 --- a/tests/components/anthemav/test_config_flow.py +++ b/tests/components/anthemav/test_config_flow.py @@ -36,10 +36,10 @@ async def test_form_with_valid_connection( await hass.async_block_till_done() assert result2["type"] == FlowResultType.CREATE_ENTRY + assert result2["title"] == "Anthem AV" assert result2["data"] == { "host": "1.1.1.1", "port": 14999, - "name": "Anthem AV", "mac": "00:00:00:00:00:01", "model": "MRX 520", }