diff --git a/homeassistant/components/config/config_entries.py b/homeassistant/components/config/config_entries.py index b1f686e23a4..61df9dc190d 100644 --- a/homeassistant/components/config/config_entries.py +++ b/homeassistant/components/config/config_entries.py @@ -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, diff --git a/homeassistant/components/hue/config_flow.py b/homeassistant/components/hue/config_flow.py index ceb5a9a1a8e..49fca2158d5 100644 --- a/homeassistant/components/hue/config_flow.py +++ b/homeassistant/components/hue/config_flow.py @@ -12,7 +12,7 @@ import async_timeout 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 @@ -48,10 +48,15 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): 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.""" diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 45bc10f5774..cdea9da2540 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -1163,6 +1163,12 @@ class ConfigFlow(data_entry_flow.FlowHandler): """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 diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 8b890148d51..20a19495597 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -47,10 +47,16 @@ async def test_get_entries(hass, client): @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 ) diff --git a/tests/components/hue/test_config_flow.py b/tests/components/hue/test_config_flow.py index 65d3dd696d6..6ce8ff3e1c4 100644 --- a/tests/components/hue/test_config_flow.py +++ b/tests/components/hue/test_config_flow.py @@ -7,7 +7,7 @@ from aiohue.errors import LinkButtonNotPressed 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 @@ -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):