mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Use dataclass properties in hue discovery (#60598)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
601ad8f71a
commit
d75785d701
@ -194,26 +194,31 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""
|
||||
# Filter out non-Hue bridges #1
|
||||
if (
|
||||
discovery_info.get(ssdp.ATTR_UPNP_MANUFACTURER_URL)
|
||||
discovery_info.upnp.get(ssdp.ATTR_UPNP_MANUFACTURER_URL)
|
||||
not in HUE_MANUFACTURERURL
|
||||
):
|
||||
return self.async_abort(reason="not_hue_bridge")
|
||||
|
||||
# Filter out non-Hue bridges #2
|
||||
if any(
|
||||
name in discovery_info.get(ssdp.ATTR_UPNP_FRIENDLY_NAME, "")
|
||||
name in discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME, "")
|
||||
for name in HUE_IGNORED_BRIDGE_NAMES
|
||||
):
|
||||
return self.async_abort(reason="not_hue_bridge")
|
||||
|
||||
if (
|
||||
not discovery_info.get(ssdp.ATTR_SSDP_LOCATION)
|
||||
or ssdp.ATTR_UPNP_SERIAL not in discovery_info
|
||||
not discovery_info.ssdp_location
|
||||
or ssdp.ATTR_UPNP_SERIAL not in discovery_info.upnp
|
||||
):
|
||||
return self.async_abort(reason="not_hue_bridge")
|
||||
|
||||
host = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION]).hostname
|
||||
bridge = await self._get_bridge(host, discovery_info[ssdp.ATTR_UPNP_SERIAL])
|
||||
url = urlparse(discovery_info.ssdp_location)
|
||||
if not url.hostname:
|
||||
return self.async_abort(reason="not_hue_bridge")
|
||||
|
||||
bridge = await self._get_bridge(
|
||||
url.hostname, discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL]
|
||||
)
|
||||
|
||||
await self.async_set_unique_id(bridge.id)
|
||||
self._abort_if_unique_id_configured(
|
||||
@ -232,8 +237,8 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
host is already configured and delegate to the import step if not.
|
||||
"""
|
||||
bridge = await self._get_bridge(
|
||||
discovery_info[zeroconf.ATTR_HOST],
|
||||
discovery_info[zeroconf.ATTR_PROPERTIES]["bridgeid"],
|
||||
discovery_info.host,
|
||||
discovery_info.properties["bridgeid"],
|
||||
)
|
||||
|
||||
await self.async_set_unique_id(bridge.id)
|
||||
@ -253,7 +258,7 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
as the unique identifier. Therefore, this method uses discovery without
|
||||
a unique ID.
|
||||
"""
|
||||
self.bridge = await self._get_bridge(discovery_info[zeroconf.ATTR_HOST])
|
||||
self.bridge = await self._get_bridge(discovery_info.host)
|
||||
await self._async_handle_discovery_without_unique_id()
|
||||
return await self.async_step_link()
|
||||
|
||||
|
@ -423,6 +423,26 @@ async def test_bridge_ssdp_missing_serial(hass):
|
||||
assert result["reason"] == "not_hue_bridge"
|
||||
|
||||
|
||||
async def test_bridge_ssdp_invalid_location(hass):
|
||||
"""Test if discovery info is a serial attribute."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data=ssdp.SsdpServiceInfo(
|
||||
ssdp_usn="mock_usn",
|
||||
ssdp_st="mock_st",
|
||||
ssdp_location="http:///",
|
||||
upnp={
|
||||
ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.HUE_MANUFACTURERURL[0],
|
||||
ssdp.ATTR_UPNP_SERIAL: "1234",
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "not_hue_bridge"
|
||||
|
||||
|
||||
async def test_bridge_ssdp_espalexa(hass):
|
||||
"""Test if discovery info is from an Espalexa based device."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
Loading…
x
Reference in New Issue
Block a user