Netgear ssdp discovery abort if no serial (#87532)

fixes undefined
This commit is contained in:
starkillerOG 2023-02-08 22:38:44 +01:00 committed by GitHub
parent 014743a27c
commit 0ab30ece68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -135,6 +135,9 @@ class NetgearFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
_LOGGER.debug("Netgear ssdp discovery info: %s", discovery_info)
if ssdp.ATTR_UPNP_SERIAL not in discovery_info.upnp:
return self.async_abort(reason="no_serial")
await self.async_set_unique_id(discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL])
self._abort_if_unique_id_configured(updates=updated_data)

View File

@ -14,7 +14,9 @@
"config": "Connection or login error: please check your configuration"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"not_ipv4_address": "No IPv4 address in ssdp discovery information",
"no_serial": "No serial number in ssdp discovery information"
}
},
"options": {

View File

@ -236,6 +236,25 @@ async def test_ssdp_already_configured(hass: HomeAssistant) -> None:
assert result["reason"] == "already_configured"
async def test_ssdp_no_serial(hass: HomeAssistant) -> None:
"""Test ssdp abort when the ssdp info does not include a serial number."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_SSDP},
data=ssdp.SsdpServiceInfo(
ssdp_usn="mock_usn",
ssdp_st="mock_st",
ssdp_location=SSDP_URL,
upnp={
ssdp.ATTR_UPNP_MODEL_NUMBER: "RBR20",
ssdp.ATTR_UPNP_PRESENTATION_URL: URL,
},
),
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "no_serial"
async def test_ssdp_ipv6(hass: HomeAssistant) -> None:
"""Test ssdp abort when using a ipv6 address."""
MockConfigEntry(