Handle empty ssdp descriptions in the cache (#51253)

This commit is contained in:
J. Nick Koston 2021-05-29 22:50:48 -05:00 committed by GitHub
parent 3ca7eb9440
commit 32dc62a996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -42,7 +42,7 @@ class DescriptionManager:
@callback
def async_cached_description(self, xml_location: str) -> None | dict[str, str]:
"""Fetch the description from the cache."""
return self._description_cache[xml_location]
return self._description_cache.get(xml_location)
async def _fetch_description(self, xml_location: str) -> None | dict[str, str]:
"""Fetch an XML description."""

View File

@ -189,6 +189,7 @@ async def test_scan_description_fetch_fail(hass, aioclient_mock, exc):
aioclient_mock.get("http://1.1.1.1", exc=exc)
mock_ssdp_response = {
"st": "mock-st",
"usn": "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL::urn:mdx-netflix-com:service:target:3",
"location": "http://1.1.1.1",
}
mock_get_ssdp = {
@ -203,6 +204,15 @@ async def test_scan_description_fetch_fail(hass, aioclient_mock, exc):
assert not mock_init.mock_calls
assert ssdp.async_get_discovery_info_by_st(hass, "mock-st") == [
{
"UDN": "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL",
"ssdp_location": "http://1.1.1.1",
"ssdp_st": "mock-st",
"ssdp_usn": "uuid:TIVRTLSR7ANF-D6E-1557809135086-RETAIL::urn:mdx-netflix-com:service:target:3",
}
]
async def test_scan_description_parse_fail(hass, aioclient_mock):
"""Test invalid XML."""