From d7ec99de7dcc649291c50a25e692183419797e2b Mon Sep 17 00:00:00 2001 From: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com> Date: Mon, 20 Jan 2025 15:18:46 -0600 Subject: [PATCH] Remove yaml config fixture from HEOS tests (#136123) --- tests/components/heos/conftest.py | 10 +- tests/components/heos/test_config_flow.py | 43 ++++---- tests/components/heos/test_init.py | 69 ++++--------- tests/components/heos/test_media_player.py | 115 +++++++++++---------- tests/components/heos/test_services.py | 69 ++++++++----- 5 files changed, 155 insertions(+), 151 deletions(-) diff --git a/tests/components/heos/conftest.py b/tests/components/heos/conftest.py index 1348923927b..f0014d07876 100644 --- a/tests/components/heos/conftest.py +++ b/tests/components/heos/conftest.py @@ -120,12 +120,6 @@ def controller_fixture( 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") def player_fixture(quick_selects): """Create two mock HeosPlayers.""" @@ -309,12 +303,12 @@ def playlists_fixture() -> Sequence[MediaItem]: @pytest.fixture(name="change_data") -def change_data_fixture() -> dict: +def change_data_fixture() -> PlayerUpdateResult: """Create player change data for testing.""" return PlayerUpdateResult() @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.""" return PlayerUpdateResult(updated_player_ids={1: 101}) diff --git a/tests/components/heos/test_config_flow.py b/tests/components/heos/test_config_flow.py index 217c7393e14..21f3606f9bd 100644 --- a/tests/components/heos/test_config_flow.py +++ b/tests/components/heos/test_config_flow.py @@ -1,6 +1,6 @@ """Tests for the Heos config flow module.""" -from pyheos import CommandAuthenticationError, CommandFailedError, HeosError +from pyheos import CommandAuthenticationError, CommandFailedError, Heos, HeosError import pytest from homeassistant.components import heos @@ -14,7 +14,9 @@ from homeassistant.helpers.service_info.ssdp import SsdpServiceInfo 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.""" config_entry.add_to_hass(hass) @@ -36,7 +38,9 @@ async def test_no_host_shows_form(hass: HomeAssistant) -> None: 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.""" controller.connect.side_effect = HeosError() 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 -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.""" 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( - hass: HomeAssistant, controller + hass: HomeAssistant, controller: Heos ) -> None: """Test result type is create entry when friendly name is valid.""" 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( hass: HomeAssistant, - controller, discovery_data: SsdpServiceInfo, discovery_data_bedroom: SsdpServiceInfo, ) -> None: @@ -113,7 +118,7 @@ async def test_discovery_shows_create_form( 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: """Test discovery flow aborts when entry already setup.""" 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( - hass: HomeAssistant, config_entry, controller + hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos ) -> None: """Test reconfigure validates host and successfully updates.""" 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( - hass: HomeAssistant, config_entry, controller + hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos ) -> None: """Test reconfigure cannot connect and recovers.""" controller.connect.side_effect = HeosError() @@ -209,8 +214,8 @@ async def test_reconfigure_cannot_connect_recovers( ) async def test_options_flow_signs_in( hass: HomeAssistant, - config_entry, - controller, + config_entry: MockConfigEntry, + controller: Heos, error: HeosError, expected_error_key: str, ) -> None: @@ -250,7 +255,7 @@ async def test_options_flow_signs_in( async def test_options_flow_signs_out( - hass: HomeAssistant, config_entry, controller + hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos ) -> None: """Test options flow signs-out when credentials cleared.""" 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( hass: HomeAssistant, - config_entry, - controller, + config_entry: MockConfigEntry, + controller: Heos, user_input: dict[str, str], expected_errors: dict[str, str], ) -> None: @@ -343,7 +348,7 @@ async def test_options_flow_missing_one_param_recovers( async def test_reauth_signs_in_aborts( hass: HomeAssistant, config_entry: MockConfigEntry, - controller, + controller: Heos, error: HeosError, expected_error_key: str, ) -> None: @@ -381,7 +386,9 @@ async def test_reauth_signs_in_aborts( 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.""" config_entry.add_to_hass(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( hass: HomeAssistant, - config_entry, - controller, + config_entry: MockConfigEntry, + controller: Heos, user_input: dict[str, str], expected_errors: dict[str, str], ) -> None: diff --git a/tests/components/heos/test_init.py b/tests/components/heos/test_init.py index f802529ac82..1362722390a 100644 --- a/tests/components/heos/test_init.py +++ b/tests/components/heos/test_init.py @@ -4,7 +4,14 @@ import asyncio from typing import cast 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 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.exceptions import ConfigEntryNotReady from homeassistant.helpers import device_registry as dr -from homeassistant.setup import async_setup_component 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( - hass: HomeAssistant, config_entry, controller, input_sources, favorites + hass: HomeAssistant, + config_entry: MockConfigEntry, + controller: Heos, ) -> None: """Test load connects to heos, retrieves players, and loads platforms.""" 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( - hass: HomeAssistant, - config_entry_options, - config, - controller, - input_sources, - favorites, + hass: HomeAssistant, config_entry_options: MockConfigEntry, controller: Heos ) -> None: """Test load connects to heos with options, retrieves players, and loads platforms.""" config_entry_options.add_to_hass(hass) - assert await async_setup_component(hass, DOMAIN, config) - await hass.async_block_till_done() + assert await hass.config_entries.async_setup(config_entry_options.entry_id) # Assert options passed and methods called 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 - assert await async_setup_component(hass, DOMAIN, {}) - await hass.async_block_till_done() + assert await hass.config_entries.async_setup(config_entry_options.entry_id) # Assert entry loaded and reauth flow started 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( hass: HomeAssistant, - config_entry, - controller, - input_sources, + config_entry: MockConfigEntry, + controller: Heos, caplog: pytest.LogCaptureFixture, ) -> None: """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( - hass: HomeAssistant, config_entry, controller + hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos ) -> None: """Connection failure raises ConfigEntryNotReady.""" 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( - hass: HomeAssistant, config_entry, controller + hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos ) -> None: """Failure to retrieve players/sources raises ConfigEntryNotReady.""" config_entry.add_to_hass(hass) @@ -180,7 +156,7 @@ async def test_async_setup_entry_player_failure( 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.""" controller_manager = Mock(ControllerManager) 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( hass: HomeAssistant, - config_entry, - config, - controller, + config_entry: MockConfigEntry, + controller: Heos, caplog: pytest.LogCaptureFixture, ) -> None: """Test update sources retries on failures to max attempts.""" 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_input_sources.reset_mock() source_manager = config_entry.runtime_data.source_manager diff --git a/tests/components/heos/test_media_player.py b/tests/components/heos/test_media_player.py index ea00bc9217a..3dd5312d899 100644 --- a/tests/components/heos/test_media_player.py +++ b/tests/components/heos/test_media_player.py @@ -11,6 +11,7 @@ from pyheos import ( Heos, HeosError, MediaItem, + PlayerUpdateResult, PlayState, SignalHeosEvent, SignalType, @@ -65,25 +66,17 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError, ServiceValidationError from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry -async def setup_platform( - 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() - - +@pytest.mark.usefixtures("controller") async def test_state_attributes( - hass: HomeAssistant, config_entry, config, controller + hass: HomeAssistant, config_entry: MockConfigEntry ) -> None: """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") assert state.state == STATE_IDLE assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0.25 @@ -119,10 +112,11 @@ async def test_state_attributes( async def test_updates_from_signals( - hass: HomeAssistant, config_entry, config, controller, favorites + hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos ) -> None: """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] # 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( hass: HomeAssistant, - config_entry, - config, - controller, + config_entry: MockConfigEntry, + controller: Heos, caplog: pytest.LogCaptureFixture, ) -> None: """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] event = asyncio.Event() @@ -208,10 +202,14 @@ async def test_updates_from_connection_event( 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: """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] event = asyncio.Event() @@ -233,14 +231,13 @@ async def test_updates_from_sources_updated( async def test_updates_from_players_changed( hass: HomeAssistant, - config_entry, - config, - controller, - change_data, - caplog: pytest.LogCaptureFixture, + config_entry: MockConfigEntry, + controller: Heos, + change_data: PlayerUpdateResult, ) -> None: """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] event = asyncio.Event() @@ -263,14 +260,13 @@ async def test_updates_from_players_changed_new_ids( hass: HomeAssistant, entity_registry: er.EntityRegistry, device_registry: dr.DeviceRegistry, - config_entry, - config, - controller, - change_data_mapped_ids, - caplog: pytest.LogCaptureFixture, + config_entry: MockConfigEntry, + controller: Heos, + change_data_mapped_ids: PlayerUpdateResult, ) -> None: """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] event = asyncio.Event() @@ -306,10 +302,11 @@ async def test_updates_from_players_changed_new_ids( async def test_updates_from_user_changed( - hass: HomeAssistant, config_entry, config, controller + hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos ) -> None: """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] event = asyncio.Event() @@ -660,10 +657,14 @@ async def test_volume_set_error( async def test_select_favorite( - hass: HomeAssistant, config_entry, config, controller, favorites + hass: HomeAssistant, + config_entry: MockConfigEntry, + controller: Heos, + favorites: dict[int, MediaItem], ) -> None: """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] # Test set music service preset favorite = favorites[1] @@ -685,10 +686,14 @@ async def test_select_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: """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] # Test set radio preset favorite = favorites[2] @@ -740,10 +745,14 @@ async def test_select_radio_favorite_command_error( 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: """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] # Test proper service called 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) +@pytest.mark.usefixtures("controller") async def test_unload_config_entry( - hass: HomeAssistant, config_entry, config, controller + hass: HomeAssistant, config_entry: MockConfigEntry ) -> None: """Test the player is set unavailable when the config entry is unloaded.""" - await setup_platform(hass, config_entry, config) - await hass.config_entries.async_unload(config_entry.entry_id) + config_entry.add_to_hass(hass) + 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 @@ -1112,14 +1123,13 @@ async def test_media_player_join_group_error( async def test_media_player_group_members( hass: HomeAssistant, - config_entry, - config, - controller, + config_entry: MockConfigEntry, + controller: Heos, caplog: pytest.LogCaptureFixture, ) -> None: """Test group_members attribute.""" - await setup_platform(hass, config_entry, config) - await hass.async_block_till_done() + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) player_entity = hass.states.get("media_player.test_player") assert player_entity.attributes[ATTR_GROUP_MEMBERS] == [ "media_player.test_player", @@ -1131,15 +1141,14 @@ async def test_media_player_group_members( async def test_media_player_group_members_error( hass: HomeAssistant, - config_entry, - config, - controller, + config_entry: MockConfigEntry, + controller: Heos, caplog: pytest.LogCaptureFixture, ) -> None: """Test error in HEOS API.""" controller.get_groups.side_effect = HeosError("error") - await setup_platform(hass, config_entry, config) - await hass.async_block_till_done() + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) assert "Unable to get HEOS group info" in caplog.text player_entity = hass.states.get("media_player.test_player") assert player_entity.attributes[ATTR_GROUP_MEMBERS] == [] diff --git a/tests/components/heos/test_services.py b/tests/components/heos/test_services.py index 175e072e8e7..92ecc1f179d 100644 --- a/tests/components/heos/test_services.py +++ b/tests/components/heos/test_services.py @@ -1,6 +1,6 @@ """Tests for the services module.""" -from pyheos import CommandAuthenticationError, HeosError +from pyheos import CommandAuthenticationError, Heos, HeosError import pytest from homeassistant.components.heos.const import ( @@ -12,21 +12,16 @@ from homeassistant.components.heos.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry -async def setup_component(hass: HomeAssistant, config_entry: MockConfigEntry) -> None: - """Set up the component for testing.""" - config_entry.add_to_hass(hass) - assert await async_setup_component(hass, DOMAIN, {}) - await hass.async_block_till_done() - - -async def test_sign_in(hass: HomeAssistant, config_entry, controller) -> None: +async def test_sign_in( + hass: HomeAssistant, config_entry: MockConfigEntry, controller: Heos +) -> None: """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( DOMAIN, @@ -39,10 +34,15 @@ async def test_sign_in(hass: HomeAssistant, config_entry, controller) -> None: 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: """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( "", "Invalid credentials", 6 ) @@ -59,10 +59,15 @@ async def test_sign_in_failed( 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: """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() await hass.services.async_call( @@ -76,10 +81,14 @@ async def test_sign_in_unknown_error( 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.""" - await setup_component(hass, config_entry) - await hass.config_entries.async_unload(config_entry.entry_id) + config_entry.add_to_hass(hass) + 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"): 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.""" - 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) 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.""" - await setup_component(hass, config_entry) - await hass.config_entries.async_unload(config_entry.entry_id) + config_entry.add_to_hass(hass) + 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"): await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True) 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: """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() await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)