mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Cleanup mac fixtures in samsungtv tests (#67529)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
74483d2669
commit
8e3b0f6554
@ -8,7 +8,7 @@ from samsungtvws.async_remote import SamsungTVWSAsyncRemote
|
||||
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .const import SAMPLE_APP_LIST
|
||||
from .const import SAMPLE_APP_LIST, SAMPLE_DEVICE_INFO_WIFI
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@ -39,16 +39,9 @@ def rest_api_fixture() -> Mock:
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVAsyncRest",
|
||||
autospec=True,
|
||||
) as rest_api_class:
|
||||
rest_api_class.return_value.rest_device_info.return_value = {
|
||||
"id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4",
|
||||
"device": {
|
||||
"modelName": "82GXARRS",
|
||||
"wifiMac": "aa:bb:cc:dd:ee:ff",
|
||||
"name": "[TV] Living Room",
|
||||
"type": "Samsung SmartTV",
|
||||
"networkType": "wireless",
|
||||
},
|
||||
}
|
||||
rest_api_class.return_value.rest_device_info.return_value = (
|
||||
SAMPLE_DEVICE_INFO_WIFI
|
||||
)
|
||||
yield rest_api_class.return_value
|
||||
|
||||
|
||||
@ -82,7 +75,7 @@ def mock_now() -> datetime:
|
||||
return dt_util.utcnow()
|
||||
|
||||
|
||||
@pytest.fixture(name="no_mac_address")
|
||||
@pytest.fixture(name="mac_address", autouse=True)
|
||||
def mac_address_fixture() -> Mock:
|
||||
"""Patch getmac.get_mac_address."""
|
||||
with patch("getmac.get_mac_address", return_value=None) as mac:
|
||||
|
@ -22,3 +22,14 @@ SAMPLE_APP_LIST = [
|
||||
"name": "Spotify - Music and Podcasts",
|
||||
},
|
||||
]
|
||||
|
||||
SAMPLE_DEVICE_INFO_WIFI = {
|
||||
"id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4",
|
||||
"device": {
|
||||
"modelName": "82GXARRS",
|
||||
"wifiMac": "aa:bb:ww:ii:ff:ii",
|
||||
"name": "[TV] Living Room",
|
||||
"type": "Samsung SmartTV",
|
||||
"networkType": "wireless",
|
||||
},
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ MOCK_SSDP_DATA_WRONGMODEL = ssdp.SsdpServiceInfo(
|
||||
},
|
||||
)
|
||||
MOCK_DHCP_DATA = dhcp.DhcpServiceInfo(
|
||||
ip="fake_host", macaddress="aa:bb:cc:dd:ee:ff", hostname="fake_hostname"
|
||||
ip="fake_host", macaddress="aa:bb:dd:hh:cc:pp", hostname="fake_hostname"
|
||||
)
|
||||
EXISTING_IP = "192.168.40.221"
|
||||
MOCK_ZEROCONF_DATA = zeroconf.ZeroconfServiceInfo(
|
||||
@ -109,7 +109,7 @@ MOCK_ZEROCONF_DATA = zeroconf.ZeroconfServiceInfo(
|
||||
name="mock_name",
|
||||
port=1234,
|
||||
properties={
|
||||
"deviceid": "aa:bb:cc:dd:ee:ff",
|
||||
"deviceid": "aa:bb:zz:ee:rr:oo",
|
||||
"manufacturer": "fake_manufacturer",
|
||||
"model": "fake_model",
|
||||
"serialNumber": "fake_serial",
|
||||
@ -316,10 +316,8 @@ async def test_user_not_successful_2(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote")
|
||||
async def test_ssdp(hass: HomeAssistant, no_mac_address: Mock) -> None:
|
||||
async def test_ssdp(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery."""
|
||||
|
||||
no_mac_address.return_value = "aa:bb:cc:dd:ee:ff"
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.async_device_info",
|
||||
return_value=MOCK_DEVICE_INFO,
|
||||
@ -345,10 +343,8 @@ async def test_ssdp(hass: HomeAssistant, no_mac_address: Mock) -> None:
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote")
|
||||
async def test_ssdp_noprefix(hass: HomeAssistant, no_mac_address: Mock) -> None:
|
||||
async def test_ssdp_noprefix(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery without prefixes."""
|
||||
|
||||
no_mac_address.return_value = "aa:bb:cc:dd:ee:ff"
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.async_device_info",
|
||||
return_value=MOCK_DEVICE_INFO_2,
|
||||
@ -449,7 +445,7 @@ async def test_ssdp_websocket_success_populates_mac_address(
|
||||
assert result["title"] == "Living Room (82GXARRS)"
|
||||
assert result["data"][CONF_HOST] == "fake_host"
|
||||
assert result["data"][CONF_NAME] == "Living Room"
|
||||
assert result["data"][CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert result["data"][CONF_MAC] == "aa:bb:ww:ii:ff:ii"
|
||||
assert result["data"][CONF_MANUFACTURER] == "Samsung fake_manufacturer"
|
||||
assert result["data"][CONF_MODEL] == "82GXARRS"
|
||||
assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de"
|
||||
@ -490,7 +486,6 @@ async def test_ssdp_model_not_supported(hass: HomeAssistant) -> None:
|
||||
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("no_mac_address")
|
||||
async def test_ssdp_not_successful(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery but no device found."""
|
||||
with patch(
|
||||
@ -519,7 +514,6 @@ async def test_ssdp_not_successful(hass: HomeAssistant) -> None:
|
||||
assert result["reason"] == RESULT_CANNOT_CONNECT
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("no_mac_address")
|
||||
async def test_ssdp_not_successful_2(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery but no device found."""
|
||||
with patch(
|
||||
@ -549,12 +543,8 @@ async def test_ssdp_not_successful_2(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote")
|
||||
async def test_ssdp_already_in_progress(
|
||||
hass: HomeAssistant, no_mac_address: Mock
|
||||
) -> None:
|
||||
async def test_ssdp_already_in_progress(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery twice."""
|
||||
|
||||
no_mac_address.return_value = "aa:bb:cc:dd:ee:ff"
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.async_device_info",
|
||||
return_value=MOCK_DEVICE_INFO,
|
||||
@ -576,12 +566,8 @@ async def test_ssdp_already_in_progress(
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote")
|
||||
async def test_ssdp_already_configured(
|
||||
hass: HomeAssistant, no_mac_address: Mock
|
||||
) -> None:
|
||||
async def test_ssdp_already_configured(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery when already configured."""
|
||||
|
||||
no_mac_address.return_value = "aa:bb:cc:dd:ee:ff"
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.async_device_info",
|
||||
return_value=MOCK_DEVICE_INFO,
|
||||
@ -609,10 +595,8 @@ async def test_ssdp_already_configured(
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote")
|
||||
async def test_import_legacy(hass: HomeAssistant, no_mac_address: Mock) -> None:
|
||||
async def test_import_legacy(hass: HomeAssistant) -> None:
|
||||
"""Test importing from yaml with hostname."""
|
||||
|
||||
no_mac_address.return_value = "aa:bb:cc:dd:ee:ff"
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
@ -632,7 +616,7 @@ async def test_import_legacy(hass: HomeAssistant, no_mac_address: Mock) -> None:
|
||||
assert entries[0].data[CONF_PORT] == LEGACY_PORT
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote", "remotews", "no_mac_address")
|
||||
@pytest.mark.usefixtures("remote", "remotews")
|
||||
async def test_import_legacy_without_name(hass: HomeAssistant, rest_api: Mock) -> None:
|
||||
"""Test importing from yaml without a name."""
|
||||
rest_api.rest_device_info.return_value = None
|
||||
@ -733,7 +717,7 @@ async def test_dhcp(hass: HomeAssistant) -> None:
|
||||
assert result["title"] == "Living Room (82GXARRS)"
|
||||
assert result["data"][CONF_HOST] == "fake_host"
|
||||
assert result["data"][CONF_NAME] == "Living Room"
|
||||
assert result["data"][CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert result["data"][CONF_MAC] == "aa:bb:ww:ii:ff:ii"
|
||||
assert result["data"][CONF_MANUFACTURER] == "Samsung"
|
||||
assert result["data"][CONF_MODEL] == "82GXARRS"
|
||||
assert result["result"].unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
|
||||
@ -759,7 +743,7 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
|
||||
assert result["title"] == "Living Room (82GXARRS)"
|
||||
assert result["data"][CONF_HOST] == "fake_host"
|
||||
assert result["data"][CONF_NAME] == "Living Room"
|
||||
assert result["data"][CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert result["data"][CONF_MAC] == "aa:bb:ww:ii:ff:ii"
|
||||
assert result["data"][CONF_MANUFACTURER] == "Samsung"
|
||||
assert result["data"][CONF_MODEL] == "82GXARRS"
|
||||
assert result["result"].unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
|
||||
@ -870,8 +854,9 @@ async def test_autodetect_websocket(hass: HomeAssistant) -> None:
|
||||
assert entries[0].data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
|
||||
|
||||
async def test_websocket_no_mac(hass: HomeAssistant) -> None:
|
||||
async def test_websocket_no_mac(hass: HomeAssistant, mac_address: Mock) -> None:
|
||||
"""Test for send key with autodetection of protocol."""
|
||||
mac_address.return_value = "gg:ee:tt:mm:aa:cc"
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.Remote",
|
||||
side_effect=OSError("Boom"),
|
||||
@ -879,9 +864,7 @@ async def test_websocket_no_mac(hass: HomeAssistant) -> None:
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVWSAsyncRemote"
|
||||
) as remotews, patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVAsyncRest",
|
||||
) as rest_api_class, patch(
|
||||
"getmac.get_mac_address", return_value="gg:hh:ii:ll:mm:nn"
|
||||
):
|
||||
) as rest_api_class:
|
||||
remote = Mock(SamsungTVWSAsyncRemote)
|
||||
remote.__aenter__ = AsyncMock(return_value=remote)
|
||||
remote.__aexit__ = AsyncMock(return_value=False)
|
||||
@ -908,14 +891,14 @@ async def test_websocket_no_mac(hass: HomeAssistant) -> None:
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["data"][CONF_METHOD] == "websocket"
|
||||
assert result["data"][CONF_TOKEN] == "123456789"
|
||||
assert result["data"][CONF_MAC] == "gg:hh:ii:ll:mm:nn"
|
||||
assert result["data"][CONF_MAC] == "gg:ee:tt:mm:aa:cc"
|
||||
remotews.assert_called_once_with(**AUTODETECT_WEBSOCKET_SSL)
|
||||
rest_api_class.assert_called_once_with(**DEVICEINFO_WEBSOCKET_SSL)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
assert entries[0].data[CONF_MAC] == "gg:hh:ii:ll:mm:nn"
|
||||
assert entries[0].data[CONF_MAC] == "gg:ee:tt:mm:aa:cc"
|
||||
|
||||
|
||||
async def test_autodetect_auth_missing(hass: HomeAssistant) -> None:
|
||||
@ -1058,7 +1041,7 @@ async def test_update_missing_mac_unique_id_added_from_dhcp(
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
assert entry.data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert entry.data[CONF_MAC] == "aa:bb:dd:hh:cc:pp"
|
||||
assert entry.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
|
||||
|
||||
|
||||
@ -1086,7 +1069,7 @@ async def test_update_missing_mac_unique_id_added_from_zeroconf(
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
assert entry.data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert entry.data[CONF_MAC] == "aa:bb:zz:ee:rr:oo"
|
||||
assert entry.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
|
||||
|
||||
|
||||
@ -1115,7 +1098,7 @@ async def test_update_missing_mac_unique_id_added_from_ssdp(
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
assert entry.data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert entry.data[CONF_MAC] == "aa:bb:ww:ii:ff:ii"
|
||||
assert entry.unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de"
|
||||
|
||||
|
||||
@ -1147,7 +1130,7 @@ async def test_update_missing_mac_added_unique_id_preserved_from_zeroconf(
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
assert entry.data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert entry.data[CONF_MAC] == "aa:bb:zz:ee:rr:oo"
|
||||
assert entry.unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de"
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ from homeassistant.components.samsungtv import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import SAMPLE_DEVICE_INFO_WIFI
|
||||
from .test_media_player import MOCK_ENTRY_WS_WITH_MAC
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -56,14 +57,5 @@ async def test_entry_diagnostics(
|
||||
"unique_id": "any",
|
||||
"version": 2,
|
||||
},
|
||||
"device_info": {
|
||||
"id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4",
|
||||
"device": {
|
||||
"modelName": "82GXARRS",
|
||||
"name": "[TV] Living Room",
|
||||
"networkType": "wireless",
|
||||
"type": "Samsung SmartTV",
|
||||
"wifiMac": "aa:bb:cc:dd:ee:ff",
|
||||
},
|
||||
},
|
||||
"device_info": SAMPLE_DEVICE_INFO_WIFI,
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ REMOTE_CALL = {
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews", "no_mac_address")
|
||||
@pytest.mark.usefixtures("remotews")
|
||||
async def test_setup(hass: HomeAssistant) -> None:
|
||||
"""Test Samsung TV integration is setup."""
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
@ -102,7 +102,7 @@ async def test_setup_from_yaml_without_port_device_online(hass: HomeAssistant) -
|
||||
|
||||
config_entries_domain = hass.config_entries.async_entries(SAMSUNGTV_DOMAIN)
|
||||
assert len(config_entries_domain) == 1
|
||||
assert config_entries_domain[0].data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert config_entries_domain[0].data[CONF_MAC] == "aa:bb:ww:ii:ff:ii"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote")
|
||||
@ -123,7 +123,7 @@ async def test_setup_duplicate_config(
|
||||
assert "duplicate host entries found" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote", "remotews", "no_mac_address")
|
||||
@pytest.mark.usefixtures("remote", "remotews")
|
||||
async def test_setup_duplicate_entries(hass: HomeAssistant) -> None:
|
||||
"""Test duplicate setup of platform."""
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
|
@ -125,9 +125,6 @@ MOCK_CONFIG_NOTURNON = {
|
||||
]
|
||||
}
|
||||
|
||||
# Fake mac address in all mediaplayer tests.
|
||||
pytestmark = pytest.mark.usefixtures("no_mac_address")
|
||||
|
||||
|
||||
@pytest.fixture(name="delay")
|
||||
def delay_fixture():
|
||||
@ -181,12 +178,10 @@ async def test_setup_websocket(hass: HomeAssistant) -> None:
|
||||
|
||||
config_entries = hass.config_entries.async_entries(SAMSUNGTV_DOMAIN)
|
||||
assert len(config_entries) == 1
|
||||
assert config_entries[0].data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert config_entries[0].data[CONF_MAC] == "aa:bb:ww:ii:ff:ii"
|
||||
|
||||
|
||||
async def test_setup_websocket_2(
|
||||
hass: HomeAssistant, mock_now: datetime, rest_api: Mock
|
||||
) -> None:
|
||||
async def test_setup_websocket_2(hass: HomeAssistant, mock_now: datetime) -> None:
|
||||
"""Test setup of platform from config entry."""
|
||||
entity_id = f"{DOMAIN}.fake"
|
||||
|
||||
@ -201,16 +196,6 @@ async def test_setup_websocket_2(
|
||||
assert len(config_entries) == 1
|
||||
assert entry is config_entries[0]
|
||||
|
||||
rest_api.rest_device_info.return_value = {
|
||||
"id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4",
|
||||
"device": {
|
||||
"modelName": "82GXARRS",
|
||||
"wifiMac": "aa:bb:cc:dd:ee:ff",
|
||||
"name": "[TV] Living Room",
|
||||
"type": "Samsung SmartTV",
|
||||
"networkType": "wireless",
|
||||
},
|
||||
}
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVWSAsyncRemote"
|
||||
) as remote_class:
|
||||
@ -223,7 +208,7 @@ async def test_setup_websocket_2(
|
||||
assert await async_setup_component(hass, SAMSUNGTV_DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entries[0].data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert config_entries[0].data[CONF_MAC] == "aa:bb:ww:ii:ff:ii"
|
||||
|
||||
next_update = mock_now + timedelta(minutes=5)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
|
||||
|
Loading…
x
Reference in New Issue
Block a user