* Add config flow to bluesound * update init * abort flow if connection is not possible * add to codeowners * update unique id * add async_unload_entry * add import flow * add device_info * add zeroconf * fix errors * formatting * use bluos specific zeroconf service type * implement requested changes * implement requested changes * fix test; add more tests * use AsyncMock assert functions * fix potential naming collision * move setup_services back to media_player.py * implement requested changes * add port to zeroconf flow * Fix comments --------- Co-authored-by: Joostlek <joostlek@outlook.com>
103 lines
2.7 KiB
Python
103 lines
2.7 KiB
Python
"""Common fixtures for the Bluesound tests."""
|
|
|
|
from collections.abc import Generator
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from pyblu import SyncStatus
|
|
import pytest
|
|
|
|
from homeassistant.components.bluesound.const import DOMAIN
|
|
from homeassistant.const import CONF_HOST, CONF_PORT
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
@pytest.fixture
|
|
def sync_status() -> SyncStatus:
|
|
"""Return a sync status object."""
|
|
return SyncStatus(
|
|
etag="etag",
|
|
id="1.1.1.1:11000",
|
|
mac="00:11:22:33:44:55",
|
|
name="player-name",
|
|
image="invalid_url",
|
|
initialized=True,
|
|
brand="brand",
|
|
model="model",
|
|
model_name="model-name",
|
|
volume_db=0.5,
|
|
volume=50,
|
|
group=None,
|
|
master=None,
|
|
slaves=None,
|
|
zone=None,
|
|
zone_master=None,
|
|
zone_slave=None,
|
|
mute_volume_db=None,
|
|
mute_volume=None,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
|
"""Override async_setup_entry."""
|
|
with patch(
|
|
"homeassistant.components.bluesound.async_setup_entry", return_value=True
|
|
) as mock_setup_entry:
|
|
yield mock_setup_entry
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
|
|
"""Return a mocked config entry."""
|
|
mock_entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data={
|
|
CONF_HOST: "1.1.1.2",
|
|
CONF_PORT: 11000,
|
|
},
|
|
unique_id="00:11:22:33:44:55-11000",
|
|
)
|
|
mock_entry.add_to_hass(hass)
|
|
|
|
return mock_entry
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_player() -> Generator[AsyncMock]:
|
|
"""Mock the player."""
|
|
with (
|
|
patch(
|
|
"homeassistant.components.bluesound.Player", autospec=True
|
|
) as mock_player,
|
|
patch(
|
|
"homeassistant.components.bluesound.config_flow.Player",
|
|
new=mock_player,
|
|
),
|
|
):
|
|
player = mock_player.return_value
|
|
player.__aenter__.return_value = player
|
|
player.status.return_value = None
|
|
player.sync_status.return_value = SyncStatus(
|
|
etag="etag",
|
|
id="1.1.1.1:11000",
|
|
mac="00:11:22:33:44:55",
|
|
name="player-name",
|
|
image="invalid_url",
|
|
initialized=True,
|
|
brand="brand",
|
|
model="model",
|
|
model_name="model-name",
|
|
volume_db=0.5,
|
|
volume=50,
|
|
group=None,
|
|
master=None,
|
|
slaves=None,
|
|
zone=None,
|
|
zone_master=None,
|
|
zone_slave=None,
|
|
mute_volume_db=None,
|
|
mute_volume=None,
|
|
)
|
|
yield player
|