Skip to content

Commit

Permalink
Remove deprecated config entry import from bluesound (home-assistant#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST authored Jan 6, 2025
1 parent 6884d79 commit 9532e98
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 165 deletions.
21 changes: 0 additions & 21 deletions homeassistant/components/bluesound/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,6 @@ async def async_step_user(
),
)

async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import bluesound config entry from configuration.yaml."""
session = async_get_clientsession(self.hass)
async with Player(
import_data[CONF_HOST], import_data[CONF_PORT], session=session
) as player:
try:
sync_status = await player.sync_status(timeout=1)
except PlayerUnreachableError:
return self.async_abort(reason="cannot_connect")

await self.async_set_unique_id(
format_unique_id(sync_status.mac, import_data[CONF_PORT])
)
self._abort_if_unique_id_configured()

return self.async_create_entry(
title=sync_status.name,
data=import_data,
)

async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> ConfigFlowResult:
Expand Down
90 changes: 4 additions & 86 deletions homeassistant/components/bluesound/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@

from homeassistant.components import media_source
from homeassistant.components.media_player import (
PLATFORM_SCHEMA as MEDIA_PLAYER_PLATFORM_SCHEMA,
BrowseMedia,
MediaPlayerEntity,
MediaPlayerEntityFeature,
MediaPlayerState,
MediaType,
async_process_play_media_url,
)
from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.const import CONF_HOST, CONF_HOSTS, CONF_NAME, CONF_PORT
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import (
config_validation as cv,
entity_platform,
issue_registry as ir,
)
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.device_registry import (
CONNECTION_NETWORK_MAC,
DeviceInfo,
Expand All @@ -43,10 +36,9 @@
async_dispatcher_send,
)
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
import homeassistant.util.dt as dt_util

from .const import ATTR_BLUESOUND_GROUP, ATTR_MASTER, DOMAIN, INTEGRATION_TITLE
from .const import ATTR_BLUESOUND_GROUP, ATTR_MASTER, DOMAIN
from .utils import dispatcher_join_signal, dispatcher_unjoin_signal, format_unique_id

if TYPE_CHECKING:
Expand All @@ -71,64 +63,6 @@

POLL_TIMEOUT = 120

PLATFORM_SCHEMA = MEDIA_PLAYER_PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_HOSTS): vol.All(
cv.ensure_list,
[
{
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
}
],
)
}
)


async def _async_import(hass: HomeAssistant, config: ConfigType) -> None:
"""Import config entry from configuration.yaml."""
if not hass.config_entries.async_entries(DOMAIN):
# Start import flow
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
)
if (
result["type"] == FlowResultType.ABORT
and result["reason"] == "cannot_connect"
):
ir.async_create_issue(
hass,
DOMAIN,
f"deprecated_yaml_import_issue_{result['reason']}",
breaks_in_ha_version="2025.2.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=ir.IssueSeverity.WARNING,
translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
translation_placeholders={
"domain": DOMAIN,
"integration_title": INTEGRATION_TITLE,
},
)
return

ir.async_create_issue(
hass,
HOMEASSISTANT_DOMAIN,
f"deprecated_yaml_{DOMAIN}",
breaks_in_ha_version="2025.2.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=ir.IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": INTEGRATION_TITLE,
},
)


async def async_setup_entry(
hass: HomeAssistant,
Expand Down Expand Up @@ -159,22 +93,6 @@ async def async_setup_entry(
async_add_entities([bluesound_player], update_before_add=True)


async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None,
) -> None:
"""Trigger import flows."""
hosts = config.get(CONF_HOSTS, [])
for host in hosts:
import_data = {
CONF_HOST: host[CONF_HOST],
CONF_PORT: host.get(CONF_PORT, 11000),
}
hass.async_create_task(_async_import(hass, import_data))


class BluesoundPlayer(MediaPlayerEntity):
"""Representation of a Bluesound Player."""

Expand Down
59 changes: 1 addition & 58 deletions tests/components/bluesound/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from homeassistant.components.bluesound.const import DOMAIN
from homeassistant.components.zeroconf import ZeroconfServiceInfo
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
Expand Down Expand Up @@ -113,63 +113,6 @@ async def test_user_flow_aleady_configured(
player_mocks.player_data_for_already_configured.player.sync_status.assert_called_once()


async def test_import_flow_success(
hass: HomeAssistant, mock_setup_entry: AsyncMock, player_mocks: PlayerMocks
) -> None:
"""Test we get the form."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_HOST: "1.1.1.1", CONF_PORT: 11000},
)

assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "player-name1111"
assert result["data"] == {CONF_HOST: "1.1.1.1", CONF_PORT: 11000}
assert result["result"].unique_id == "ff:ff:01:01:01:01-11000"

mock_setup_entry.assert_called_once()
player_mocks.player_data.player.sync_status.assert_called_once()


async def test_import_flow_cannot_connect(
hass: HomeAssistant, player_mocks: PlayerMocks
) -> None:
"""Test we handle cannot connect error."""
player_mocks.player_data.player.sync_status.side_effect = PlayerUnreachableError(
"Player not reachable"
)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_HOST: "1.1.1.1", CONF_PORT: 11000},
)

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "cannot_connect"

player_mocks.player_data.player.sync_status.assert_called_once()


async def test_import_flow_already_configured(
hass: HomeAssistant,
player_mocks: PlayerMocks,
config_entry: MockConfigEntry,
) -> None:
"""Test we handle already configured."""
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_HOST: "1.1.1.2", CONF_PORT: 11000},
)

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"

player_mocks.player_data_for_already_configured.player.sync_status.assert_called_once()


async def test_zeroconf_flow_success(
hass: HomeAssistant, mock_setup_entry: AsyncMock, player_mocks: PlayerMocks
) -> None:
Expand Down

0 comments on commit 9532e98

Please sign in to comment.