Add comments to samsungtv config flow tests (#144787)

This commit is contained in:
epenet 2025-05-13 07:54:37 +02:00 committed by GitHub
parent b15c9ad130
commit eec617b391
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,7 +17,10 @@ from websockets import frames
from websockets.exceptions import ConnectionClosedError, WebSocketException from websockets.exceptions import ConnectionClosedError, WebSocketException
from homeassistant import config_entries 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 ( from homeassistant.components.samsungtv.const import (
CONF_MANUFACTURER, CONF_MANUFACTURER,
CONF_SESSION_ID, CONF_SESSION_ID,
@ -45,6 +48,7 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import BaseServiceInfo, FlowResultType 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.dhcp import DhcpServiceInfo
from homeassistant.helpers.service_info.ssdp import ( from homeassistant.helpers.service_info.ssdp import (
ATTR_UPNP_FRIENDLY_NAME, 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" assert entry.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
@pytest.mark.usefixtures( @pytest.mark.usefixtures("remote_websocket")
"remote_websocket", "rest_api", "remote_encrypted_websocket_failing"
)
async def test_update_incorrect_udn_matching_mac_from_dhcp( 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: ) -> None:
"""Test that DHCP updates the wrong udn from ssdp via mac match.""" """Test that DHCP updates the wrong udn from ssdp via mac match."""
entry = MockConfigEntry( entry = MockConfigEntry(
@ -2016,6 +2018,12 @@ async def test_update_incorrect_udn_matching_mac_from_dhcp(
) )
entry.add_to_hass(hass) 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( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_DHCP}, 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["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured" 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" assert entry.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
@pytest.mark.usefixtures( @pytest.mark.usefixtures("remote_websocket")
"remote_websocket", "rest_api", "remote_encrypted_websocket_failing"
)
async def test_no_update_incorrect_udn_not_matching_mac_from_dhcp( 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: ) -> None:
"""Test that DHCP does not update the wrong udn from ssdp via host match.""" """Test that DHCP does not update the wrong udn from ssdp via host match."""
entry = MockConfigEntry( entry = MockConfigEntry(
@ -2045,6 +2052,12 @@ async def test_no_update_incorrect_udn_not_matching_mac_from_dhcp(
) )
entry.add_to_hass(hass) 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( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_DHCP}, 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["type"] is FlowResultType.FORM
assert result["step_id"] == "confirm" 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" assert entry.unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de"