mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Remove yaml config fixture from HEOS tests (#136123)
This commit is contained in:
parent
24610e4b9f
commit
d7ec99de7d
@ -120,12 +120,6 @@ def controller_fixture(
|
|||||||
yield mock_heos
|
yield mock_heos
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="config")
|
|
||||||
def config_fixture():
|
|
||||||
"""Create hass config fixture."""
|
|
||||||
return {DOMAIN: {CONF_HOST: "127.0.0.1"}}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="players")
|
@pytest.fixture(name="players")
|
||||||
def player_fixture(quick_selects):
|
def player_fixture(quick_selects):
|
||||||
"""Create two mock HeosPlayers."""
|
"""Create two mock HeosPlayers."""
|
||||||
@ -309,12 +303,12 @@ def playlists_fixture() -> Sequence[MediaItem]:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="change_data")
|
@pytest.fixture(name="change_data")
|
||||||
def change_data_fixture() -> dict:
|
def change_data_fixture() -> PlayerUpdateResult:
|
||||||
"""Create player change data for testing."""
|
"""Create player change data for testing."""
|
||||||
return PlayerUpdateResult()
|
return PlayerUpdateResult()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="change_data_mapped_ids")
|
@pytest.fixture(name="change_data_mapped_ids")
|
||||||
def change_data_mapped_ids_fixture() -> dict:
|
def change_data_mapped_ids_fixture() -> PlayerUpdateResult:
|
||||||
"""Create player change data for testing."""
|
"""Create player change data for testing."""
|
||||||
return PlayerUpdateResult(updated_player_ids={1: 101})
|
return PlayerUpdateResult(updated_player_ids={1: 101})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Tests for the Heos config flow module."""
|
"""Tests for the Heos config flow module."""
|
||||||
|
|
||||||
from pyheos import CommandAuthenticationError, CommandFailedError, HeosError
|
from pyheos import CommandAuthenticationError, CommandFailedError, Heos, HeosError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import heos
|
from homeassistant.components import heos
|
||||||
@ -14,7 +14,9 @@ from homeassistant.helpers.service_info.ssdp import SsdpServiceInfo
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_aborts_already_setup(hass: HomeAssistant, config_entry) -> None:
|
async def test_flow_aborts_already_setup(
|
||||||
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Test flow aborts when entry already setup."""
|
"""Test flow aborts when entry already setup."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -36,7 +38,9 @@ async def test_no_host_shows_form(hass: HomeAssistant) -> None:
|
|||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
|
|
||||||
async def test_cannot_connect_shows_error_form(hass: HomeAssistant, controller) -> None:
|
async def test_cannot_connect_shows_error_form(
|
||||||
|
hass: HomeAssistant, controller: Heos
|
||||||
|
) -> None:
|
||||||
"""Test form is shown with error when cannot connect."""
|
"""Test form is shown with error when cannot connect."""
|
||||||
controller.connect.side_effect = HeosError()
|
controller.connect.side_effect = HeosError()
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -49,7 +53,9 @@ async def test_cannot_connect_shows_error_form(hass: HomeAssistant, controller)
|
|||||||
assert controller.disconnect.call_count == 1
|
assert controller.disconnect.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_create_entry_when_host_valid(hass: HomeAssistant, controller) -> None:
|
async def test_create_entry_when_host_valid(
|
||||||
|
hass: HomeAssistant, controller: Heos
|
||||||
|
) -> None:
|
||||||
"""Test result type is create entry when host is valid."""
|
"""Test result type is create entry when host is valid."""
|
||||||
data = {CONF_HOST: "127.0.0.1"}
|
data = {CONF_HOST: "127.0.0.1"}
|
||||||
|
|
||||||
@ -65,7 +71,7 @@ async def test_create_entry_when_host_valid(hass: HomeAssistant, controller) ->
|
|||||||
|
|
||||||
|
|
||||||
async def test_create_entry_when_friendly_name_valid(
|
async def test_create_entry_when_friendly_name_valid(
|
||||||
hass: HomeAssistant, controller
|
hass: HomeAssistant, controller: Heos
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test result type is create entry when friendly name is valid."""
|
"""Test result type is create entry when friendly name is valid."""
|
||||||
hass.data[DOMAIN] = {"Office (127.0.0.1)": "127.0.0.1"}
|
hass.data[DOMAIN] = {"Office (127.0.0.1)": "127.0.0.1"}
|
||||||
@ -86,7 +92,6 @@ async def test_create_entry_when_friendly_name_valid(
|
|||||||
|
|
||||||
async def test_discovery_shows_create_form(
|
async def test_discovery_shows_create_form(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
controller,
|
|
||||||
discovery_data: SsdpServiceInfo,
|
discovery_data: SsdpServiceInfo,
|
||||||
discovery_data_bedroom: SsdpServiceInfo,
|
discovery_data_bedroom: SsdpServiceInfo,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -113,7 +118,7 @@ async def test_discovery_shows_create_form(
|
|||||||
|
|
||||||
|
|
||||||
async def test_discovery_flow_aborts_already_setup(
|
async def test_discovery_flow_aborts_already_setup(
|
||||||
hass: HomeAssistant, controller, discovery_data: SsdpServiceInfo, config_entry
|
hass: HomeAssistant, discovery_data: SsdpServiceInfo, config_entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test discovery flow aborts when entry already setup."""
|
"""Test discovery flow aborts when entry already setup."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
@ -127,7 +132,7 @@ async def test_discovery_flow_aborts_already_setup(
|
|||||||
|
|
||||||
|
|
||||||
async def test_reconfigure_validates_and_updates_config(
|
async def test_reconfigure_validates_and_updates_config(
|
||||||
hass: HomeAssistant, config_entry, controller
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test reconfigure validates host and successfully updates."""
|
"""Test reconfigure validates host and successfully updates."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
@ -157,7 +162,7 @@ async def test_reconfigure_validates_and_updates_config(
|
|||||||
|
|
||||||
|
|
||||||
async def test_reconfigure_cannot_connect_recovers(
|
async def test_reconfigure_cannot_connect_recovers(
|
||||||
hass: HomeAssistant, config_entry, controller
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test reconfigure cannot connect and recovers."""
|
"""Test reconfigure cannot connect and recovers."""
|
||||||
controller.connect.side_effect = HeosError()
|
controller.connect.side_effect = HeosError()
|
||||||
@ -209,8 +214,8 @@ async def test_reconfigure_cannot_connect_recovers(
|
|||||||
)
|
)
|
||||||
async def test_options_flow_signs_in(
|
async def test_options_flow_signs_in(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
controller,
|
controller: Heos,
|
||||||
error: HeosError,
|
error: HeosError,
|
||||||
expected_error_key: str,
|
expected_error_key: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -250,7 +255,7 @@ async def test_options_flow_signs_in(
|
|||||||
|
|
||||||
|
|
||||||
async def test_options_flow_signs_out(
|
async def test_options_flow_signs_out(
|
||||||
hass: HomeAssistant, config_entry, controller
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test options flow signs-out when credentials cleared."""
|
"""Test options flow signs-out when credentials cleared."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
@ -294,8 +299,8 @@ async def test_options_flow_signs_out(
|
|||||||
)
|
)
|
||||||
async def test_options_flow_missing_one_param_recovers(
|
async def test_options_flow_missing_one_param_recovers(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
controller,
|
controller: Heos,
|
||||||
user_input: dict[str, str],
|
user_input: dict[str, str],
|
||||||
expected_errors: dict[str, str],
|
expected_errors: dict[str, str],
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -343,7 +348,7 @@ async def test_options_flow_missing_one_param_recovers(
|
|||||||
async def test_reauth_signs_in_aborts(
|
async def test_reauth_signs_in_aborts(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
controller,
|
controller: Heos,
|
||||||
error: HeosError,
|
error: HeosError,
|
||||||
expected_error_key: str,
|
expected_error_key: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -381,7 +386,9 @@ async def test_reauth_signs_in_aborts(
|
|||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth_signs_out(hass: HomeAssistant, config_entry, controller) -> None:
|
async def test_reauth_signs_out(
|
||||||
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
|
) -> None:
|
||||||
"""Test reauth flow signs-out when credentials cleared and aborts."""
|
"""Test reauth flow signs-out when credentials cleared and aborts."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
result = await config_entry.start_reauth_flow(hass)
|
result = await config_entry.start_reauth_flow(hass)
|
||||||
@ -425,8 +432,8 @@ async def test_reauth_signs_out(hass: HomeAssistant, config_entry, controller) -
|
|||||||
)
|
)
|
||||||
async def test_reauth_flow_missing_one_param_recovers(
|
async def test_reauth_flow_missing_one_param_recovers(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
controller,
|
controller: Heos,
|
||||||
user_input: dict[str, str],
|
user_input: dict[str, str],
|
||||||
expected_errors: dict[str, str],
|
expected_errors: dict[str, str],
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -4,7 +4,14 @@ import asyncio
|
|||||||
from typing import cast
|
from typing import cast
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from pyheos import CommandFailedError, HeosError, SignalHeosEvent, SignalType, const
|
from pyheos import (
|
||||||
|
CommandFailedError,
|
||||||
|
Heos,
|
||||||
|
HeosError,
|
||||||
|
SignalHeosEvent,
|
||||||
|
SignalType,
|
||||||
|
const,
|
||||||
|
)
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.heos import (
|
from homeassistant.components.heos import (
|
||||||
@ -20,37 +27,14 @@ from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_async_setup_returns_true(
|
|
||||||
hass: HomeAssistant, config_entry, config
|
|
||||||
) -> None:
|
|
||||||
"""Test component setup from config."""
|
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
assert await async_setup_component(hass, DOMAIN, config)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
|
||||||
assert len(entries) == 1
|
|
||||||
assert entries[0] == config_entry
|
|
||||||
|
|
||||||
|
|
||||||
async def test_async_setup_no_config_returns_true(
|
|
||||||
hass: HomeAssistant, config_entry
|
|
||||||
) -> None:
|
|
||||||
"""Test component setup from entry only."""
|
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
assert await async_setup_component(hass, DOMAIN, {})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
|
||||||
assert len(entries) == 1
|
|
||||||
assert entries[0] == config_entry
|
|
||||||
|
|
||||||
|
|
||||||
async def test_async_setup_entry_loads_platforms(
|
async def test_async_setup_entry_loads_platforms(
|
||||||
hass: HomeAssistant, config_entry, controller, input_sources, favorites
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
controller: Heos,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test load connects to heos, retrieves players, and loads platforms."""
|
"""Test load connects to heos, retrieves players, and loads platforms."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
@ -69,17 +53,11 @@ async def test_async_setup_entry_loads_platforms(
|
|||||||
|
|
||||||
|
|
||||||
async def test_async_setup_entry_with_options_loads_platforms(
|
async def test_async_setup_entry_with_options_loads_platforms(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant, config_entry_options: MockConfigEntry, controller: Heos
|
||||||
config_entry_options,
|
|
||||||
config,
|
|
||||||
controller,
|
|
||||||
input_sources,
|
|
||||||
favorites,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test load connects to heos with options, retrieves players, and loads platforms."""
|
"""Test load connects to heos with options, retrieves players, and loads platforms."""
|
||||||
config_entry_options.add_to_hass(hass)
|
config_entry_options.add_to_hass(hass)
|
||||||
assert await async_setup_component(hass, DOMAIN, config)
|
assert await hass.config_entries.async_setup(config_entry_options.entry_id)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Assert options passed and methods called
|
# Assert options passed and methods called
|
||||||
assert config_entry_options.state is ConfigEntryState.LOADED
|
assert config_entry_options.state is ConfigEntryState.LOADED
|
||||||
@ -111,8 +89,7 @@ async def test_async_setup_entry_auth_failure_starts_reauth(
|
|||||||
|
|
||||||
controller.connect.side_effect = connect_send_auth_failure
|
controller.connect.side_effect = connect_send_auth_failure
|
||||||
|
|
||||||
assert await async_setup_component(hass, DOMAIN, {})
|
assert await hass.config_entries.async_setup(config_entry_options.entry_id)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Assert entry loaded and reauth flow started
|
# Assert entry loaded and reauth flow started
|
||||||
assert controller.connect.call_count == 1
|
assert controller.connect.call_count == 1
|
||||||
@ -126,9 +103,8 @@ async def test_async_setup_entry_auth_failure_starts_reauth(
|
|||||||
|
|
||||||
async def test_async_setup_entry_not_signed_in_loads_platforms(
|
async def test_async_setup_entry_not_signed_in_loads_platforms(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
controller,
|
controller: Heos,
|
||||||
input_sources,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setup does not retrieve favorites when not logged in."""
|
"""Test setup does not retrieve favorites when not logged in."""
|
||||||
@ -153,7 +129,7 @@ async def test_async_setup_entry_not_signed_in_loads_platforms(
|
|||||||
|
|
||||||
|
|
||||||
async def test_async_setup_entry_connect_failure(
|
async def test_async_setup_entry_connect_failure(
|
||||||
hass: HomeAssistant, config_entry, controller
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Connection failure raises ConfigEntryNotReady."""
|
"""Connection failure raises ConfigEntryNotReady."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
@ -167,7 +143,7 @@ async def test_async_setup_entry_connect_failure(
|
|||||||
|
|
||||||
|
|
||||||
async def test_async_setup_entry_player_failure(
|
async def test_async_setup_entry_player_failure(
|
||||||
hass: HomeAssistant, config_entry, controller
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Failure to retrieve players/sources raises ConfigEntryNotReady."""
|
"""Failure to retrieve players/sources raises ConfigEntryNotReady."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
@ -180,7 +156,7 @@ async def test_async_setup_entry_player_failure(
|
|||||||
controller.disconnect.reset_mock()
|
controller.disconnect.reset_mock()
|
||||||
|
|
||||||
|
|
||||||
async def test_unload_entry(hass: HomeAssistant, config_entry, controller) -> None:
|
async def test_unload_entry(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
|
||||||
"""Test entries are unloaded correctly."""
|
"""Test entries are unloaded correctly."""
|
||||||
controller_manager = Mock(ControllerManager)
|
controller_manager = Mock(ControllerManager)
|
||||||
config_entry.runtime_data = HeosRuntimeData(controller_manager, None, None, {})
|
config_entry.runtime_data = HeosRuntimeData(controller_manager, None, None, {})
|
||||||
@ -197,14 +173,13 @@ async def test_unload_entry(hass: HomeAssistant, config_entry, controller) -> No
|
|||||||
|
|
||||||
async def test_update_sources_retry(
|
async def test_update_sources_retry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
config,
|
controller: Heos,
|
||||||
controller,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test update sources retries on failures to max attempts."""
|
"""Test update sources retries on failures to max attempts."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
assert await async_setup_component(hass, DOMAIN, config)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
controller.get_favorites.reset_mock()
|
controller.get_favorites.reset_mock()
|
||||||
controller.get_input_sources.reset_mock()
|
controller.get_input_sources.reset_mock()
|
||||||
source_manager = config_entry.runtime_data.source_manager
|
source_manager = config_entry.runtime_data.source_manager
|
||||||
|
@ -11,6 +11,7 @@ from pyheos import (
|
|||||||
Heos,
|
Heos,
|
||||||
HeosError,
|
HeosError,
|
||||||
MediaItem,
|
MediaItem,
|
||||||
|
PlayerUpdateResult,
|
||||||
PlayState,
|
PlayState,
|
||||||
SignalHeosEvent,
|
SignalHeosEvent,
|
||||||
SignalType,
|
SignalType,
|
||||||
@ -65,25 +66,17 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def setup_platform(
|
@pytest.mark.usefixtures("controller")
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry, config: dict[str, Any]
|
|
||||||
) -> None:
|
|
||||||
"""Set up the media player platform for testing."""
|
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
assert await async_setup_component(hass, DOMAIN, config)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_state_attributes(
|
async def test_state_attributes(
|
||||||
hass: HomeAssistant, config_entry, config, controller
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests the state attributes."""
|
"""Tests the state attributes."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
state = hass.states.get("media_player.test_player")
|
state = hass.states.get("media_player.test_player")
|
||||||
assert state.state == STATE_IDLE
|
assert state.state == STATE_IDLE
|
||||||
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0.25
|
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0.25
|
||||||
@ -119,10 +112,11 @@ async def test_state_attributes(
|
|||||||
|
|
||||||
|
|
||||||
async def test_updates_from_signals(
|
async def test_updates_from_signals(
|
||||||
hass: HomeAssistant, config_entry, config, controller, favorites
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests dispatched signals update player."""
|
"""Tests dispatched signals update player."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
|
|
||||||
# Test player does not update for other players
|
# Test player does not update for other players
|
||||||
@ -161,13 +155,13 @@ async def test_updates_from_signals(
|
|||||||
|
|
||||||
async def test_updates_from_connection_event(
|
async def test_updates_from_connection_event(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
config,
|
controller: Heos,
|
||||||
controller,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests player updates from connection event after connection failure."""
|
"""Tests player updates from connection event after connection failure."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
event = asyncio.Event()
|
event = asyncio.Event()
|
||||||
|
|
||||||
@ -208,10 +202,14 @@ async def test_updates_from_connection_event(
|
|||||||
|
|
||||||
|
|
||||||
async def test_updates_from_sources_updated(
|
async def test_updates_from_sources_updated(
|
||||||
hass: HomeAssistant, config_entry, config, controller, input_sources
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
controller: Heos,
|
||||||
|
input_sources: Sequence[MediaItem],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests player updates from changes in sources list."""
|
"""Tests player updates from changes in sources list."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
event = asyncio.Event()
|
event = asyncio.Event()
|
||||||
|
|
||||||
@ -233,14 +231,13 @@ async def test_updates_from_sources_updated(
|
|||||||
|
|
||||||
async def test_updates_from_players_changed(
|
async def test_updates_from_players_changed(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
config,
|
controller: Heos,
|
||||||
controller,
|
change_data: PlayerUpdateResult,
|
||||||
change_data,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test player updates from changes to available players."""
|
"""Test player updates from changes to available players."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
event = asyncio.Event()
|
event = asyncio.Event()
|
||||||
|
|
||||||
@ -263,14 +260,13 @@ async def test_updates_from_players_changed_new_ids(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
config,
|
controller: Heos,
|
||||||
controller,
|
change_data_mapped_ids: PlayerUpdateResult,
|
||||||
change_data_mapped_ids,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test player updates from changes to available players."""
|
"""Test player updates from changes to available players."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
event = asyncio.Event()
|
event = asyncio.Event()
|
||||||
|
|
||||||
@ -306,10 +302,11 @@ async def test_updates_from_players_changed_new_ids(
|
|||||||
|
|
||||||
|
|
||||||
async def test_updates_from_user_changed(
|
async def test_updates_from_user_changed(
|
||||||
hass: HomeAssistant, config_entry, config, controller
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests player updates from changes in user."""
|
"""Tests player updates from changes in user."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
event = asyncio.Event()
|
event = asyncio.Event()
|
||||||
|
|
||||||
@ -660,10 +657,14 @@ async def test_volume_set_error(
|
|||||||
|
|
||||||
|
|
||||||
async def test_select_favorite(
|
async def test_select_favorite(
|
||||||
hass: HomeAssistant, config_entry, config, controller, favorites
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
controller: Heos,
|
||||||
|
favorites: dict[int, MediaItem],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests selecting a music service favorite and state."""
|
"""Tests selecting a music service favorite and state."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
# Test set music service preset
|
# Test set music service preset
|
||||||
favorite = favorites[1]
|
favorite = favorites[1]
|
||||||
@ -685,10 +686,14 @@ async def test_select_favorite(
|
|||||||
|
|
||||||
|
|
||||||
async def test_select_radio_favorite(
|
async def test_select_radio_favorite(
|
||||||
hass: HomeAssistant, config_entry, config, controller, favorites
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
controller: Heos,
|
||||||
|
favorites: dict[int, MediaItem],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests selecting a radio favorite and state."""
|
"""Tests selecting a radio favorite and state."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
# Test set radio preset
|
# Test set radio preset
|
||||||
favorite = favorites[2]
|
favorite = favorites[2]
|
||||||
@ -740,10 +745,14 @@ async def test_select_radio_favorite_command_error(
|
|||||||
|
|
||||||
|
|
||||||
async def test_select_input_source(
|
async def test_select_input_source(
|
||||||
hass: HomeAssistant, config_entry, config, controller, input_sources
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
controller: Heos,
|
||||||
|
input_sources: Sequence[MediaItem],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests selecting input source and state."""
|
"""Tests selecting input source and state."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
# Test proper service called
|
# Test proper service called
|
||||||
input_source = input_sources[0]
|
input_source = input_sources[0]
|
||||||
@ -815,12 +824,14 @@ async def test_select_input_command_error(
|
|||||||
player.play_input_source.assert_called_once_with(input_source.media_id)
|
player.play_input_source.assert_called_once_with(input_source.media_id)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("controller")
|
||||||
async def test_unload_config_entry(
|
async def test_unload_config_entry(
|
||||||
hass: HomeAssistant, config_entry, config, controller
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the player is set unavailable when the config entry is unloaded."""
|
"""Test the player is set unavailable when the config entry is unloaded."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||||
assert hass.states.get("media_player.test_player").state == STATE_UNAVAILABLE
|
assert hass.states.get("media_player.test_player").state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
@ -1112,14 +1123,13 @@ async def test_media_player_join_group_error(
|
|||||||
|
|
||||||
async def test_media_player_group_members(
|
async def test_media_player_group_members(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
config,
|
controller: Heos,
|
||||||
controller,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test group_members attribute."""
|
"""Test group_members attribute."""
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
await hass.async_block_till_done()
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
player_entity = hass.states.get("media_player.test_player")
|
player_entity = hass.states.get("media_player.test_player")
|
||||||
assert player_entity.attributes[ATTR_GROUP_MEMBERS] == [
|
assert player_entity.attributes[ATTR_GROUP_MEMBERS] == [
|
||||||
"media_player.test_player",
|
"media_player.test_player",
|
||||||
@ -1131,15 +1141,14 @@ async def test_media_player_group_members(
|
|||||||
|
|
||||||
async def test_media_player_group_members_error(
|
async def test_media_player_group_members_error(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry,
|
config_entry: MockConfigEntry,
|
||||||
config,
|
controller: Heos,
|
||||||
controller,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error in HEOS API."""
|
"""Test error in HEOS API."""
|
||||||
controller.get_groups.side_effect = HeosError("error")
|
controller.get_groups.side_effect = HeosError("error")
|
||||||
await setup_platform(hass, config_entry, config)
|
config_entry.add_to_hass(hass)
|
||||||
await hass.async_block_till_done()
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
assert "Unable to get HEOS group info" in caplog.text
|
assert "Unable to get HEOS group info" in caplog.text
|
||||||
player_entity = hass.states.get("media_player.test_player")
|
player_entity = hass.states.get("media_player.test_player")
|
||||||
assert player_entity.attributes[ATTR_GROUP_MEMBERS] == []
|
assert player_entity.attributes[ATTR_GROUP_MEMBERS] == []
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Tests for the services module."""
|
"""Tests for the services module."""
|
||||||
|
|
||||||
from pyheos import CommandAuthenticationError, HeosError
|
from pyheos import CommandAuthenticationError, Heos, HeosError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.heos.const import (
|
from homeassistant.components.heos.const import (
|
||||||
@ -12,21 +12,16 @@ from homeassistant.components.heos.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def setup_component(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
|
async def test_sign_in(
|
||||||
"""Set up the component for testing."""
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
config_entry.add_to_hass(hass)
|
) -> None:
|
||||||
assert await async_setup_component(hass, DOMAIN, {})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_sign_in(hass: HomeAssistant, config_entry, controller) -> None:
|
|
||||||
"""Test the sign-in service."""
|
"""Test the sign-in service."""
|
||||||
await setup_component(hass, config_entry)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -39,10 +34,15 @@ async def test_sign_in(hass: HomeAssistant, config_entry, controller) -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def test_sign_in_failed(
|
async def test_sign_in_failed(
|
||||||
hass: HomeAssistant, config_entry, controller, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
controller: Heos,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test sign-in service logs error when not connected."""
|
"""Test sign-in service logs error when not connected."""
|
||||||
await setup_component(hass, config_entry)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
|
||||||
controller.sign_in.side_effect = CommandAuthenticationError(
|
controller.sign_in.side_effect = CommandAuthenticationError(
|
||||||
"", "Invalid credentials", 6
|
"", "Invalid credentials", 6
|
||||||
)
|
)
|
||||||
@ -59,10 +59,15 @@ async def test_sign_in_failed(
|
|||||||
|
|
||||||
|
|
||||||
async def test_sign_in_unknown_error(
|
async def test_sign_in_unknown_error(
|
||||||
hass: HomeAssistant, config_entry, controller, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
controller: Heos,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test sign-in service logs error for failure."""
|
"""Test sign-in service logs error for failure."""
|
||||||
await setup_component(hass, config_entry)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
|
||||||
controller.sign_in.side_effect = HeosError()
|
controller.sign_in.side_effect = HeosError()
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -76,10 +81,14 @@ async def test_sign_in_unknown_error(
|
|||||||
assert "Unable to sign in" in caplog.text
|
assert "Unable to sign in" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_sign_in_not_loaded_raises(hass: HomeAssistant, config_entry) -> None:
|
@pytest.mark.usefixtures("controller")
|
||||||
|
async def test_sign_in_not_loaded_raises(
|
||||||
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Test the sign-in service when entry not loaded raises exception."""
|
"""Test the sign-in service when entry not loaded raises exception."""
|
||||||
await setup_component(hass, config_entry)
|
config_entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||||
|
|
||||||
with pytest.raises(HomeAssistantError, match="The HEOS integration is not loaded"):
|
with pytest.raises(HomeAssistantError, match="The HEOS integration is not loaded"):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -90,29 +99,39 @@ async def test_sign_in_not_loaded_raises(hass: HomeAssistant, config_entry) -> N
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_sign_out(hass: HomeAssistant, config_entry, controller) -> None:
|
async def test_sign_out(
|
||||||
|
hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos
|
||||||
|
) -> None:
|
||||||
"""Test the sign-out service."""
|
"""Test the sign-out service."""
|
||||||
await setup_component(hass, config_entry)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
|
||||||
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
||||||
|
|
||||||
assert controller.sign_out.call_count == 1
|
assert controller.sign_out.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_sign_out_not_loaded_raises(hass: HomeAssistant, config_entry) -> None:
|
async def test_sign_out_not_loaded_raises(
|
||||||
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Test the sign-out service when entry not loaded raises exception."""
|
"""Test the sign-out service when entry not loaded raises exception."""
|
||||||
await setup_component(hass, config_entry)
|
config_entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||||
|
|
||||||
with pytest.raises(HomeAssistantError, match="The HEOS integration is not loaded"):
|
with pytest.raises(HomeAssistantError, match="The HEOS integration is not loaded"):
|
||||||
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
||||||
|
|
||||||
|
|
||||||
async def test_sign_out_unknown_error(
|
async def test_sign_out_unknown_error(
|
||||||
hass: HomeAssistant, config_entry, controller, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
controller: Heos,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the sign-out service."""
|
"""Test the sign-out service."""
|
||||||
await setup_component(hass, config_entry)
|
config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
controller.sign_out.side_effect = HeosError()
|
controller.sign_out.side_effect = HeosError()
|
||||||
|
|
||||||
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user