From 2333c10915ed2227632cd394f5a8b5745b38976f Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 12 May 2025 09:13:23 +0200 Subject: [PATCH] Rename samsung legacy test fixtures and constants (#144715) * Rename samsung legacy test fixtures and constants * More --- tests/components/samsungtv/conftest.py | 17 +- tests/components/samsungtv/const.py | 8 +- .../components/samsungtv/test_config_flow.py | 95 ++++----- tests/components/samsungtv/test_init.py | 2 +- .../components/samsungtv/test_media_player.py | 188 +++++++++--------- tests/components/samsungtv/test_remote.py | 8 +- 6 files changed, 157 insertions(+), 161 deletions(-) diff --git a/tests/components/samsungtv/conftest.py b/tests/components/samsungtv/conftest.py index c33fd89ec56..024a06617a5 100644 --- a/tests/components/samsungtv/conftest.py +++ b/tests/components/samsungtv/conftest.py @@ -148,15 +148,16 @@ def upnp_notify_server_fixture(upnp_factory: Mock) -> Generator[Mock]: yield notify_server -@pytest.fixture(name="remote") -def remote_fixture() -> Generator[Mock]: +@pytest.fixture(name="remote_legacy") +def remote_legacy_fixture() -> Generator[Mock]: """Patch the samsungctl Remote.""" - with patch("homeassistant.components.samsungtv.bridge.Remote") as remote_class: - remote = Mock(Remote) - remote.__enter__ = Mock() - remote.__exit__ = Mock() - remote_class.return_value = remote - yield remote + remote_legacy = Mock(Remote) + remote_legacy.__enter__ = Mock() + remote_legacy.__exit__ = Mock() + with patch( + "homeassistant.components.samsungtv.bridge.Remote", return_value=remote_legacy + ): + yield remote_legacy @pytest.fixture(name="rest_api") diff --git a/tests/components/samsungtv/const.py b/tests/components/samsungtv/const.py index 7078f088217..e4acc41d1c2 100644 --- a/tests/components/samsungtv/const.py +++ b/tests/components/samsungtv/const.py @@ -3,6 +3,7 @@ from homeassistant.components.samsungtv.const import ( CONF_SESSION_ID, DOMAIN, + LEGACY_PORT, METHOD_LEGACY, METHOD_WEBSOCKET, ) @@ -19,10 +20,9 @@ from homeassistant.helpers.service_info.ssdp import SsdpServiceInfo from tests.common import load_json_object_fixture -MOCK_CONFIG = { - CONF_HOST: "fake_host", - CONF_NAME: "fake", - CONF_PORT: 55000, +ENTRYDATA_LEGACY = { + CONF_HOST: "10.10.12.34", + CONF_PORT: LEGACY_PORT, CONF_METHOD: METHOD_LEGACY, } MOCK_CONFIG_ENCRYPTED_WS = { diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index 504eccc4f12..d57a594e5dc 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -26,6 +26,7 @@ from homeassistant.components.samsungtv.const import ( DEFAULT_MANUFACTURER, DOMAIN, LEGACY_PORT, + METHOD_LEGACY, RESULT_AUTH_MISSING, RESULT_CANNOT_CONNECT, RESULT_NOT_SUPPORTED, @@ -54,6 +55,7 @@ from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo from homeassistant.setup import async_setup_component from .const import ( + ENTRYDATA_LEGACY, MOCK_ENTRYDATA_ENCRYPTED_WS, MOCK_ENTRYDATA_WS, MOCK_SSDP_DATA, @@ -71,7 +73,6 @@ MOCK_USER_DATA = {CONF_HOST: "fake_host"} MOCK_DHCP_DATA = DhcpServiceInfo( ip="10.10.12.34", macaddress="aabbccddeeff", hostname="fake_hostname" ) -EXISTING_IP = "192.168.40.221" MOCK_ZEROCONF_DATA = ZeroconfServiceInfo( ip_address=ip_address("127.0.0.1"), ip_addresses=[ip_address("127.0.0.1")], @@ -86,16 +87,6 @@ MOCK_ZEROCONF_DATA = ZeroconfServiceInfo( }, type="mock_type", ) -MOCK_OLD_ENTRY = { - CONF_HOST: "10.10.12.34", - CONF_METHOD: "legacy", - CONF_PORT: None, -} -MOCK_LEGACY_ENTRY = { - CONF_HOST: EXISTING_IP, - CONF_METHOD: "legacy", - CONF_PORT: None, -} MOCK_DEVICE_INFO = { "device": { "type": "Samsung SmartTV", @@ -109,7 +100,7 @@ AUTODETECT_LEGACY = { "name": "HomeAssistant", "description": "HomeAssistant", "id": "ha.component.samsung", - "method": "legacy", + "method": METHOD_LEGACY, "port": LEGACY_PORT, "host": "fake_host", "timeout": TIMEOUT_REQUEST, @@ -144,7 +135,7 @@ DEVICEINFO_WEBSOCKET_NO_SSL = { pytestmark = pytest.mark.usefixtures("mock_setup_entry") -@pytest.mark.usefixtures("remote", "rest_api_failing") +@pytest.mark.usefixtures("remote_legacy", "rest_api_failing") async def test_user_legacy(hass: HomeAssistant) -> None: """Test starting a flow by user.""" # show form @@ -162,7 +153,7 @@ async def test_user_legacy(hass: HomeAssistant) -> None: assert result["type"] is FlowResultType.CREATE_ENTRY assert result["title"] == "fake_host" assert result["data"][CONF_HOST] == "fake_host" - assert result["data"][CONF_METHOD] == "legacy" + assert result["data"][CONF_METHOD] == METHOD_LEGACY assert result["data"][CONF_MANUFACTURER] == DEFAULT_MANUFACTURER assert result["data"][CONF_MODEL] is None assert result["result"].unique_id is None @@ -196,7 +187,7 @@ async def test_user_legacy_does_not_ok_first_time(hass: HomeAssistant) -> None: assert result3["type"] is FlowResultType.CREATE_ENTRY assert result3["title"] == "fake_host" assert result3["data"][CONF_HOST] == "fake_host" - assert result3["data"][CONF_METHOD] == "legacy" + assert result3["data"][CONF_METHOD] == METHOD_LEGACY assert result3["data"][CONF_MANUFACTURER] == DEFAULT_MANUFACTURER assert result3["data"][CONF_MODEL] is None assert result3["result"].unique_id is None @@ -447,7 +438,7 @@ async def test_user_not_successful_2(hass: HomeAssistant) -> None: assert result["reason"] == RESULT_CANNOT_CONNECT -@pytest.mark.usefixtures("remote", "rest_api_failing") +@pytest.mark.usefixtures("remote_legacy", "rest_api_failing") async def test_ssdp(hass: HomeAssistant) -> None: """Test starting a flow from discovery.""" # confirm to add the entry @@ -469,7 +460,7 @@ async def test_ssdp(hass: HomeAssistant) -> None: assert result["result"].unique_id == "068e7781-006e-1000-bbbf-84a4668d8423" -@pytest.mark.usefixtures("remote", "rest_api_failing") +@pytest.mark.usefixtures("remote_legacy", "rest_api_failing") async def test_ssdp_no_manufacturer(hass: HomeAssistant) -> None: """Test starting a flow from discovery when the manufacturer data is missing.""" ssdp_data = deepcopy(MOCK_SSDP_DATA) @@ -487,7 +478,7 @@ async def test_ssdp_no_manufacturer(hass: HomeAssistant) -> None: @pytest.mark.parametrize( "data", [MOCK_SSDP_DATA_MAIN_TV_AGENT_ST, MOCK_SSDP_DATA_RENDERING_CONTROL_ST] ) -@pytest.mark.usefixtures("remote", "rest_api_failing") +@pytest.mark.usefixtures("remote_legacy", "rest_api_failing") async def test_ssdp_legacy_not_remote_control_receiver_udn( hass: HomeAssistant, data: SsdpServiceInfo ) -> None: @@ -499,7 +490,7 @@ async def test_ssdp_legacy_not_remote_control_receiver_udn( assert result["reason"] == RESULT_NOT_SUPPORTED -@pytest.mark.usefixtures("remote", "rest_api_failing") +@pytest.mark.usefixtures("remote_legacy", "rest_api_failing") async def test_ssdp_noprefix(hass: HomeAssistant) -> None: """Test starting a flow from discovery when friendly name doesn't start with [TV].""" ssdp_data = deepcopy(MOCK_SSDP_DATA) @@ -731,7 +722,7 @@ async def test_ssdp_websocket_cannot_connect(hass: HomeAssistant) -> None: assert result["reason"] == RESULT_CANNOT_CONNECT -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_ssdp_wrong_manufacturer(hass: HomeAssistant) -> None: """Test starting a flow from discovery.""" ssdp_data = deepcopy(MOCK_SSDP_DATA) @@ -810,7 +801,7 @@ async def test_ssdp_not_successful_2(hass: HomeAssistant) -> None: assert result["reason"] == RESULT_CANNOT_CONNECT -@pytest.mark.usefixtures("remote", "remoteencws_failing") +@pytest.mark.usefixtures("remote_legacy", "remoteencws_failing") async def test_ssdp_already_in_progress(hass: HomeAssistant) -> None: """Test starting a flow from discovery twice.""" with patch( @@ -1036,7 +1027,7 @@ async def test_zeroconf_ignores_soundbar(hass: HomeAssistant, rest_api: Mock) -> assert result["reason"] == RESULT_NOT_SUPPORTED -@pytest.mark.usefixtures("remote", "remotews", "remoteencws", "rest_api_failing") +@pytest.mark.usefixtures("remote_legacy", "remotews", "remoteencws", "rest_api_failing") async def test_zeroconf_no_device_info(hass: HomeAssistant) -> None: """Test starting a flow from zeroconf where device_info returns None.""" result = await hass.config_entries.flow.async_init( @@ -1217,14 +1208,14 @@ async def test_autodetect_not_supported(hass: HomeAssistant) -> None: assert remote.call_args_list == [call(AUTODETECT_LEGACY)] -@pytest.mark.usefixtures("remote", "rest_api_failing") +@pytest.mark.usefixtures("remote_legacy", "rest_api_failing") async def test_autodetect_legacy(hass: HomeAssistant) -> None: """Test for send key with autodetection of protocol.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["data"][CONF_METHOD] == "legacy" + assert result["data"][CONF_METHOD] == METHOD_LEGACY assert result["data"][CONF_MAC] is None assert result["data"][CONF_PORT] == LEGACY_PORT @@ -1256,7 +1247,7 @@ async def test_autodetect_none(hass: HomeAssistant) -> None: @pytest.mark.usefixtures("remotews", "rest_api", "remoteencws_failing") async def test_update_old_entry(hass: HomeAssistant) -> None: """Test update of old entry sets unique id.""" - entry = MockConfigEntry(domain=DOMAIN, data=MOCK_OLD_ENTRY) + entry = MockConfigEntry(domain=DOMAIN, data=ENTRYDATA_LEGACY) entry.add_to_hass(hass) config_entries_domain = hass.config_entries.async_entries(DOMAIN) @@ -1287,7 +1278,7 @@ async def test_update_missing_mac_unique_id_added_from_dhcp( hass: HomeAssistant, mock_setup_entry: AsyncMock ) -> None: """Test missing mac and unique id added.""" - entry = MockConfigEntry(domain=DOMAIN, data=MOCK_OLD_ENTRY, unique_id=None) + entry = MockConfigEntry(domain=DOMAIN, data=ENTRYDATA_LEGACY, unique_id=None) entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( @@ -1309,7 +1300,7 @@ async def test_update_incorrectly_formatted_mac_unique_id_added_from_dhcp( hass: HomeAssistant, mock_setup_entry: AsyncMock ) -> None: """Test incorrectly formatted mac is updated and unique id added.""" - entry_data = MOCK_OLD_ENTRY.copy() + entry_data = ENTRYDATA_LEGACY.copy() entry_data[CONF_MAC] = "aabbccddeeff" entry = MockConfigEntry(domain=DOMAIN, data=entry_data, unique_id=None) entry.add_to_hass(hass) @@ -1334,7 +1325,9 @@ async def test_update_missing_mac_unique_id_added_from_zeroconf( ) -> None: """Test missing mac and unique id added.""" entry = MockConfigEntry( - domain=DOMAIN, data={**MOCK_OLD_ENTRY, "host": "127.0.0.1"}, unique_id=None + domain=DOMAIN, + data={**ENTRYDATA_LEGACY, "host": "127.0.0.1"}, + unique_id=None, ) entry.add_to_hass(hass) @@ -1352,14 +1345,14 @@ async def test_update_missing_mac_unique_id_added_from_zeroconf( assert entry.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4" -@pytest.mark.usefixtures("remote", "rest_api_failing") +@pytest.mark.usefixtures("remote_legacy", "rest_api_failing") async def test_update_missing_model_added_from_ssdp( hass: HomeAssistant, mock_setup_entry: AsyncMock ) -> None: """Test missing model added via ssdp on legacy models.""" entry = MockConfigEntry( domain=DOMAIN, - data=MOCK_OLD_ENTRY, + data=ENTRYDATA_LEGACY, unique_id=None, ) entry.add_to_hass(hass) @@ -1382,7 +1375,7 @@ async def test_update_missing_mac_unique_id_ssdp_location_added_from_ssdp( hass: HomeAssistant, mock_setup_entry: AsyncMock ) -> None: """Test missing mac, ssdp_location, and unique id added via ssdp.""" - entry = MockConfigEntry(domain=DOMAIN, data=MOCK_OLD_ENTRY, unique_id=None) + entry = MockConfigEntry(domain=DOMAIN, data=ENTRYDATA_LEGACY, unique_id=None) entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( @@ -1402,7 +1395,7 @@ async def test_update_missing_mac_unique_id_ssdp_location_added_from_ssdp( @pytest.mark.usefixtures( - "remote", "remotews", "remoteencws_failing", "rest_api_failing" + "remote_legacy", "remotews", "remoteencws_failing", "rest_api_failing" ) async def test_update_zeroconf_discovery_preserved_unique_id( hass: HomeAssistant, @@ -1410,7 +1403,7 @@ async def test_update_zeroconf_discovery_preserved_unique_id( """Test zeroconf discovery preserves unique id.""" entry = MockConfigEntry( domain=DOMAIN, - data={**MOCK_OLD_ENTRY, CONF_MAC: "aa:bb:zz:ee:rr:oo"}, + data={**ENTRYDATA_LEGACY, CONF_MAC: "aa:bb:zz:ee:rr:oo"}, unique_id="original", ) entry.add_to_hass(hass) @@ -1434,7 +1427,7 @@ async def test_update_missing_mac_unique_id_added_ssdp_location_updated_from_ssd entry = MockConfigEntry( domain=DOMAIN, data={ - **MOCK_OLD_ENTRY, + **ENTRYDATA_LEGACY, CONF_SSDP_RENDERING_CONTROL_LOCATION: "https://1.2.3.4:555/test", }, unique_id=None, @@ -1467,7 +1460,7 @@ async def test_update_missing_mac_unique_id_added_ssdp_location_rendering_st_upd entry = MockConfigEntry( domain=DOMAIN, data={ - **MOCK_OLD_ENTRY, + **ENTRYDATA_LEGACY, CONF_SSDP_RENDERING_CONTROL_LOCATION: "https://1.2.3.4:555/test", }, unique_id=None, @@ -1501,7 +1494,7 @@ async def test_update_missing_mac_unique_id_added_ssdp_location_main_tv_agent_st entry = MockConfigEntry( domain=DOMAIN, data={ - **MOCK_OLD_ENTRY, + **ENTRYDATA_LEGACY, CONF_SSDP_RENDERING_CONTROL_LOCATION: "https://1.2.3.4:555/test", CONF_SSDP_MAIN_TV_AGENT_LOCATION: "https://1.2.3.4:555/test", }, @@ -1538,7 +1531,7 @@ async def test_update_ssdp_location_rendering_st_updated_from_ssdp( """Test with outdated ssdp_location with the correct st added via ssdp.""" entry = MockConfigEntry( domain=DOMAIN, - data={**MOCK_OLD_ENTRY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, + data={**ENTRYDATA_LEGACY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, unique_id="be9554b9-c9fb-41f4-8920-22da015376a4", ) entry.add_to_hass(hass) @@ -1569,7 +1562,7 @@ async def test_update_main_tv_ssdp_location_rendering_st_updated_from_ssdp( """Test with outdated ssdp_location with the correct st added via ssdp.""" entry = MockConfigEntry( domain=DOMAIN, - data={**MOCK_OLD_ENTRY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, + data={**ENTRYDATA_LEGACY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, unique_id="be9554b9-c9fb-41f4-8920-22da015376a4", ) entry.add_to_hass(hass) @@ -1599,7 +1592,7 @@ async def test_update_missing_mac_added_unique_id_preserved_from_zeroconf( """Test missing mac and unique id added.""" entry = MockConfigEntry( domain=DOMAIN, - data={**MOCK_OLD_ENTRY, "host": "127.0.0.1"}, + data={**ENTRYDATA_LEGACY, "host": "127.0.0.1"}, unique_id="0d1cef00-00dc-1000-9c80-4844f7b172de", ) entry.add_to_hass(hass) @@ -1618,14 +1611,14 @@ async def test_update_missing_mac_added_unique_id_preserved_from_zeroconf( assert entry.unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de" -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_update_legacy_missing_mac_from_dhcp( hass: HomeAssistant, mock_setup_entry: AsyncMock ) -> None: """Test missing mac added.""" entry = MockConfigEntry( domain=DOMAIN, - data=MOCK_LEGACY_ENTRY, + data=ENTRYDATA_LEGACY, unique_id="0d1cef00-00dc-1000-9c80-4844f7b172de", ) entry.add_to_hass(hass) @@ -1634,7 +1627,7 @@ async def test_update_legacy_missing_mac_from_dhcp( DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=DhcpServiceInfo( - ip=EXISTING_IP, macaddress="aabbccddeeff", hostname="fake_hostname" + ip="10.10.12.34", macaddress="aabbccddeeff", hostname="fake_hostname" ), ) await hass.async_block_till_done() @@ -1646,7 +1639,7 @@ async def test_update_legacy_missing_mac_from_dhcp( assert entry.unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de" -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_update_legacy_missing_mac_from_dhcp_no_unique_id( hass: HomeAssistant, rest_api: Mock, mock_setup_entry: AsyncMock ) -> None: @@ -1654,7 +1647,7 @@ async def test_update_legacy_missing_mac_from_dhcp_no_unique_id( rest_api.rest_device_info.side_effect = HttpApiError entry = MockConfigEntry( domain=DOMAIN, - data=MOCK_LEGACY_ENTRY, + data=ENTRYDATA_LEGACY, ) entry.add_to_hass(hass) with ( @@ -1671,7 +1664,7 @@ async def test_update_legacy_missing_mac_from_dhcp_no_unique_id( DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=DhcpServiceInfo( - ip=EXISTING_IP, macaddress="aabbccddeeff", hostname="fake_hostname" + ip="10.10.12.34", macaddress="aabbccddeeff", hostname="fake_hostname" ), ) await hass.async_block_till_done() @@ -1690,7 +1683,7 @@ async def test_update_ssdp_location_unique_id_added_from_ssdp( """Test missing ssdp_location, and unique id added via ssdp.""" entry = MockConfigEntry( domain=DOMAIN, - data={**MOCK_OLD_ENTRY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, + data={**ENTRYDATA_LEGACY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, unique_id=None, ) entry.add_to_hass(hass) @@ -1718,7 +1711,7 @@ async def test_update_ssdp_location_unique_id_added_from_ssdp_with_rendering_con """Test missing ssdp_location, and unique id added via ssdp with rendering control st.""" entry = MockConfigEntry( domain=DOMAIN, - data={**MOCK_OLD_ENTRY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, + data={**ENTRYDATA_LEGACY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, unique_id=None, ) entry.add_to_hass(hass) @@ -1742,10 +1735,10 @@ async def test_update_ssdp_location_unique_id_added_from_ssdp_with_rendering_con assert entry.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4" -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_form_reauth_legacy(hass: HomeAssistant) -> None: """Test reauthenticate legacy.""" - entry = MockConfigEntry(domain=DOMAIN, data=MOCK_OLD_ENTRY) + entry = MockConfigEntry(domain=DOMAIN, data=ENTRYDATA_LEGACY) entry.add_to_hass(hass) result = await entry.start_reauth_flow(hass) assert result["type"] is FlowResultType.FORM @@ -1911,7 +1904,7 @@ async def test_update_incorrect_udn_matching_upnp_udn_unique_id_added_from_ssdp( """Test updating the wrong udn from ssdp via upnp udn match.""" entry = MockConfigEntry( domain=DOMAIN, - data=MOCK_OLD_ENTRY, + data=ENTRYDATA_LEGACY, unique_id="068e7781-006e-1000-bbbf-84a4668d8423", ) entry.add_to_hass(hass) @@ -1937,7 +1930,7 @@ async def test_update_incorrect_udn_matching_mac_unique_id_added_from_ssdp( """Test updating the wrong udn from ssdp via mac match.""" entry = MockConfigEntry( domain=DOMAIN, - data={**MOCK_OLD_ENTRY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, + data={**ENTRYDATA_LEGACY, CONF_MAC: "aa:bb:aa:aa:aa:aa"}, unique_id=None, ) entry.add_to_hass(hass) diff --git a/tests/components/samsungtv/test_init.py b/tests/components/samsungtv/test_init.py index 7e0d1c87fb1..d1d51a597c5 100644 --- a/tests/components/samsungtv/test_init.py +++ b/tests/components/samsungtv/test_init.py @@ -179,7 +179,7 @@ async def test_reauth_triggered_encrypted(hass: HomeAssistant) -> None: assert len(flows_in_progress) == 1 -@pytest.mark.usefixtures("remote", "remotews", "rest_api_failing") +@pytest.mark.usefixtures("remote_legacy", "remotews", "rest_api_failing") async def test_update_imported_legacy_without_method(hass: HomeAssistant) -> None: """Test updating an imported legacy entry without a method.""" await setup_samsungtv_entry( diff --git a/tests/components/samsungtv/test_media_player.py b/tests/components/samsungtv/test_media_player.py index 9171c49ef06..dba9c790825 100644 --- a/tests/components/samsungtv/test_media_player.py +++ b/tests/components/samsungtv/test_media_player.py @@ -81,7 +81,7 @@ from homeassistant.setup import async_setup_component from . import setup_samsungtv_entry from .const import ( - MOCK_CONFIG, + ENTRYDATA_LEGACY, MOCK_ENTRY_WS_WITH_MAC, MOCK_ENTRYDATA_ENCRYPTED_WS, SAMPLE_DEVICE_INFO_WIFI, @@ -119,10 +119,10 @@ MOCK_ENTRY_WS = { } -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_setup(hass: HomeAssistant) -> None: """Test setup of platform.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) assert hass.states.get(ENTITY_ID) @@ -212,10 +212,10 @@ async def test_setup_encrypted_websocket( remote_class.assert_called_once() -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_update_on(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None: """Testing update tv on.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) freezer.tick(timedelta(minutes=5)) async_fire_time_changed(hass) @@ -225,10 +225,10 @@ async def test_update_on(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> assert state.state == STATE_ON -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_update_off(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None: """Testing update tv off.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) with patch( "homeassistant.components.samsungtv.bridge.Remote", @@ -359,12 +359,12 @@ async def test_update_off_encryptedws( rest_api.rest_device_info.assert_called_once() -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_update_access_denied( hass: HomeAssistant, freezer: FrozenDateTimeFactory ) -> None: """Testing update tv access denied exception.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) with patch( "homeassistant.components.samsungtv.bridge.Remote", @@ -464,12 +464,12 @@ async def test_update_ws_unauthorized_error( assert state.state == STATE_UNAVAILABLE -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_update_unhandled_response( hass: HomeAssistant, freezer: FrozenDateTimeFactory ) -> None: """Testing update tv unhandled response exception.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) with patch( "homeassistant.components.samsungtv.bridge.Remote", @@ -483,12 +483,12 @@ async def test_update_unhandled_response( assert state.state == STATE_ON -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_connection_closed_during_update_can_recover( hass: HomeAssistant, freezer: FrozenDateTimeFactory ) -> None: """Testing update tv connection closed exception can recover.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) with patch( "homeassistant.components.samsungtv.bridge.Remote", @@ -509,23 +509,23 @@ async def test_connection_closed_during_update_can_recover( assert state.state == STATE_ON -async def test_send_key(hass: HomeAssistant, remote: Mock) -> None: +async def test_send_key(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for send key.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True ) state = hass.states.get(ENTITY_ID) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_VOLUP")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_VOLUP")] assert state.state == STATE_ON -async def test_send_key_broken_pipe(hass: HomeAssistant, remote: Mock) -> None: +async def test_send_key_broken_pipe(hass: HomeAssistant, remote_legacy: Mock) -> None: """Testing broken pipe Exception.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) - remote.control = Mock(side_effect=BrokenPipeError("Boom")) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) + remote_legacy.control = Mock(side_effect=BrokenPipeError("Boom")) await hass.services.async_call( MP_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True ) @@ -534,11 +534,11 @@ async def test_send_key_broken_pipe(hass: HomeAssistant, remote: Mock) -> None: async def test_send_key_connection_closed_retry_succeed( - hass: HomeAssistant, remote: Mock + hass: HomeAssistant, remote_legacy: Mock ) -> None: """Test retry on connection closed.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) - remote.control = Mock( + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) + remote_legacy.control = Mock( side_effect=[exceptions.ConnectionClosed("Boom"), DEFAULT_MOCK, DEFAULT_MOCK] ) await hass.services.async_call( @@ -546,18 +546,20 @@ async def test_send_key_connection_closed_retry_succeed( ) state = hass.states.get(ENTITY_ID) # key because of retry two times - assert remote.control.call_count == 2 - assert remote.control.call_args_list == [ + assert remote_legacy.control.call_count == 2 + assert remote_legacy.control.call_args_list == [ call("KEY_VOLUP"), call("KEY_VOLUP"), ] assert state.state == STATE_ON -async def test_send_key_unhandled_response(hass: HomeAssistant, remote: Mock) -> None: +async def test_send_key_unhandled_response( + hass: HomeAssistant, remote_legacy: Mock +) -> None: """Testing unhandled response exception.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) - remote.control = Mock(side_effect=exceptions.UnhandledResponse("Boom")) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) + remote_legacy.control = Mock(side_effect=exceptions.UnhandledResponse("Boom")) with pytest.raises(HomeAssistantError) as err: await hass.services.async_call( MP_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True @@ -619,10 +621,10 @@ async def test_send_key_os_error_ws_encrypted( assert state.state == STATE_ON -async def test_send_key_os_error(hass: HomeAssistant, remote: Mock) -> None: +async def test_send_key_os_error(hass: HomeAssistant, remote_legacy: Mock) -> None: """Testing broken pipe Exception.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) - remote.control = Mock(side_effect=OSError("Boom")) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) + remote_legacy.control = Mock(side_effect=OSError("Boom")) await hass.services.async_call( MP_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True ) @@ -630,18 +632,18 @@ async def test_send_key_os_error(hass: HomeAssistant, remote: Mock) -> None: assert state.state == STATE_ON -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_name(hass: HomeAssistant) -> None: """Test for name property.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) state = hass.states.get(ENTITY_ID) assert state.attributes[ATTR_FRIENDLY_NAME] == "Mock Title" -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_state(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None: """Test for state property.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True ) @@ -667,18 +669,18 @@ async def test_state(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> Non assert state.state == STATE_UNAVAILABLE -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_supported_features(hass: HomeAssistant) -> None: """Test for supported_features property.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) state = hass.states.get(ENTITY_ID) assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_SAMSUNGTV -@pytest.mark.usefixtures("remote") +@pytest.mark.usefixtures("remote_legacy") async def test_device_class(hass: HomeAssistant) -> None: """Test for device_class property.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) state = hass.states.get(ENTITY_ID) assert state.attributes[ATTR_DEVICE_CLASS] == MediaPlayerDeviceClass.TV @@ -821,24 +823,24 @@ async def test_turn_off_encrypted_websocket_key_type( assert "Unknown power_off command for" not in caplog.text -async def test_turn_off_legacy(hass: HomeAssistant, remote: Mock) -> None: +async def test_turn_off_legacy(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for turn_off.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_POWEROFF")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_POWEROFF")] async def test_turn_off_os_error( - hass: HomeAssistant, remote: Mock, caplog: pytest.LogCaptureFixture + hass: HomeAssistant, remote_legacy: Mock, caplog: pytest.LogCaptureFixture ) -> None: """Test for turn_off with OSError.""" caplog.set_level(logging.DEBUG) - await setup_samsungtv_entry(hass, MOCK_CONFIG) - remote.close = Mock(side_effect=OSError("BOOM")) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) + remote_legacy.close = Mock(side_effect=OSError("BOOM")) await hass.services.async_call( MP_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_ID}, True ) @@ -873,31 +875,31 @@ async def test_turn_off_encryptedws_os_error( assert "Error closing connection" in caplog.text -async def test_volume_up(hass: HomeAssistant, remote: Mock) -> None: +async def test_volume_up(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for volume_up.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_VOLUP")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_VOLUP")] -async def test_volume_down(hass: HomeAssistant, remote: Mock) -> None: +async def test_volume_down(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for volume_down.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_VOLUME_DOWN, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_VOLDOWN")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_VOLDOWN")] -async def test_mute_volume(hass: HomeAssistant, remote: Mock) -> None: +async def test_mute_volume(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for mute_volume.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_VOLUME_MUTE, @@ -905,66 +907,66 @@ async def test_mute_volume(hass: HomeAssistant, remote: Mock) -> None: True, ) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_MUTE")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_MUTE")] -async def test_media_play(hass: HomeAssistant, remote: Mock) -> None: +async def test_media_play(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for media_play.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_MEDIA_PLAY, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_PLAY")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_PLAY")] await hass.services.async_call( MP_DOMAIN, SERVICE_MEDIA_PLAY_PAUSE, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # key called - assert remote.control.call_count == 2 - assert remote.control.call_args_list == [call("KEY_PLAY"), call("KEY_PAUSE")] + assert remote_legacy.control.call_count == 2 + assert remote_legacy.control.call_args_list == [call("KEY_PLAY"), call("KEY_PAUSE")] -async def test_media_pause(hass: HomeAssistant, remote: Mock) -> None: +async def test_media_pause(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for media_pause.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_MEDIA_PAUSE, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_PAUSE")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_PAUSE")] await hass.services.async_call( MP_DOMAIN, SERVICE_MEDIA_PLAY_PAUSE, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # key called - assert remote.control.call_count == 2 - assert remote.control.call_args_list == [call("KEY_PAUSE"), call("KEY_PLAY")] + assert remote_legacy.control.call_count == 2 + assert remote_legacy.control.call_args_list == [call("KEY_PAUSE"), call("KEY_PLAY")] -async def test_media_next_track(hass: HomeAssistant, remote: Mock) -> None: +async def test_media_next_track(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for media_next_track.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_MEDIA_NEXT_TRACK, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_CHUP")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_CHUP")] -async def test_media_previous_track(hass: HomeAssistant, remote: Mock) -> None: +async def test_media_previous_track(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for media_previous_track.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_MEDIA_PREVIOUS_TRACK, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_CHDOWN")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_CHDOWN")] @pytest.mark.usefixtures("remotews", "rest_api") @@ -988,21 +990,21 @@ async def test_turn_on_wol(hass: HomeAssistant) -> None: assert mock_send_magic_packet.called -async def test_turn_on_without_turnon(hass: HomeAssistant, remote: Mock) -> None: +async def test_turn_on_without_turnon(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test turn on.""" await async_setup_component(hass, "homeassistant", {}) - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) with pytest.raises(ServiceNotSupported, match="does not support action"): await hass.services.async_call( MP_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # nothing called as not supported feature - assert remote.control.call_count == 0 + assert remote_legacy.control.call_count == 0 -async def test_play_media(hass: HomeAssistant, remote: Mock) -> None: +async def test_play_media(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for play_media.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) with patch("homeassistant.components.samsungtv.bridge.asyncio.sleep") as sleep: await hass.services.async_call( MP_DOMAIN, @@ -1015,8 +1017,8 @@ async def test_play_media(hass: HomeAssistant, remote: Mock) -> None: True, ) # keys and update called - assert remote.control.call_count == 4 - assert remote.control.call_args_list == [ + assert remote_legacy.control.call_count == 4 + assert remote_legacy.control.call_args_list == [ call("KEY_5"), call("KEY_7"), call("KEY_6"), @@ -1029,7 +1031,7 @@ async def test_play_media_invalid_type(hass: HomeAssistant) -> None: """Test for play_media with invalid media type.""" with patch("homeassistant.components.samsungtv.bridge.Remote") as remote: url = "https://example.com" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) remote.reset_mock() await hass.services.async_call( MP_DOMAIN, @@ -1049,7 +1051,7 @@ async def test_play_media_channel_as_string(hass: HomeAssistant) -> None: """Test for play_media with invalid channel as string.""" with patch("homeassistant.components.samsungtv.bridge.Remote") as remote: url = "https://example.com" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) remote.reset_mock() await hass.services.async_call( MP_DOMAIN, @@ -1068,7 +1070,7 @@ async def test_play_media_channel_as_string(hass: HomeAssistant) -> None: async def test_play_media_channel_as_non_positive(hass: HomeAssistant) -> None: """Test for play_media with invalid channel as non positive integer.""" with patch("homeassistant.components.samsungtv.bridge.Remote") as remote: - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) remote.reset_mock() await hass.services.async_call( MP_DOMAIN, @@ -1084,9 +1086,9 @@ async def test_play_media_channel_as_non_positive(hass: HomeAssistant) -> None: assert remote.control.call_count == 0 -async def test_select_source(hass: HomeAssistant, remote: Mock) -> None: +async def test_select_source(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test for select_source.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) await hass.services.async_call( MP_DOMAIN, SERVICE_SELECT_SOURCE, @@ -1094,8 +1096,8 @@ async def test_select_source(hass: HomeAssistant, remote: Mock) -> None: True, ) # key called - assert remote.control.call_count == 1 - assert remote.control.call_args_list == [call("KEY_HDMI")] + assert remote_legacy.control.call_count == 1 + assert remote_legacy.control.call_args_list == [call("KEY_HDMI")] async def test_select_source_invalid_source(hass: HomeAssistant) -> None: @@ -1104,7 +1106,7 @@ async def test_select_source_invalid_source(hass: HomeAssistant) -> None: source = "INVALID" with patch("homeassistant.components.samsungtv.bridge.Remote") as remote: - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) remote.reset_mock() with pytest.raises(HomeAssistantError) as exc_info: await hass.services.async_call( diff --git a/tests/components/samsungtv/test_remote.py b/tests/components/samsungtv/test_remote.py index 4149352ba3f..9f847d87395 100644 --- a/tests/components/samsungtv/test_remote.py +++ b/tests/components/samsungtv/test_remote.py @@ -17,7 +17,7 @@ from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_registry as er from . import setup_samsungtv_entry -from .const import MOCK_CONFIG, MOCK_ENTRY_WS_WITH_MAC, MOCK_ENTRYDATA_ENCRYPTED_WS +from .const import ENTRYDATA_LEGACY, MOCK_ENTRY_WS_WITH_MAC, MOCK_ENTRYDATA_ENCRYPTED_WS from tests.common import MockConfigEntry @@ -119,15 +119,15 @@ async def test_turn_on_wol(hass: HomeAssistant) -> None: assert mock_send_magic_packet.called -async def test_turn_on_without_turnon(hass: HomeAssistant, remote: Mock) -> None: +async def test_turn_on_without_turnon(hass: HomeAssistant, remote_legacy: Mock) -> None: """Test turn on.""" - await setup_samsungtv_entry(hass, MOCK_CONFIG) + await setup_samsungtv_entry(hass, ENTRYDATA_LEGACY) with pytest.raises(HomeAssistantError) as exc_info: await hass.services.async_call( REMOTE_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_ID}, True ) # nothing called as not supported feature - assert remote.control.call_count == 0 + assert remote_legacy.control.call_count == 0 assert exc_info.value.translation_domain == DOMAIN assert exc_info.value.translation_key == "service_unsupported" assert exc_info.value.translation_placeholders == {