Remove setting name in AnthemAV config flow (#99148)

This commit is contained in:
Joost Lekkerkerker 2023-09-26 19:58:47 +02:00 committed by GitHub
parent 20a2e129fb
commit bc665a1368
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 12 deletions

View file

@ -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()

View file

@ -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]

View file

@ -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",
},

View file

@ -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",
}