mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Move more SamsungTV test constants to fixture files (#144249)
* Add SSDP fixtures to SamsungTV * Adjust * Improve * Improve
This commit is contained in:
parent
66b2e06cd3
commit
d88cd72d13
@ -2,6 +2,7 @@
|
||||
|
||||
from homeassistant.components.samsungtv.const import (
|
||||
CONF_SESSION_ID,
|
||||
DOMAIN,
|
||||
METHOD_LEGACY,
|
||||
METHOD_WEBSOCKET,
|
||||
)
|
||||
@ -15,13 +16,9 @@ from homeassistant.const import (
|
||||
CONF_PORT,
|
||||
CONF_TOKEN,
|
||||
)
|
||||
from homeassistant.helpers.service_info.ssdp import (
|
||||
ATTR_UPNP_FRIENDLY_NAME,
|
||||
ATTR_UPNP_MANUFACTURER,
|
||||
ATTR_UPNP_MODEL_NAME,
|
||||
ATTR_UPNP_UDN,
|
||||
SsdpServiceInfo,
|
||||
)
|
||||
from homeassistant.helpers.service_info.ssdp import SsdpServiceInfo
|
||||
|
||||
from tests.common import load_json_object_fixture
|
||||
|
||||
MOCK_CONFIG = {
|
||||
CONF_HOST: "fake_host",
|
||||
@ -59,28 +56,6 @@ MOCK_ENTRY_WS_WITH_MAC = {
|
||||
CONF_TOKEN: "123456789",
|
||||
}
|
||||
|
||||
MOCK_SSDP_DATA_RENDERING_CONTROL_ST = SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="urn:schemas-upnp-org:service:RenderingControl:1",
|
||||
ssdp_location="https://fake_host:12345/test",
|
||||
upnp={
|
||||
ATTR_UPNP_FRIENDLY_NAME: "[TV] fake_name",
|
||||
ATTR_UPNP_MANUFACTURER: "Samsung fake_manufacturer",
|
||||
ATTR_UPNP_MODEL_NAME: "fake_model",
|
||||
ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de",
|
||||
},
|
||||
)
|
||||
MOCK_SSDP_DATA_MAIN_TV_AGENT_ST = SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="urn:samsung.com:service:MainTVAgent2:1",
|
||||
ssdp_location="https://fake_host:12345/tv_agent",
|
||||
upnp={
|
||||
ATTR_UPNP_FRIENDLY_NAME: "[TV] fake_name",
|
||||
ATTR_UPNP_MANUFACTURER: "Samsung fake_manufacturer",
|
||||
ATTR_UPNP_MODEL_NAME: "fake_model",
|
||||
ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de",
|
||||
},
|
||||
)
|
||||
|
||||
SAMPLE_DEVICE_INFO_WIFI = {
|
||||
"id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4",
|
||||
@ -92,3 +67,15 @@ SAMPLE_DEVICE_INFO_WIFI = {
|
||||
"networkType": "wireless",
|
||||
},
|
||||
}
|
||||
|
||||
MOCK_SSDP_DATA = SsdpServiceInfo(
|
||||
**load_json_object_fixture("ssdp_service_remote_control_receiver.json", DOMAIN)
|
||||
)
|
||||
|
||||
MOCK_SSDP_DATA_RENDERING_CONTROL_ST = SsdpServiceInfo(
|
||||
**load_json_object_fixture("ssdp_service_rendering_control.json", DOMAIN)
|
||||
)
|
||||
|
||||
MOCK_SSDP_DATA_MAIN_TV_AGENT_ST = SsdpServiceInfo(
|
||||
**load_json_object_fixture("ssdp_device_main_tv_agent.json", DOMAIN)
|
||||
)
|
||||
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"ssdp_usn": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de::urn:samsung.com:service:MainTVAgent2:1",
|
||||
"ssdp_st": "urn:samsung.com:service:MainTVAgent2:1",
|
||||
"upnp": {
|
||||
"friendlyName": "[TV] fake_name",
|
||||
"manufacturer": "Samsung fake_manufacturer",
|
||||
"modelName": "fake_model",
|
||||
"UDN": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de"
|
||||
},
|
||||
"ssdp_location": "https://fake_host:12345/tv_agent"
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"ssdp_usn": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de::urn:samsung.com:device:RemoteControlReceiver:1",
|
||||
"ssdp_st": "urn:samsung.com:device:RemoteControlReceiver:1",
|
||||
"upnp": {
|
||||
"friendlyName": "[TV] fake_name",
|
||||
"manufacturer": "Samsung fake_manufacturer",
|
||||
"modelName": "fake_model",
|
||||
"UDN": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de"
|
||||
},
|
||||
"ssdp_location": "http://fake_host:7676/smp_7_"
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"ssdp_usn": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de::urn:schemas-upnp-org:service:RenderingControl:1",
|
||||
"ssdp_st": "urn:schemas-upnp-org:service:RenderingControl:1",
|
||||
"upnp": {
|
||||
"friendlyName": "[TV] fake_name",
|
||||
"manufacturer": "Samsung fake_manufacturer",
|
||||
"modelName": "fake_model",
|
||||
"UDN": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de"
|
||||
},
|
||||
"ssdp_location": "https://fake_host:12345/test"
|
||||
}
|
@ -51,8 +51,6 @@ from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
|
||||
from homeassistant.helpers.service_info.ssdp import (
|
||||
ATTR_UPNP_FRIENDLY_NAME,
|
||||
ATTR_UPNP_MANUFACTURER,
|
||||
ATTR_UPNP_MODEL_NAME,
|
||||
ATTR_UPNP_UDN,
|
||||
SsdpServiceInfo,
|
||||
)
|
||||
from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
|
||||
@ -61,6 +59,7 @@ from homeassistant.setup import async_setup_component
|
||||
from .const import (
|
||||
MOCK_ENTRYDATA_ENCRYPTED_WS,
|
||||
MOCK_ENTRYDATA_WS,
|
||||
MOCK_SSDP_DATA,
|
||||
MOCK_SSDP_DATA_MAIN_TV_AGENT_ST,
|
||||
MOCK_SSDP_DATA_RENDERING_CONTROL_ST,
|
||||
)
|
||||
@ -84,49 +83,7 @@ MOCK_IMPORT_WSDATA = {
|
||||
CONF_PORT: 8002,
|
||||
}
|
||||
MOCK_USER_DATA = {CONF_HOST: "fake_host", CONF_NAME: "fake_name"}
|
||||
MOCK_SSDP_DATA = SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
ssdp_location="https://fake_host:12345/test",
|
||||
upnp={
|
||||
ATTR_UPNP_FRIENDLY_NAME: "[TV] fake_name",
|
||||
ATTR_UPNP_MANUFACTURER: "Samsung fake_manufacturer",
|
||||
ATTR_UPNP_MODEL_NAME: "fake_model",
|
||||
ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de",
|
||||
},
|
||||
)
|
||||
MOCK_SSDP_DATA_NO_MANUFACTURER = SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
ssdp_location="https://fake_host:12345/test",
|
||||
upnp={
|
||||
ATTR_UPNP_FRIENDLY_NAME: "[TV] fake_name",
|
||||
ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de",
|
||||
},
|
||||
)
|
||||
|
||||
MOCK_SSDP_DATA_NOPREFIX = SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
ssdp_location="http://fake2_host:12345/test",
|
||||
upnp={
|
||||
ATTR_UPNP_FRIENDLY_NAME: "fake2_name",
|
||||
ATTR_UPNP_MANUFACTURER: "Samsung fake2_manufacturer",
|
||||
ATTR_UPNP_MODEL_NAME: "fake2_model",
|
||||
ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172df",
|
||||
},
|
||||
)
|
||||
MOCK_SSDP_DATA_WRONGMODEL = SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
ssdp_location="http://fake2_host:12345/test",
|
||||
upnp={
|
||||
ATTR_UPNP_FRIENDLY_NAME: "fake2_name",
|
||||
ATTR_UPNP_MANUFACTURER: "fake2_manufacturer",
|
||||
ATTR_UPNP_MODEL_NAME: "HW-Qfake",
|
||||
ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172df",
|
||||
},
|
||||
)
|
||||
MOCK_DHCP_DATA = DhcpServiceInfo(
|
||||
ip="fake_host", macaddress="aabbccddeeff", hostname="fake_hostname"
|
||||
)
|
||||
@ -540,13 +497,16 @@ async def test_ssdp(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.usefixtures("remote", "rest_api_failing")
|
||||
async def test_ssdp_no_manufacturer(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery when the manufacturer data is missing."""
|
||||
ssdp_data = deepcopy(MOCK_SSDP_DATA)
|
||||
ssdp_data.upnp.pop(ATTR_UPNP_MANUFACTURER)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data=MOCK_SSDP_DATA_NO_MANUFACTURER,
|
||||
data=ssdp_data,
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "not_supported"
|
||||
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -566,12 +526,17 @@ async def test_ssdp_legacy_not_remote_control_receiver_udn(
|
||||
|
||||
@pytest.mark.usefixtures("remote", "rest_api_failing")
|
||||
async def test_ssdp_noprefix(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery without prefixes."""
|
||||
"""Test starting a flow from discovery when friendly name doesn't start with [TV]."""
|
||||
ssdp_data = deepcopy(MOCK_SSDP_DATA)
|
||||
ssdp_data.upnp[ATTR_UPNP_FRIENDLY_NAME] = ssdp_data.upnp[ATTR_UPNP_FRIENDLY_NAME][
|
||||
4:
|
||||
]
|
||||
|
||||
# confirm to add the entry
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data=MOCK_SSDP_DATA_NOPREFIX,
|
||||
data=ssdp_data,
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "confirm"
|
||||
@ -580,12 +545,12 @@ async def test_ssdp_noprefix(hass: HomeAssistant) -> None:
|
||||
result["flow_id"], user_input="whatever"
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "fake2_model"
|
||||
assert result["data"][CONF_HOST] == "fake2_host"
|
||||
assert result["data"][CONF_NAME] == "fake2_model"
|
||||
assert result["data"][CONF_MANUFACTURER] == "Samsung fake2_manufacturer"
|
||||
assert result["data"][CONF_MODEL] == "fake2_model"
|
||||
assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172df"
|
||||
assert result["title"] == "fake_model"
|
||||
assert result["data"][CONF_HOST] == "fake_host"
|
||||
assert result["data"][CONF_NAME] == "fake_model"
|
||||
assert result["data"][CONF_MANUFACTURER] == "Samsung fake_manufacturer"
|
||||
assert result["data"][CONF_MODEL] == "fake_model"
|
||||
assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews", "rest_api_failing")
|
||||
@ -797,14 +762,15 @@ async def test_ssdp_websocket_cannot_connect(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote")
|
||||
async def test_ssdp_model_not_supported(hass: HomeAssistant) -> None:
|
||||
async def test_ssdp_wrong_manufacturer(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery."""
|
||||
|
||||
ssdp_data = deepcopy(MOCK_SSDP_DATA)
|
||||
ssdp_data.upnp[ATTR_UPNP_MANUFACTURER] = ssdp_data.upnp[ATTR_UPNP_MANUFACTURER][7:]
|
||||
# confirm to add the entry
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data=MOCK_SSDP_DATA_WRONGMODEL,
|
||||
data=ssdp_data,
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||
@ -1100,7 +1066,7 @@ async def test_zeroconf_ignores_soundbar(hass: HomeAssistant, rest_api: Mock) ->
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "not_supported"
|
||||
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote", "remotews", "remoteencws", "rest_api_failing")
|
||||
@ -1113,7 +1079,7 @@ async def test_zeroconf_no_device_info(hass: HomeAssistant) -> None:
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "not_supported"
|
||||
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews", "rest_api", "remoteencws_failing")
|
||||
@ -1493,7 +1459,7 @@ async def test_update_zeroconf_discovery_preserved_unique_id(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "not_supported"
|
||||
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||
assert entry.data[CONF_MAC] == "aa:bb:zz:ee:rr:oo"
|
||||
assert entry.unique_id == "original"
|
||||
|
||||
@ -1752,7 +1718,7 @@ async def test_update_legacy_missing_mac_from_dhcp_no_unique_id(
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "not_supported"
|
||||
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||
assert entry.data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
|
||||
assert entry.unique_id is None
|
||||
|
||||
@ -1905,7 +1871,7 @@ async def test_form_reauth_websocket_not_supported(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.ABORT
|
||||
assert result2["reason"] == "not_supported"
|
||||
assert result2["reason"] == RESULT_NOT_SUPPORTED
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remoteencws", "rest_api")
|
||||
|
Loading…
x
Reference in New Issue
Block a user