mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Remove discovery (#17070)
This commit is contained in:
parent
02bf07d9df
commit
769dda735d
@ -12,9 +12,9 @@ import voluptuous as vol
|
|||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_FILENAME, CONF_HOST
|
from homeassistant.const import CONF_FILENAME, CONF_HOST
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
aiohttp_client, config_validation as cv, device_registry as dr)
|
config_validation as cv, device_registry as dr)
|
||||||
|
|
||||||
from .const import DOMAIN, API_NUPNP
|
from .const import DOMAIN
|
||||||
from .bridge import HueBridge
|
from .bridge import HueBridge
|
||||||
# Loading the config flow file will register the flow
|
# Loading the config flow file will register the flow
|
||||||
from .config_flow import configured_hosts
|
from .config_flow import configured_hosts
|
||||||
@ -62,37 +62,11 @@ async def async_setup(hass, config):
|
|||||||
configured = configured_hosts(hass)
|
configured = configured_hosts(hass)
|
||||||
|
|
||||||
# User has configured bridges
|
# User has configured bridges
|
||||||
if CONF_BRIDGES in conf:
|
if CONF_BRIDGES not in conf:
|
||||||
bridges = conf[CONF_BRIDGES]
|
|
||||||
|
|
||||||
# Component is part of config but no bridges specified, discover.
|
|
||||||
elif DOMAIN in config:
|
|
||||||
# discover from nupnp
|
|
||||||
websession = aiohttp_client.async_get_clientsession(hass)
|
|
||||||
|
|
||||||
async with websession.get(API_NUPNP) as req:
|
|
||||||
hosts = await req.json()
|
|
||||||
|
|
||||||
bridges = []
|
|
||||||
for entry in hosts:
|
|
||||||
# Filter out already configured hosts
|
|
||||||
if entry['internalipaddress'] in configured:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Run through config schema to populate defaults
|
|
||||||
bridges.append(BRIDGE_CONFIG_SCHEMA({
|
|
||||||
CONF_HOST: entry['internalipaddress'],
|
|
||||||
# Careful with using entry['id'] for other reasons. The
|
|
||||||
# value is in lowercase but is returned uppercase from hub.
|
|
||||||
CONF_FILENAME: '.hue_{}.conf'.format(entry['id']),
|
|
||||||
}))
|
|
||||||
else:
|
|
||||||
# Component not specified in config, we're loaded via discovery
|
|
||||||
bridges = []
|
|
||||||
|
|
||||||
if not bridges:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
bridges = conf[CONF_BRIDGES]
|
||||||
|
|
||||||
for bridge_conf in bridges:
|
for bridge_conf in bridges:
|
||||||
host = bridge_conf[CONF_HOST]
|
host = bridge_conf[CONF_HOST]
|
||||||
|
|
||||||
|
@ -20,62 +20,6 @@ async def test_setup_with_no_config(hass):
|
|||||||
assert hass.data[hue.DOMAIN] == {}
|
assert hass.data[hue.DOMAIN] == {}
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_with_discovery_no_known_auth(hass, aioclient_mock):
|
|
||||||
"""Test discovering a bridge and not having known auth."""
|
|
||||||
aioclient_mock.get(hue.API_NUPNP, json=[
|
|
||||||
{
|
|
||||||
'internalipaddress': '0.0.0.0',
|
|
||||||
'id': 'abcd1234'
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
|
||||||
patch.object(hue, 'configured_hosts', return_value=[]):
|
|
||||||
mock_config_entries.flow.async_init.return_value = mock_coro()
|
|
||||||
assert await async_setup_component(hass, hue.DOMAIN, {
|
|
||||||
hue.DOMAIN: {}
|
|
||||||
}) is True
|
|
||||||
|
|
||||||
# Flow started for discovered bridge
|
|
||||||
assert len(mock_config_entries.flow.mock_calls) == 1
|
|
||||||
assert mock_config_entries.flow.mock_calls[0][2]['data'] == {
|
|
||||||
'host': '0.0.0.0',
|
|
||||||
'path': '.hue_abcd1234.conf',
|
|
||||||
}
|
|
||||||
|
|
||||||
# Config stored for domain.
|
|
||||||
assert hass.data[hue.DOMAIN] == {
|
|
||||||
'0.0.0.0': {
|
|
||||||
hue.CONF_HOST: '0.0.0.0',
|
|
||||||
hue.CONF_FILENAME: '.hue_abcd1234.conf',
|
|
||||||
hue.CONF_ALLOW_HUE_GROUPS: hue.DEFAULT_ALLOW_HUE_GROUPS,
|
|
||||||
hue.CONF_ALLOW_UNREACHABLE: hue.DEFAULT_ALLOW_UNREACHABLE,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_with_discovery_known_auth(hass, aioclient_mock):
|
|
||||||
"""Test we don't do anything if we discover already configured hub."""
|
|
||||||
aioclient_mock.get(hue.API_NUPNP, json=[
|
|
||||||
{
|
|
||||||
'internalipaddress': '0.0.0.0',
|
|
||||||
'id': 'abcd1234'
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
|
||||||
patch.object(hue, 'configured_hosts', return_value=['0.0.0.0']):
|
|
||||||
assert await async_setup_component(hass, hue.DOMAIN, {
|
|
||||||
hue.DOMAIN: {}
|
|
||||||
}) is True
|
|
||||||
|
|
||||||
# Flow started for discovered bridge
|
|
||||||
assert len(mock_config_entries.flow.mock_calls) == 0
|
|
||||||
|
|
||||||
# Config stored for domain.
|
|
||||||
assert hass.data[hue.DOMAIN] == {}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_defined_hosts_known_auth(hass):
|
async def test_setup_defined_hosts_known_auth(hass):
|
||||||
"""Test we don't initiate a config entry if config bridge is known."""
|
"""Test we don't initiate a config entry if config bridge is known."""
|
||||||
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user