Disable Hue groups for new setups (#31713)

pull/31732/head
Paulus Schoutsen 2020-02-11 08:50:07 -08:00 committed by GitHub
parent 3df2cb6b78
commit 81b159f424
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 11 deletions

View File

@ -11,22 +11,22 @@ from homeassistant.const import CONF_HOST
from homeassistant.helpers import config_validation as cv, device_registry as dr
from .bridge import HueBridge
from .const import DOMAIN
from .const import (
CONF_ALLOW_HUE_GROUPS,
CONF_ALLOW_UNREACHABLE,
DEFAULT_ALLOW_HUE_GROUPS,
DEFAULT_ALLOW_UNREACHABLE,
DOMAIN,
)
_LOGGER = logging.getLogger(__name__)
CONF_BRIDGES = "bridges"
CONF_ALLOW_UNREACHABLE = "allow_unreachable"
DEFAULT_ALLOW_UNREACHABLE = False
DATA_CONFIGS = "hue_configs"
PHUE_CONFIG_FILE = "phue.conf"
CONF_ALLOW_HUE_GROUPS = "allow_hue_groups"
DEFAULT_ALLOW_HUE_GROUPS = True
BRIDGE_CONFIG_SCHEMA = vol.Schema(
{
# Validate as IP address and then convert back to a string.
@ -112,8 +112,10 @@ async def async_setup_entry(
config = hass.data[DATA_CONFIGS].get(host)
if config is None:
allow_unreachable = DEFAULT_ALLOW_UNREACHABLE
allow_groups = DEFAULT_ALLOW_HUE_GROUPS
allow_unreachable = entry.data.get(
CONF_ALLOW_UNREACHABLE, DEFAULT_ALLOW_UNREACHABLE
)
allow_groups = entry.data.get(CONF_ALLOW_HUE_GROUPS, DEFAULT_ALLOW_HUE_GROUPS)
else:
allow_unreachable = config[CONF_ALLOW_UNREACHABLE]
allow_groups = config[CONF_ALLOW_HUE_GROUPS]

View File

@ -14,7 +14,11 @@ from homeassistant.const import CONF_HOST
from homeassistant.helpers import aiohttp_client
from .bridge import authenticate_bridge
from .const import DOMAIN, LOGGER # pylint: disable=unused-import
from .const import ( # pylint: disable=unused-import
CONF_ALLOW_HUE_GROUPS,
DOMAIN,
LOGGER,
)
from .errors import AuthenticationRequired, CannotConnect
HUE_MANUFACTURERURL = "http://www.philips.com"
@ -125,7 +129,11 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_create_entry(
title=bridge.config.name,
data={"host": bridge.host, "username": bridge.username},
data={
"host": bridge.host,
"username": bridge.username,
CONF_ALLOW_HUE_GROUPS: False,
},
)
except AuthenticationRequired:
errors["base"] = "register_failed"

View File

@ -7,3 +7,9 @@ DOMAIN = "hue"
# How long to wait to actually do the refresh after requesting it.
# We wait some time so if we control multiple lights, we batch requests.
REQUEST_REFRESH_DELAY = 0.3
CONF_ALLOW_UNREACHABLE = "allow_unreachable"
DEFAULT_ALLOW_UNREACHABLE = False
CONF_ALLOW_HUE_GROUPS = "allow_hue_groups"
DEFAULT_ALLOW_HUE_GROUPS = True

View File

@ -79,6 +79,7 @@ async def test_flow_works(hass):
assert result["data"] == {
"host": "1.2.3.4",
"username": "home-assistant#test-home",
"allow_hue_groups": False,
}
assert len(mock_bridge.initialize.mock_calls) == 1
@ -440,6 +441,7 @@ async def test_creating_entry_removes_entries_for_same_host_or_bridge(hass):
assert result["data"] == {
"host": "2.2.2.2",
"username": "username-abc",
"allow_hue_groups": False,
}
entries = hass.config_entries.async_entries("hue")
assert len(entries) == 2