def validate_integration(config: Config, integration: Integration): """Validate config flow of an 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") return needs_unique_id = integration.domain not in UNIQUE_ID_IGNORE and any( bool(integration.manifest.get(key)) for keys in DISCOVERY_INTEGRATIONS.values() for key in keys) if not needs_unique_id: return config_flow = config_flow_file.read_text() 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) if has_unique_id: return if config.specific_integrations: notice_method = integration.add_warning else: notice_method = integration.add_error notice_method( "config_flow", "Config flows that are discoverable need to set a unique ID")
def calc_allowed_references(integration: Integration) -> Set[str]: """Return a set of allowed references.""" allowed_references = ( ALLOWED_USED_COMPONENTS | set(integration.manifest["dependencies"]) | set(integration.manifest.get("after_dependencies", []))) # Discovery requirements are ok if referenced in manifest for check_domain, to_check in DISCOVERY_INTEGRATIONS.items(): if any(check in integration.manifest for check in to_check): allowed_references.add(check_domain) return allowed_references