Change check for existence of options flow (#61147)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
4a814405c2
commit
7c7df5bb51
5 changed files with 29 additions and 15 deletions
|
@ -366,13 +366,11 @@ async def ignore_config_flow(hass, connection, msg):
|
||||||
def entry_json(entry: config_entries.ConfigEntry) -> dict:
|
def entry_json(entry: config_entries.ConfigEntry) -> dict:
|
||||||
"""Return JSON value of a config entry."""
|
"""Return JSON value of a config entry."""
|
||||||
handler = config_entries.HANDLERS.get(entry.domain)
|
handler = config_entries.HANDLERS.get(entry.domain)
|
||||||
supports_options = (
|
# work out if handler has support for options flow
|
||||||
# Guard in case handler is no longer registered (custom component etc)
|
supports_options = handler is not None and handler.async_supports_options_flow(
|
||||||
handler is not None
|
entry
|
||||||
# pylint: disable=comparison-with-callable
|
|
||||||
and handler.async_get_options_flow
|
|
||||||
!= config_entries.ConfigFlow.async_get_options_flow
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"entry_id": entry.entry_id,
|
"entry_id": entry.entry_id,
|
||||||
"domain": entry.domain,
|
"domain": entry.domain,
|
||||||
|
|
|
@ -12,7 +12,7 @@ import async_timeout
|
||||||
import slugify as unicode_slug
|
import slugify as unicode_slug
|
||||||
import voluptuous as vol
|
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 import ssdp, zeroconf
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_HOST
|
from homeassistant.const import CONF_API_KEY, CONF_HOST
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
@ -48,10 +48,15 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
config_entry: config_entries.ConfigEntry,
|
config_entry: config_entries.ConfigEntry,
|
||||||
) -> HueOptionsFlowHandler:
|
) -> HueOptionsFlowHandler:
|
||||||
"""Get the options flow for this handler."""
|
"""Get the options flow for this handler."""
|
||||||
if config_entry.data.get(CONF_API_VERSION, 1) == 1:
|
return HueOptionsFlowHandler(config_entry)
|
||||||
# Options for Hue are only applicable to V1 bridges.
|
|
||||||
return HueOptionsFlowHandler(config_entry)
|
@classmethod
|
||||||
raise data_entry_flow.UnknownHandler
|
@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:
|
def __init__(self) -> None:
|
||||||
"""Initialize the Hue flow."""
|
"""Initialize the Hue flow."""
|
||||||
|
|
|
@ -1163,6 +1163,12 @@ class ConfigFlow(data_entry_flow.FlowHandler):
|
||||||
"""Get the options flow for this handler."""
|
"""Get the options flow for this handler."""
|
||||||
raise data_entry_flow.UnknownHandler
|
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
|
@callback
|
||||||
def _async_abort_entries_match(
|
def _async_abort_entries_match(
|
||||||
self, match_dict: dict[str, Any] | None = None
|
self, match_dict: dict[str, Any] | None = None
|
||||||
|
|
|
@ -47,10 +47,16 @@ async def test_get_entries(hass, client):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(config, options):
|
def async_get_options_flow(config_entry):
|
||||||
"""Get options flow."""
|
"""Get options flow."""
|
||||||
pass
|
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(
|
hass.helpers.config_entry_flow.register_discovery_flow(
|
||||||
"comp2", "Comp 2", lambda: None
|
"comp2", "Comp 2", lambda: None
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,7 +7,7 @@ from aiohue.errors import LinkButtonNotPressed
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
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 import ssdp, zeroconf
|
||||||
from homeassistant.components.hue import config_flow, const
|
from homeassistant.components.hue import config_flow, const
|
||||||
from homeassistant.components.hue.errors import CannotConnect
|
from homeassistant.components.hue.errors import CannotConnect
|
||||||
|
@ -706,8 +706,7 @@ async def test_options_flow_v2(hass):
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
with pytest.raises(data_entry_flow.UnknownHandler):
|
assert config_flow.HueFlowHandler.async_supports_options_flow(entry) is False
|
||||||
await hass.config_entries.options.async_init(entry.entry_id)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_zeroconf(hass, aioclient_mock):
|
async def test_bridge_zeroconf(hass, aioclient_mock):
|
||||||
|
|
Loading…
Add table
Reference in a new issue