diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index 83639171576..dd744bd82ca 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -17,7 +17,10 @@ from websockets import frames from websockets.exceptions import ConnectionClosedError, WebSocketException from homeassistant import config_entries -from homeassistant.components.samsungtv.config_flow import SamsungTVConfigFlow +from homeassistant.components.samsungtv.config_flow import ( + SamsungTVConfigFlow, + _strip_uuid, +) from homeassistant.components.samsungtv.const import ( CONF_MANUFACTURER, CONF_SESSION_ID, @@ -45,6 +48,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import BaseServiceInfo, FlowResultType +from homeassistant.helpers import device_registry as dr from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo from homeassistant.helpers.service_info.ssdp import ( ATTR_UPNP_FRIENDLY_NAME, @@ -2001,11 +2005,9 @@ async def test_update_incorrect_udn_matching_mac_unique_id_added_from_ssdp( assert entry.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4" -@pytest.mark.usefixtures( - "remote_websocket", "rest_api", "remote_encrypted_websocket_failing" -) +@pytest.mark.usefixtures("remote_websocket") async def test_update_incorrect_udn_matching_mac_from_dhcp( - hass: HomeAssistant, mock_setup_entry: AsyncMock + hass: HomeAssistant, rest_api: Mock, mock_setup_entry: AsyncMock ) -> None: """Test that DHCP updates the wrong udn from ssdp via mac match.""" entry = MockConfigEntry( @@ -2016,6 +2018,12 @@ async def test_update_incorrect_udn_matching_mac_from_dhcp( ) entry.add_to_hass(hass) + assert entry.data[CONF_HOST] == MOCK_DHCP_DATA.ip + assert entry.data[CONF_MAC] == dr.format_mac( + rest_api.rest_device_info.return_value["device"]["wifiMac"] + ) + assert entry.unique_id != _strip_uuid(rest_api.rest_device_info.return_value["id"]) + result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_DHCP}, @@ -2026,15 +2034,14 @@ async def test_update_incorrect_udn_matching_mac_from_dhcp( assert result["type"] is FlowResultType.ABORT assert result["reason"] == "already_configured" - assert entry.data[CONF_MAC] == "aa:bb:aa:aa:aa:aa" + + # Same IP + same MAC => unique id updated assert entry.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4" -@pytest.mark.usefixtures( - "remote_websocket", "rest_api", "remote_encrypted_websocket_failing" -) +@pytest.mark.usefixtures("remote_websocket") async def test_no_update_incorrect_udn_not_matching_mac_from_dhcp( - hass: HomeAssistant, mock_setup_entry: AsyncMock + hass: HomeAssistant, rest_api: Mock, mock_setup_entry: AsyncMock ) -> None: """Test that DHCP does not update the wrong udn from ssdp via host match.""" entry = MockConfigEntry( @@ -2045,6 +2052,12 @@ async def test_no_update_incorrect_udn_not_matching_mac_from_dhcp( ) entry.add_to_hass(hass) + assert entry.data[CONF_HOST] == MOCK_DHCP_DATA.ip + assert entry.data[CONF_MAC] != dr.format_mac( + rest_api.rest_device_info.return_value["device"]["wifiMac"] + ) + assert entry.unique_id != _strip_uuid(rest_api.rest_device_info.return_value["id"]) + result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_DHCP}, @@ -2055,7 +2068,8 @@ async def test_no_update_incorrect_udn_not_matching_mac_from_dhcp( assert result["type"] is FlowResultType.FORM assert result["step_id"] == "confirm" - assert entry.data[CONF_MAC] == "aa:bb:ss:ss:dd:pp" + + # Same IP + different MAC => unique id not updated assert entry.unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de"