Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config_flow to bluesound integration #115207

Merged
merged 21 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add port to zeroconf flow
  • Loading branch information
LouisChrist committed Jul 27, 2024
commit 63bb483380226f8897d47ac3ce9510d339efc794
12 changes: 9 additions & 3 deletions homeassistant/components/bluesound/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BluesoundConfigFlow(ConfigFlow, domain=DOMAIN):
def __init__(self) -> None:
"""Initialize the config flow."""
self._host: str | None = None
self._port = DEFAULT_PORT
self._sync_status: SyncStatus | None = None

async def async_step_user(
Expand Down Expand Up @@ -95,14 +96,19 @@ async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Handle a flow initialized by zeroconf discovery."""
if discovery_info.port is not None:
self._port = discovery_info.port

session = async_get_clientsession(self.hass)
try:
async with Player(discovery_info.host, session=session) as player:
async with Player(
discovery_info.host, self._port, session=session
) as player:
sync_status = await player.sync_status(timeout=1)
except (TimeoutError, aiohttp.ClientError):
return self.async_abort(reason="cannot_connect")

await self.async_set_unique_id(format_unique_id(sync_status.mac, DEFAULT_PORT))
await self.async_set_unique_id(format_unique_id(sync_status.mac, self._port))

self._host = discovery_info.host
self._sync_status = sync_status
Expand Down Expand Up @@ -131,7 +137,7 @@ async def async_step_confirm(self, user_input=None) -> ConfigFlowResult:
title=self._sync_status.name,
data={
CONF_HOST: self._host,
CONF_PORT: DEFAULT_PORT,
CONF_PORT: self._port,
},
)

Expand Down
2 changes: 1 addition & 1 deletion tests/components/bluesound/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
mock_entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_HOST: "1.1.1.1",
CONF_HOST: "1.1.1.2",
CONF_PORT: 11000,
},
unique_id="00:11:22:33:44:55-11000",
Expand Down
3 changes: 3 additions & 0 deletions tests/components/bluesound/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ async def test_user_flow_aleady_configured(
result["flow_id"],
{
CONF_HOST: "1.1.1.1",
CONF_PORT: 11000,
},
)

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

assert mock_config_entry.data[CONF_HOST] == "1.1.1.1"

mock_player_sync_status.sync_status.assert_called_once()


Expand Down
Loading