Cleanup ServiceInfo compatibility (#60540)

Co-authored-by: epenet <epenet@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
epenet 2022-05-09 14:17:48 +02:00 committed by GitHub
parent ddd22398f2
commit 141688e210
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 1 additions and 412 deletions

View file

@ -75,17 +75,6 @@ async def test_ssdp_flow_dispatched_on_st(mock_get_ssdp, hass, caplog, mock_flow
assert mock_call_data.x_homeassistant_matching_domains == {"mock-domain"}
assert mock_call_data.upnp == {ssdp.ATTR_UPNP_UDN: "uuid:mock-udn"}
assert "Failed to fetch ssdp data" not in caplog.text
# Compatibility with old dict access (to be removed after 2022.6)
assert mock_call_data[ssdp.ATTR_SSDP_ST] == "mock-st"
assert mock_call_data[ssdp.ATTR_SSDP_LOCATION] == "http://1.1.1.1"
assert mock_call_data[ssdp.ATTR_SSDP_USN] == "uuid:mock-udn::mock-st"
assert mock_call_data[ssdp.ATTR_SSDP_SERVER] == "mock-server"
assert mock_call_data[ssdp.ATTR_SSDP_EXT] == ""
assert mock_call_data[ssdp.ATTR_UPNP_UDN] == "uuid:mock-udn"
assert mock_call_data[ssdp.ATTR_SSDP_UDN] == ANY
assert mock_call_data["_timestamp"] == ANY
assert mock_call_data[ssdp.ATTR_HA_MATCHING_DOMAINS] == {"mock-domain"}
# End compatibility checks
@patch(
@ -129,17 +118,6 @@ async def test_ssdp_flow_dispatched_on_manufacturer_url(
assert mock_call_data.x_homeassistant_matching_domains == {"mock-domain"}
assert mock_call_data.upnp == {ssdp.ATTR_UPNP_UDN: "uuid:mock-udn"}
assert "Failed to fetch ssdp data" not in caplog.text
# Compatibility with old dict access (to be removed after 2022.6)
assert mock_call_data[ssdp.ATTR_SSDP_ST] == "mock-st"
assert mock_call_data[ssdp.ATTR_SSDP_LOCATION] == "http://1.1.1.1"
assert mock_call_data[ssdp.ATTR_SSDP_USN] == "uuid:mock-udn::mock-st"
assert mock_call_data[ssdp.ATTR_SSDP_SERVER] == "mock-server"
assert mock_call_data[ssdp.ATTR_SSDP_EXT] == ""
assert mock_call_data[ssdp.ATTR_UPNP_UDN] == "uuid:mock-udn"
assert mock_call_data[ssdp.ATTR_SSDP_UDN] == ANY
assert mock_call_data["_timestamp"] == ANY
assert mock_call_data[ssdp.ATTR_HA_MATCHING_DOMAINS] == {"mock-domain"}
# End compatibility checks
@pytest.mark.usefixtures("mock_get_source_ip")
@ -426,18 +404,6 @@ async def test_discovery_from_advertisement_sets_ssdp_st(
ssdp.ATTR_UPNP_DEVICE_TYPE: "Paulus",
ssdp.ATTR_UPNP_UDN: "uuid:mock-udn",
}
# Compatibility with old dict access (to be removed after 2022.6)
assert discovery_info[ssdp.ATTR_SSDP_LOCATION] == "http://1.1.1.1"
assert discovery_info[ssdp.ATTR_SSDP_NT] == "mock-st"
# Set by ssdp component, not in original advertisement.
assert discovery_info[ssdp.ATTR_SSDP_ST] == "mock-st"
assert discovery_info[ssdp.ATTR_SSDP_USN] == "uuid:mock-udn::mock-st"
assert discovery_info[ssdp.ATTR_UPNP_UDN] == "uuid:mock-udn"
assert discovery_info[ssdp.ATTR_UPNP_DEVICE_TYPE] == "Paulus"
assert discovery_info[ssdp.ATTR_SSDP_UDN] == ANY
assert discovery_info["nts"] == "ssdp:alive"
assert discovery_info["_timestamp"] == ANY
# End compatibility checks
@patch(
@ -547,25 +513,6 @@ async def test_scan_with_registered_callback(
ssdp.ATTR_UPNP_DEVICE_TYPE: "Paulus",
ssdp.ATTR_UPNP_UDN: "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL",
}
# Compatibility with old dict access (to be removed after 2022.6)
assert mock_call_data[ssdp.ATTR_UPNP_DEVICE_TYPE] == "Paulus"
assert mock_call_data[ssdp.ATTR_SSDP_EXT] == ""
assert mock_call_data[ssdp.ATTR_SSDP_LOCATION] == "http://1.1.1.1"
assert mock_call_data[ssdp.ATTR_SSDP_SERVER] == "mock-server"
assert mock_call_data[ssdp.ATTR_SSDP_ST] == "mock-st"
assert (
mock_call_data[ssdp.ATTR_SSDP_USN]
== "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL::mock-st"
)
assert (
mock_call_data[ssdp.ATTR_UPNP_UDN]
== "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL"
)
assert mock_call_data["x-rincon-bootseq"] == "55"
assert mock_call_data[ssdp.ATTR_SSDP_UDN] == ANY
assert mock_call_data["_timestamp"] == ANY
assert mock_call_data[ssdp.ATTR_HA_MATCHING_DOMAINS] == set()
# End of compatibility checks
assert "Failed to callback info" in caplog.text
async_integration_callback_from_cache = AsyncMock()
@ -622,23 +569,6 @@ async def test_getting_existing_headers(
ssdp.ATTR_UPNP_DEVICE_TYPE: "Paulus",
ssdp.ATTR_UPNP_UDN: "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL",
}
# Compatibility with old dict access (to be removed after 2022.6)
assert discovery_info_by_st[ssdp.ATTR_SSDP_EXT] == ""
assert discovery_info_by_st[ssdp.ATTR_SSDP_LOCATION] == "http://1.1.1.1"
assert discovery_info_by_st[ssdp.ATTR_SSDP_SERVER] == "mock-server"
assert discovery_info_by_st[ssdp.ATTR_SSDP_ST] == "mock-st"
assert (
discovery_info_by_st[ssdp.ATTR_SSDP_USN]
== "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL::urn:mdx-netflix-com:service:target:3"
)
assert (
discovery_info_by_st[ssdp.ATTR_UPNP_UDN]
== "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL"
)
assert discovery_info_by_st[ssdp.ATTR_UPNP_DEVICE_TYPE] == "Paulus"
assert discovery_info_by_st[ssdp.ATTR_SSDP_UDN] == ANY
assert discovery_info_by_st["_timestamp"] == ANY
# End of compatibility checks
discovery_info_by_udn = await ssdp.async_get_discovery_info_by_udn(
hass, "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL"
@ -658,23 +588,6 @@ async def test_getting_existing_headers(
ssdp.ATTR_UPNP_DEVICE_TYPE: "Paulus",
ssdp.ATTR_UPNP_UDN: "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL",
}
# Compatibility with old dict access (to be removed after 2022.6)
assert discovery_info_by_udn[ssdp.ATTR_SSDP_EXT] == ""
assert discovery_info_by_udn[ssdp.ATTR_SSDP_LOCATION] == "http://1.1.1.1"
assert discovery_info_by_udn[ssdp.ATTR_SSDP_SERVER] == "mock-server"
assert discovery_info_by_udn[ssdp.ATTR_SSDP_ST] == "mock-st"
assert (
discovery_info_by_udn[ssdp.ATTR_SSDP_USN]
== "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL::urn:mdx-netflix-com:service:target:3"
)
assert (
discovery_info_by_udn[ssdp.ATTR_UPNP_UDN]
== "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL"
)
assert discovery_info_by_udn[ssdp.ATTR_UPNP_DEVICE_TYPE] == "Paulus"
assert discovery_info_by_udn[ssdp.ATTR_SSDP_UDN] == ANY
assert discovery_info_by_udn["_timestamp"] == ANY
# End of compatibility checks
discovery_info_by_udn_st = await ssdp.async_get_discovery_info_by_udn_st(
hass, "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL", "mock-st"
@ -693,23 +606,6 @@ async def test_getting_existing_headers(
ssdp.ATTR_UPNP_DEVICE_TYPE: "Paulus",
ssdp.ATTR_UPNP_UDN: "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL",
}
# Compatibility with old dict access (to be removed after 2022.6)
assert discovery_info_by_udn_st[ssdp.ATTR_SSDP_EXT] == ""
assert discovery_info_by_udn_st[ssdp.ATTR_SSDP_LOCATION] == "http://1.1.1.1"
assert discovery_info_by_udn_st[ssdp.ATTR_SSDP_SERVER] == "mock-server"
assert discovery_info_by_udn_st[ssdp.ATTR_SSDP_ST] == "mock-st"
assert (
discovery_info_by_udn_st[ssdp.ATTR_SSDP_USN]
== "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL::urn:mdx-netflix-com:service:target:3"
)
assert (
discovery_info_by_udn_st[ssdp.ATTR_UPNP_UDN]
== "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL"
)
assert discovery_info_by_udn_st[ssdp.ATTR_UPNP_DEVICE_TYPE] == "Paulus"
assert discovery_info_by_udn_st[ssdp.ATTR_SSDP_UDN] == ANY
assert discovery_info_by_udn_st["_timestamp"] == ANY
# End of compatibility checks
assert (
await ssdp.async_get_discovery_info_by_udn_st(hass, "wrong", "mock-st") is None
@ -845,61 +741,3 @@ async def test_ipv4_does_additional_search_for_sonos(
),
)
assert ssdp_listener.async_search.call_args[1] == {}
@pytest.mark.usefixtures("mock_integration_frame")
async def test_service_info_compatibility(hass, caplog):
"""Test compatibility with old-style dict.
To be removed in 2022.6
"""
discovery_info = ssdp.SsdpServiceInfo(
ssdp_st="mock-st",
ssdp_location="http://1.1.1.1",
ssdp_usn="uuid:mock-udn::mock-st",
ssdp_server="mock-server",
ssdp_ext="",
ssdp_headers=_ssdp_headers(
{
"st": "mock-st",
"location": "http://1.1.1.1",
"usn": "uuid:mock-udn::mock-st",
"server": "mock-server",
"ext": "",
}
),
upnp={ssdp.ATTR_UPNP_DEVICE_TYPE: "ABC"},
)
with patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()):
assert discovery_info["ssdp_st"] == "mock-st"
assert "Detected integration that accessed discovery_info['ssdp_st']" in caplog.text
with patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()):
assert discovery_info.get("ssdp_location") == "http://1.1.1.1"
assert (
"Detected integration that accessed discovery_info.get('ssdp_location')"
in caplog.text
)
with patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()):
assert "ssdp_usn" in discovery_info
assert (
"Detected integration that accessed discovery_info.__contains__('ssdp_usn')"
in caplog.text
)
# Root item
assert discovery_info["ssdp_usn"] == "uuid:mock-udn::mock-st"
assert discovery_info.get("ssdp_usn") == "uuid:mock-udn::mock-st"
assert "ssdp_usn" in discovery_info
# SSDP header
assert discovery_info["st"] == "mock-st"
assert discovery_info.get("st") == "mock-st"
assert "st" in discovery_info
# UPnP item
assert discovery_info[ssdp.ATTR_UPNP_DEVICE_TYPE] == "ABC"
assert discovery_info.get(ssdp.ATTR_UPNP_DEVICE_TYPE) == "ABC"
assert ssdp.ATTR_UPNP_DEVICE_TYPE in discovery_info