ConfigFlow default discovery without unique ID (#36754)
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
import json
|
||||
from typing import Dict
|
||||
|
||||
from homeassistant.requirements import DISCOVERY_INTEGRATIONS
|
||||
|
||||
from .model import Config, Integration
|
||||
|
||||
BASE = """
|
||||
@@ -25,20 +23,36 @@ def validate_integration(config: Config, integration: Integration):
|
||||
config_flow_file = integration.path / "config_flow.py"
|
||||
|
||||
if not config_flow_file.is_file():
|
||||
integration.add_error(
|
||||
"config_flow", "Config flows need to be defined in the file config_flow.py"
|
||||
)
|
||||
if integration.get("config_flow"):
|
||||
integration.add_error(
|
||||
"config_flow",
|
||||
"Config flows need to be defined in the file config_flow.py",
|
||||
)
|
||||
if integration.get("homekit"):
|
||||
integration.add_error(
|
||||
"config_flow",
|
||||
"HomeKit information in a manifest requires a config flow to exist",
|
||||
)
|
||||
if integration.get("ssdp"):
|
||||
integration.add_error(
|
||||
"config_flow",
|
||||
"SSDP information in a manifest requires a config flow to exist",
|
||||
)
|
||||
if integration.get("zeroconf"):
|
||||
integration.add_error(
|
||||
"config_flow",
|
||||
"Zeroconf information in a manifest requires a config flow to exist",
|
||||
)
|
||||
return
|
||||
|
||||
config_flow = config_flow_file.read_text()
|
||||
|
||||
needs_unique_id = integration.domain not in UNIQUE_ID_IGNORE and (
|
||||
"async_step_hassio" in config_flow
|
||||
or any(
|
||||
bool(integration.manifest.get(key))
|
||||
for keys in DISCOVERY_INTEGRATIONS.values()
|
||||
for key in keys
|
||||
)
|
||||
"async_step_discovery" in config_flow
|
||||
or "async_step_hassio" in config_flow
|
||||
or "async_step_homekit" in config_flow
|
||||
or "async_step_ssdp" in config_flow
|
||||
or "async_step_zeroconf" in config_flow
|
||||
)
|
||||
|
||||
if not needs_unique_id:
|
||||
@@ -46,8 +60,9 @@ def validate_integration(config: Config, integration: Integration):
|
||||
|
||||
has_unique_id = (
|
||||
"self.async_set_unique_id" in config_flow
|
||||
or "config_entry_flow.register_discovery_flow" in config_flow
|
||||
or "config_entry_oauth2_flow.AbstractOAuth2FlowHandler" in config_flow
|
||||
or "self._async_handle_discovery_without_unique_id" in config_flow
|
||||
or "register_discovery_flow" in config_flow
|
||||
or "AbstractOAuth2FlowHandler" in config_flow
|
||||
)
|
||||
|
||||
if has_unique_id:
|
||||
@@ -73,9 +88,12 @@ def generate_and_validate(integrations: Dict[str, Integration], config: Config):
|
||||
if not integration.manifest:
|
||||
continue
|
||||
|
||||
config_flow = integration.manifest.get("config_flow")
|
||||
|
||||
if not config_flow:
|
||||
if not (
|
||||
integration.manifest.get("config_flow")
|
||||
or integration.manifest.get("homekit")
|
||||
or integration.manifest.get("ssdp")
|
||||
or integration.manifest.get("zeroconf")
|
||||
):
|
||||
continue
|
||||
|
||||
validate_integration(config, integration)
|
||||
|
||||
@@ -38,22 +38,6 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
if not ssdp:
|
||||
continue
|
||||
|
||||
try:
|
||||
with open(str(integration.path / "config_flow.py")) as fp:
|
||||
content = fp.read()
|
||||
if (
|
||||
" async_step_ssdp" not in content
|
||||
and "AbstractOAuth2FlowHandler" not in content
|
||||
and "register_discovery_flow" not in content
|
||||
):
|
||||
integration.add_error("ssdp", "Config flow has no async_step_ssdp")
|
||||
continue
|
||||
except FileNotFoundError:
|
||||
integration.add_error(
|
||||
"ssdp", "SSDP info in a manifest requires a config flow to exist"
|
||||
)
|
||||
continue
|
||||
|
||||
for matcher in ssdp:
|
||||
data[domain].append(sort_dict(matcher))
|
||||
|
||||
|
||||
@@ -34,42 +34,7 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
homekit = integration.manifest.get("homekit", {})
|
||||
homekit_models = homekit.get("models", [])
|
||||
|
||||
if not service_types and not homekit_models:
|
||||
continue
|
||||
|
||||
try:
|
||||
with open(str(integration.path / "config_flow.py")) as fp:
|
||||
content = fp.read()
|
||||
uses_discovery_flow = "register_discovery_flow" in content
|
||||
uses_oauth2_flow = "AbstractOAuth2FlowHandler" in content
|
||||
|
||||
if (
|
||||
service_types
|
||||
and not uses_discovery_flow
|
||||
and not uses_oauth2_flow
|
||||
and " async_step_zeroconf" not in content
|
||||
):
|
||||
integration.add_error(
|
||||
"zeroconf", "Config flow has no async_step_zeroconf"
|
||||
)
|
||||
continue
|
||||
|
||||
if (
|
||||
homekit_models
|
||||
and not uses_discovery_flow
|
||||
and not uses_oauth2_flow
|
||||
and " async_step_homekit" not in content
|
||||
):
|
||||
integration.add_error(
|
||||
"zeroconf", "Config flow has no async_step_homekit"
|
||||
)
|
||||
continue
|
||||
|
||||
except FileNotFoundError:
|
||||
integration.add_error(
|
||||
"zeroconf",
|
||||
"Zeroconf info in a manifest requires a config flow to exist",
|
||||
)
|
||||
if not (service_types or homekit_models):
|
||||
continue
|
||||
|
||||
for service_type in service_types:
|
||||
|
||||
Reference in New Issue
Block a user