Fix Espalexa being detected as Hue Bridge (#29237)

This commit is contained in:
Franck Nijhof 2019-12-01 06:28:42 +01:00 committed by Paulus Schoutsen
parent c0619944fa
commit d5efd0b352
2 changed files with 27 additions and 4 deletions

View file

@ -16,6 +16,7 @@ from .const import DOMAIN, LOGGER
from .errors import AuthenticationRequired, CannotConnect
HUE_MANUFACTURERURL = "http://www.philips.com"
HUE_IGNORED_BRIDGE_NAMES = ["HASS Bridge", "Espalexa"]
@callback
@ -133,14 +134,16 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
This flow is triggered by the SSDP component. It will check if the
host is already configured and delegate to the import step if not.
"""
from homeassistant.components.ssdp import ATTR_MANUFACTURERURL
from homeassistant.components.ssdp import ATTR_MANUFACTURERURL, ATTR_NAME
if discovery_info[ATTR_MANUFACTURERURL] != HUE_MANUFACTURERURL:
return self.async_abort(reason="not_hue_bridge")
# Filter out emulated Hue
if "HASS Bridge" in discovery_info.get("name", ""):
return self.async_abort(reason="already_configured")
if any(
name in discovery_info.get(ATTR_NAME, "")
for name in HUE_IGNORED_BRIDGE_NAMES
):
return self.async_abort(reason="not_hue_bridge")
host = self.context["host"] = discovery_info.get("host")

View file

@ -230,6 +230,26 @@ async def test_bridge_ssdp_emulated_hue(hass):
)
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."""
flow = config_flow.HueFlowHandler()
flow.hass = hass
flow.context = {}
result = await flow.async_step_ssdp(
{
"name": "Espalexa (0.0.0.0)",
"host": "0.0.0.0",
"serial": "1234",
"manufacturerURL": config_flow.HUE_MANUFACTURERURL,
}
)
assert result["type"] == "abort"
assert result["reason"] == "not_hue_bridge"
async def test_bridge_ssdp_already_configured(hass):