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
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
fix potential naming collision
  • Loading branch information
LouisChrist committed Jul 27, 2024
commit 6343225aa38d74cde98ed89c41598a28ab373c2d
39 changes: 23 additions & 16 deletions homeassistant/components/bluesound/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
from homeassistant.core import (
DOMAIN as HOMEASSISTANT_DOMAIN,
Event,
HomeAssistant,
callback,
)
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import config_validation as cv, issue_registry as ir
Expand Down Expand Up @@ -88,30 +93,30 @@
"""Add Bluesound players."""

@callback
def _init_player(event=None):
def _init_bluesound_player(event: Event | None = None):

Check warning on line 96 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L96

Added line #L96 was not covered by tests
"""Start polling."""
hass.async_create_task(player.async_init())
hass.async_create_task(bluesound_player.async_init())

Check warning on line 98 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L98

Added line #L98 was not covered by tests

@callback
def _start_polling(event=None):
def _start_polling(event: Event):

Check warning on line 101 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L101

Added line #L101 was not covered by tests
"""Start polling."""
player.start_polling()
bluesound_player.start_polling()

Check warning on line 103 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L103

Added line #L103 was not covered by tests

@callback
def _stop_polling(event=None):
def _stop_polling(event: Event):

Check warning on line 106 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L106

Added line #L106 was not covered by tests
"""Stop polling."""
player.stop_polling()
bluesound_player.stop_polling()

Check warning on line 108 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L108

Added line #L108 was not covered by tests

@callback
def _add_player_cb():
def _add_bluesound_player_cb():

Check warning on line 111 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L111

Added line #L111 was not covered by tests
"""Add player after first sync fetch."""
if player.id in [x.id for x in hass.data[DATA_BLUESOUND]]:
_LOGGER.warning("Player already added %s", player.id)
if bluesound_player.id in [x.id for x in hass.data[DATA_BLUESOUND]]:
_LOGGER.warning("Player already added %s", bluesound_player.id)

Check warning on line 114 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L113-L114

Added lines #L113 - L114 were not covered by tests
return

hass.data[DATA_BLUESOUND].append(player)
async_add_entities([player])
_LOGGER.info("Added device with name: %s", player.name)
hass.data[DATA_BLUESOUND].append(bluesound_player)
async_add_entities([bluesound_player])
_LOGGER.info("Added device with name: %s", bluesound_player.name)

Check warning on line 119 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L117-L119

Added lines #L117 - L119 were not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't log on info


if hass.is_running:
_start_polling()
Expand All @@ -120,23 +125,25 @@

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _stop_polling)

player = BluesoundPlayer(hass, host, port, player, sync_status, _add_player_cb)
bluesound_player = BluesoundPlayer(

Check warning on line 128 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L128

Added line #L128 was not covered by tests
hass, host, port, player, sync_status, _add_bluesound_player_cb
)

if hass.is_running:
_init_player()
_init_bluesound_player()

Check warning on line 133 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L133

Added line #L133 was not covered by tests
else:
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _init_player)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _init_bluesound_player)

Check warning on line 135 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L135

Added line #L135 was not covered by tests


async def _async_import(hass: HomeAssistant, config: ConfigType) -> None:
"""Import config entry from configuration.yaml."""
if not hass.config_entries.async_entries(DOMAIN):

Check warning on line 140 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L140

Added line #L140 was not covered by tests
# Start import flow
result = await hass.config_entries.flow.async_init(

Check warning on line 142 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L142

Added line #L142 was not covered by tests
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
)
if result["type"] == FlowResultType.ABORT:
ir.async_create_issue(

Check warning on line 146 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L145-L146

Added lines #L145 - L146 were not covered by tests
hass,
DOMAIN,
f"deprecated_yaml_import_issue_{result['reason']}",
Expand All @@ -150,9 +157,9 @@
"integration_title": INTEGRATION_TITLE,
},
)
return

Check warning on line 160 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L160

Added line #L160 was not covered by tests

ir.async_create_issue(

Check warning on line 162 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L162

Added line #L162 was not covered by tests
hass,
HOMEASSISTANT_DOMAIN,
f"deprecated_yaml_{DOMAIN}",
Expand All @@ -177,12 +184,12 @@
if DATA_BLUESOUND not in hass.data:
hass.data[DATA_BLUESOUND] = []

host = config_entry.data.get(CONF_HOST)
port = config_entry.data.get(CONF_PORT)
assert isinstance(host, str)
assert isinstance(port, int)

Check warning on line 190 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L187-L190

Added lines #L187 - L190 were not covered by tests

_add_player(

Check warning on line 192 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L192

Added line #L192 was not covered by tests
hass,
async_add_entities,
host,
Expand All @@ -199,13 +206,13 @@
discovery_info: DiscoveryInfoType | None,
) -> None:
"""Trigger import flows."""
hosts = config.get(CONF_HOSTS, [])
for host in hosts:
import_data = {

Check warning on line 211 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L209-L211

Added lines #L209 - L211 were not covered by tests
CONF_HOST: host[CONF_HOST],
CONF_PORT: host.get(CONF_PORT, 11000),
}
hass.async_create_task(_async_import(hass, import_data))

Check warning on line 215 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L215

Added line #L215 was not covered by tests


class BluesoundPlayer(MediaPlayerEntity):
Expand All @@ -227,7 +234,7 @@
self._hass = hass
self.port = port
self._polling_task = None # The actual polling task.
self._name = sync_status.name

Check warning on line 237 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L237

Added line #L237 was not covered by tests
self._id = None
self._last_status_update = None
self._sync_status: SyncStatus | None = None
Expand All @@ -242,7 +249,7 @@
self._group_name = None
self._group_list: list[str] = []
self._bluesound_device_name = None
self._player = player

Check warning on line 252 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L252

Added line #L252 was not covered by tests

self._init_callback = init_callback

Expand Down Expand Up @@ -394,7 +401,7 @@
def unique_id(self) -> str:
"""Return an unique ID."""
assert self._sync_status is not None
return format_unique_id(self._sync_status.mac, self.port)

Check warning on line 404 in homeassistant/components/bluesound/media_player.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluesound/media_player.py#L404

Added line #L404 was not covered by tests

async def async_trigger_sync_on_all(self):
"""Trigger sync status update on all devices."""
Expand Down
Loading