diff --git a/homeassistant/components/ssdp/descriptions.py b/homeassistant/components/ssdp/descriptions.py index a6fda3685f2..def302641ed 100644 --- a/homeassistant/components/ssdp/descriptions.py +++ b/homeassistant/components/ssdp/descriptions.py @@ -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.""" diff --git a/tests/components/ssdp/test_init.py b/tests/components/ssdp/test_init.py index 6dfdc02f6e7..f5418bd227e 100644 --- a/tests/components/ssdp/test_init.py +++ b/tests/components/ssdp/test_init.py @@ -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."""