1
mirror of https://github.com/home-assistant/core synced 2024-10-01 05:30:36 +02:00

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:
Marcel van der Veldt 2021-12-07 21:50:34 +01:00 committed by GitHub
parent 4a814405c2
commit 7c7df5bb51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 15 deletions

View File

@ -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,

View File

@ -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."""

View File

@ -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

View File

@ -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
)

View File

@ -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):