1
mirror of https://github.com/home-assistant/core synced 2024-08-06 09:34:49 +02:00

Adjust get_mac routine in SamsungTV (#67804)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-03-08 07:54:12 +01:00 committed by GitHub
parent 2d4ccddd99
commit 5b23b9a617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 5 deletions

View File

@ -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

View File

@ -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",
}

View File

@ -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."""