Remove setting name in AnthemAV config flow (#99148)
This commit is contained in:
parent
20a2e129fb
commit
bc665a1368
4 changed files with 9 additions and 12 deletions
|
@ -9,8 +9,8 @@ from anthemav.connection import Connection
|
||||||
from anthemav.device_error import DeviceError
|
from anthemav.device_error import DeviceError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant.config_entries import ConfigFlow
|
||||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_PORT
|
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.device_registry import format_mac
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
|
@ -43,7 +43,7 @@ async def connect_device(user_input: dict[str, Any]) -> Connection:
|
||||||
return avr
|
return avr
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class AnthemAVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for Anthem A/V Receivers."""
|
"""Handle a config flow for Anthem A/V Receivers."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
@ -57,9 +57,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
|
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
|
||||||
)
|
)
|
||||||
|
|
||||||
if CONF_NAME not in user_input:
|
|
||||||
user_input[CONF_NAME] = DEFAULT_NAME
|
|
||||||
|
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
avr: Connection | None = None
|
avr: Connection | None = None
|
||||||
|
@ -84,7 +81,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
user_input[CONF_MODEL] = avr.protocol.model
|
user_input[CONF_MODEL] = avr.protocol.model
|
||||||
await self.async_set_unique_id(user_input[CONF_MAC])
|
await self.async_set_unique_id(user_input[CONF_MAC])
|
||||||
self._abort_if_unique_id_configured()
|
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:
|
finally:
|
||||||
if avr is not None:
|
if avr is not None:
|
||||||
avr.close()
|
avr.close()
|
||||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.components.media_player import (
|
||||||
MediaPlayerState,
|
MediaPlayerState,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
@ -30,7 +30,7 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up entry."""
|
"""Set up entry."""
|
||||||
name = config_entry.data[CONF_NAME]
|
name = config_entry.title
|
||||||
mac_address = config_entry.data[CONF_MAC]
|
mac_address = config_entry.data[CONF_MAC]
|
||||||
model = config_entry.data[CONF_MODEL]
|
model = config_entry.data[CONF_MODEL]
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.anthemav.const import CONF_MODEL, DOMAIN
|
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 homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
@ -55,10 +55,10 @@ def mock_config_entry() -> MockConfigEntry:
|
||||||
"""Return the default mocked config entry."""
|
"""Return the default mocked config entry."""
|
||||||
return MockConfigEntry(
|
return MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
title="Anthem AV",
|
||||||
data={
|
data={
|
||||||
CONF_HOST: "1.1.1.1",
|
CONF_HOST: "1.1.1.1",
|
||||||
CONF_PORT: 14999,
|
CONF_PORT: 14999,
|
||||||
CONF_NAME: "Anthem AV",
|
|
||||||
CONF_MAC: "00:00:00:00:00:01",
|
CONF_MAC: "00:00:00:00:00:01",
|
||||||
CONF_MODEL: "MRX 520",
|
CONF_MODEL: "MRX 520",
|
||||||
},
|
},
|
||||||
|
|
|
@ -36,10 +36,10 @@ async def test_form_with_valid_connection(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
||||||
|
assert result2["title"] == "Anthem AV"
|
||||||
assert result2["data"] == {
|
assert result2["data"] == {
|
||||||
"host": "1.1.1.1",
|
"host": "1.1.1.1",
|
||||||
"port": 14999,
|
"port": 14999,
|
||||||
"name": "Anthem AV",
|
|
||||||
"mac": "00:00:00:00:00:01",
|
"mac": "00:00:00:00:00:01",
|
||||||
"model": "MRX 520",
|
"model": "MRX 520",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue