Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change check for existence of options flow #61147

Merged
merged 7 commits into from Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions homeassistant/components/config/config_entries.py
Expand Up @@ -366,13 +366,11 @@ async def ignore_config_flow(hass, connection, msg):
def entry_json(entry: config_entries.ConfigEntry) -> dict:
"""Return JSON value of a config entry."""
handler = config_entries.HANDLERS.get(entry.domain)
supports_options = (
# Guard in case handler is no longer registered (custom component etc)
handler is not None
# pylint: disable=comparison-with-callable
and handler.async_get_options_flow
!= config_entries.ConfigFlow.async_get_options_flow
# work out if handler has support for options flow
supports_options = handler is not None and handler.async_supports_options_flow(
entry
)

return {
"entry_id": entry.entry_id,
"domain": entry.domain,
Expand Down
15 changes: 10 additions & 5 deletions homeassistant/components/hue/config_flow.py
Expand Up @@ -12,7 +12,7 @@
import slugify as unicode_slug
import voluptuous as vol

from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components import ssdp, zeroconf
from homeassistant.const import CONF_API_KEY, CONF_HOST
from homeassistant.core import callback
Expand Down Expand Up @@ -48,10 +48,15 @@ def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
) -> HueOptionsFlowHandler:
"""Get the options flow for this handler."""
if config_entry.data.get(CONF_API_VERSION, 1) == 1:
# Options for Hue are only applicable to V1 bridges.
return HueOptionsFlowHandler(config_entry)
raise data_entry_flow.UnknownHandler
return HueOptionsFlowHandler(config_entry)

@classmethod
@callback
def async_supports_options_flow(
cls, config_entry: config_entries.ConfigEntry
) -> bool:
"""Return options flow support for this handler."""
return config_entry.data.get(CONF_API_VERSION, 1) == 1

def __init__(self) -> None:
"""Initialize the Hue flow."""
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/config_entries.py
Expand Up @@ -1163,6 +1163,12 @@ def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow:
"""Get the options flow for this handler."""
raise data_entry_flow.UnknownHandler

@classmethod
@callback
def async_supports_options_flow(cls, config_entry: ConfigEntry) -> bool:
"""Return options flow support for this handler."""
return cls.async_get_options_flow is not ConfigFlow.async_get_options_flow

@callback
def _async_abort_entries_match(
self, match_dict: dict[str, Any] | None = None
Expand Down
8 changes: 7 additions & 1 deletion tests/components/config/test_config_entries.py
Expand Up @@ -47,10 +47,16 @@ class Comp1ConfigFlow:

@staticmethod
@callback
def async_get_options_flow(config, options):
def async_get_options_flow(config_entry):
"""Get options flow."""
pass

@classmethod
@callback
def async_supports_options_flow(cls, config_entry):
"""Return options flow support for this handler."""
return True

hass.helpers.config_entry_flow.register_discovery_flow(
"comp2", "Comp 2", lambda: None
)
Expand Down
5 changes: 2 additions & 3 deletions tests/components/hue/test_config_flow.py
Expand Up @@ -7,7 +7,7 @@
import pytest
import voluptuous as vol

from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries
from homeassistant.components import ssdp, zeroconf
from homeassistant.components.hue import config_flow, const
from homeassistant.components.hue.errors import CannotConnect
Expand Down Expand Up @@ -706,8 +706,7 @@ async def test_options_flow_v2(hass):
)
entry.add_to_hass(hass)

with pytest.raises(data_entry_flow.UnknownHandler):
await hass.config_entries.options.async_init(entry.entry_id)
assert config_flow.HueFlowHandler.async_supports_options_flow(entry) is False


async def test_bridge_zeroconf(hass, aioclient_mock):
Expand Down