diff --git a/homeassistant/components/samsungtv/bridge.py b/homeassistant/components/samsungtv/bridge.py index 17d6f1554c4..b32ee28674d 100644 --- a/homeassistant/components/samsungtv/bridge.py +++ b/homeassistant/components/samsungtv/bridge.py @@ -50,9 +50,8 @@ KEY_PRESS_TIMEOUT = 1.2 def mac_from_device_info(info: dict[str, Any]) -> str | None: """Extract the mac address from the device info.""" - dev_info = info.get("device", {}) - if dev_info.get("networkType") == "wireless" and dev_info.get("wifiMac"): - return format_mac(dev_info["wifiMac"]) + if wifi_mac := info.get("device", {}).get("wifiMac"): + return format_mac(wifi_mac) return None diff --git a/tests/components/samsungtv/const.py b/tests/components/samsungtv/const.py index a3bbcb2dd7f..7f9f175c171 100644 --- a/tests/components/samsungtv/const.py +++ b/tests/components/samsungtv/const.py @@ -33,3 +33,43 @@ SAMPLE_DEVICE_INFO_WIFI = { "networkType": "wireless", }, } + +SAMPLE_DEVICE_INFO_FRAME = { + "device": { + "FrameTVSupport": "true", + "GamePadSupport": "true", + "ImeSyncedSupport": "true", + "OS": "Tizen", + "TokenAuthSupport": "true", + "VoiceSupport": "true", + "countryCode": "FR", + "description": "Samsung DTV RCR", + "developerIP": "0.0.0.0", + "developerMode": "0", + "duid": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", + "firmwareVersion": "Unknown", + "id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", + "ip": "1.2.3.4", + "model": "17_KANTM_UHD", + "modelName": "UE43LS003", + "name": "[TV] Samsung Frame (43)", + "networkType": "wired", + "resolution": "3840x2160", + "smartHubAgreement": "true", + "type": "Samsung SmartTV", + "udn": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", + "wifiMac": "aa:ee:tt:hh:ee:rr", + }, + "id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", + "isSupport": ( + '{"DMP_DRM_PLAYREADY":"false","DMP_DRM_WIDEVINE":"false","DMP_available":"true",' + '"EDEN_available":"true","FrameTVSupport":"true","ImeSyncedSupport":"true",' + '"TokenAuthSupport":"true","remote_available":"true","remote_fourDirections":"true",' + '"remote_touchPad":"true","remote_voiceControl":"true"}\n' + ), + "name": "[TV] Samsung Frame (43)", + "remote": "1.0", + "type": "Samsung SmartTV", + "uri": "https://1.2.3.4:8002/api/v2/", + "version": "2.0.25", +} diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index b6f23f83912..a3565f4d884 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -44,7 +44,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -from .const import SAMPLE_APP_LIST +from .const import SAMPLE_APP_LIST, SAMPLE_DEVICE_INFO_FRAME from tests.common import MockConfigEntry @@ -697,7 +697,7 @@ async def test_import_unknown_host(hass: HomeAssistant): @pytest.mark.usefixtures("remote", "remotews") -async def test_dhcp(hass: HomeAssistant) -> None: +async def test_dhcp_wireless(hass: HomeAssistant) -> None: """Test starting a flow from dhcp.""" # confirm to add the entry result = await hass.config_entries.flow.async_init( @@ -723,6 +723,35 @@ async def test_dhcp(hass: HomeAssistant) -> None: assert result["result"].unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4" +@pytest.mark.usefixtures("remote", "remotews") +async def test_dhcp_wired(hass: HomeAssistant, rest_api: Mock) -> None: + """Test starting a flow from dhcp.""" + # Even though it is named "wifiMac", it matches the mac of the wired connection + rest_api.rest_device_info.return_value = SAMPLE_DEVICE_INFO_FRAME + # confirm to add the entry + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_DHCP}, + data=MOCK_DHCP_DATA, + ) + await hass.async_block_till_done() + assert result["type"] == "form" + assert result["step_id"] == "confirm" + + # entry was added + result = await hass.config_entries.flow.async_configure( + result["flow_id"], user_input="whatever" + ) + assert result["type"] == "create_entry" + assert result["title"] == "Samsung Frame (43) (UE43LS003)" + assert result["data"][CONF_HOST] == "fake_host" + assert result["data"][CONF_NAME] == "Samsung Frame (43)" + assert result["data"][CONF_MAC] == "aa:ee:tt:hh:ee:rr" + assert result["data"][CONF_MANUFACTURER] == "Samsung" + assert result["data"][CONF_MODEL] == "UE43LS003" + assert result["result"].unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4" + + @pytest.mark.usefixtures("remote", "remotews") async def test_zeroconf(hass: HomeAssistant) -> None: """Test starting a flow from zeroconf."""