Load the SSDP component only when it's needed (#24420)

* fix(hue): Load the SSDP component only when it's needed

* fix(deconz): Don't load the SSDP component when it's not needed

* Update config_flow.py

* Update test_config_flow.py
pull/24460/head
Julien Brochet 2019-06-10 18:11:07 +02:00 committed by Paulus Schoutsen
parent 84e6813779
commit fadfb89b4c
3 changed files with 11 additions and 7 deletions

View File

@ -9,7 +9,6 @@ from pydeconz.utils import (
async_discovery, async_get_api_key, async_get_bridgeid)
from homeassistant import config_entries
from homeassistant.components.ssdp import ATTR_MANUFACTURERURL, ATTR_SERIAL
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT
from homeassistant.core import callback
from homeassistant.helpers import aiohttp_client
@ -154,6 +153,9 @@ class DeconzFlowHandler(config_entries.ConfigFlow):
async def async_step_ssdp(self, discovery_info):
"""Handle a discovered deCONZ bridge."""
from homeassistant.components.ssdp import (
ATTR_MANUFACTURERURL, ATTR_SERIAL)
if discovery_info[ATTR_MANUFACTURERURL] != DECONZ_MANUFACTURERURL:
return self.async_abort(reason='not_deconz_bridge')

View File

@ -8,7 +8,6 @@ import async_timeout
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components.ssdp import ATTR_MANUFACTURERURL
from homeassistant.core import callback
from homeassistant.helpers import aiohttp_client
@ -146,6 +145,8 @@ class HueFlowHandler(config_entries.ConfigFlow):
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
if discovery_info[ATTR_MANUFACTURERURL] != HUE_MANUFACTURERURL:
return self.async_abort(reason='not_hue_bridge')

View File

@ -4,6 +4,7 @@ from unittest.mock import Mock, patch
import asyncio
from homeassistant.components.deconz import config_flow
from homeassistant.components.ssdp import ATTR_MANUFACTURERURL, ATTR_SERIAL
from tests.common import MockConfigEntry
import pydeconz
@ -175,8 +176,8 @@ async def test_bridge_ssdp_discovery(hass):
data={
config_flow.CONF_HOST: '1.2.3.4',
config_flow.CONF_PORT: 80,
config_flow.ATTR_SERIAL: 'id',
config_flow.ATTR_MANUFACTURERURL:
ATTR_SERIAL: 'id',
ATTR_MANUFACTURERURL:
config_flow.DECONZ_MANUFACTURERURL,
config_flow.ATTR_UUID: 'uuid:1234'
},
@ -192,7 +193,7 @@ async def test_bridge_ssdp_discovery_not_deconz_bridge(hass):
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
data={
config_flow.ATTR_MANUFACTURERURL: 'not deconz bridge'
ATTR_MANUFACTURERURL: 'not deconz bridge'
},
context={'source': 'ssdp'}
)
@ -217,8 +218,8 @@ async def test_bridge_discovery_update_existing_entry(hass):
config_flow.DOMAIN,
data={
config_flow.CONF_HOST: 'mock-deconz',
config_flow.ATTR_SERIAL: 'id',
config_flow.ATTR_MANUFACTURERURL:
ATTR_SERIAL: 'id',
ATTR_MANUFACTURERURL:
config_flow.DECONZ_MANUFACTURERURL,
config_flow.ATTR_UUID: 'uuid:1234'
},