Ensure hue options show the defaults when the config options have not yet been saved (#47067)
parent
8ab163eda8
commit
6af67c9558
|
@ -18,6 +18,8 @@ from .bridge import authenticate_bridge
|
|||
from .const import ( # pylint: disable=unused-import
|
||||
CONF_ALLOW_HUE_GROUPS,
|
||||
CONF_ALLOW_UNREACHABLE,
|
||||
DEFAULT_ALLOW_HUE_GROUPS,
|
||||
DEFAULT_ALLOW_UNREACHABLE,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
)
|
||||
|
@ -246,13 +248,13 @@ class HueOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
vol.Optional(
|
||||
CONF_ALLOW_HUE_GROUPS,
|
||||
default=self.config_entry.options.get(
|
||||
CONF_ALLOW_HUE_GROUPS, False
|
||||
CONF_ALLOW_HUE_GROUPS, DEFAULT_ALLOW_HUE_GROUPS
|
||||
),
|
||||
): bool,
|
||||
vol.Optional(
|
||||
CONF_ALLOW_UNREACHABLE,
|
||||
default=self.config_entry.options.get(
|
||||
CONF_ALLOW_UNREACHABLE, False
|
||||
CONF_ALLOW_UNREACHABLE, DEFAULT_ALLOW_UNREACHABLE
|
||||
),
|
||||
): bool,
|
||||
}
|
||||
|
|
|
@ -12,6 +12,6 @@ CONF_ALLOW_UNREACHABLE = "allow_unreachable"
|
|||
DEFAULT_ALLOW_UNREACHABLE = False
|
||||
|
||||
CONF_ALLOW_HUE_GROUPS = "allow_hue_groups"
|
||||
DEFAULT_ALLOW_HUE_GROUPS = True
|
||||
DEFAULT_ALLOW_HUE_GROUPS = False
|
||||
|
||||
DEFAULT_SCENE_TRANSITION = 4
|
||||
|
|
|
@ -640,6 +640,15 @@ async def test_options_flow(hass):
|
|||
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "init"
|
||||
schema = result["data_schema"].schema
|
||||
assert (
|
||||
_get_schema_default(schema, const.CONF_ALLOW_HUE_GROUPS)
|
||||
== const.DEFAULT_ALLOW_HUE_GROUPS
|
||||
)
|
||||
assert (
|
||||
_get_schema_default(schema, const.CONF_ALLOW_UNREACHABLE)
|
||||
== const.DEFAULT_ALLOW_UNREACHABLE
|
||||
)
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
|
@ -654,3 +663,11 @@ async def test_options_flow(hass):
|
|||
const.CONF_ALLOW_HUE_GROUPS: True,
|
||||
const.CONF_ALLOW_UNREACHABLE: True,
|
||||
}
|
||||
|
||||
|
||||
def _get_schema_default(schema, key_name):
|
||||
"""Iterate schema to find a key."""
|
||||
for schema_key in schema:
|
||||
if schema_key == key_name:
|
||||
return schema_key.default()
|
||||
raise KeyError(f"{key_name} not found in schema")
|
||||
|
|
Loading…
Reference in New Issue