public void InitializeComponent(Component component, ComponentConfiguration configuration)
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var context = new WirehomeDictionary
            {
                ["component_uid"] = component.Uid
            };

            var adapterPackage = _packageManagerService.LoadPackage(configuration.Logic.Adapter.Uid);

            var adapter = new ScriptComponentAdapter(_pythonScriptHostFactoryService, _componentRegistryService, _scriptComponentAdapterLogger);

            adapter.Compile(component.Uid, adapterPackage.Script);

            if (configuration.Logic.Adapter.Variables != null)
            {
                foreach (var parameter in configuration.Logic.Adapter.Variables)
                {
                    adapter.SetVariable(parameter.Key, parameter.Value);
                }
            }

            context["adapter_uid"]     = adapterPackage.Uid.ToString();
            context["adapter_id"]      = adapterPackage.Uid.Id;
            context["adapter_version"] = adapterPackage.Uid.Version;

            if (string.IsNullOrEmpty(configuration.Logic.Uid?.Id))
            {
                component.SetLogic(new EmptyLogic(adapter));
            }
            else
            {
                var logicPackage = _packageManagerService.LoadPackage(configuration.Logic.Uid);

                var logic = new ScriptComponentLogic(_pythonScriptHostFactoryService, _componentRegistryService, _scriptComponentLogicLogger);
                adapter.MessagePublishedCallback      = message => logic.ProcessAdapterMessage(message);
                logic.AdapterMessagePublishedCallback = message => adapter.ProcessMessage(message);

                logic.Compile(component.Uid, logicPackage.Script);

                if (configuration.Logic.Variables != null)
                {
                    foreach (var parameter in configuration.Logic.Variables)
                    {
                        logic.SetVariable(parameter.Key, parameter.Value);
                    }
                }

                context["logic_uid"]     = logicPackage.Uid.ToString();
                context["logic_id"]      = logicPackage.Uid.Id;
                context["logic_version"] = logicPackage.Uid.Version;

                // TODO: Remove "scope" as soon as it is migrated.
                logic.SetVariable("scope", context);
                logic.SetVariable("context", context);
                logic.AddToWirehomeWrapper("context", context);

                component.SetLogic(logic);
            }

            // TODO: Remove "scope" as soon as it is migrated.
            adapter.SetVariable("scope", context);
            adapter.SetVariable("context", context);
            adapter.AddToWirehomeWrapper("context", context);
        }
        private void SetupComponentBasedOnPackages(Component component, ComponentConfiguration configuration, IDictionary <object, object> context)
        {
            Package                adapterPackage = null;
            IComponentAdapter      adapter;
            ScriptComponentAdapter scriptAdapter = null;

            if (configuration.Logic?.Adapter?.Uid != null)
            {
                adapterPackage = _packageManagerService.LoadPackage(configuration.Logic.Adapter.Uid);

                scriptAdapter = new ScriptComponentAdapter(_pythonScriptHostFactoryService, _componentRegistryService, _scriptComponentAdapterLogger);
                scriptAdapter.Compile(component.Uid, adapterPackage.Script);

                if (configuration.Logic.Adapter.Variables != null)
                {
                    foreach (var parameter in configuration.Logic.Adapter.Variables)
                    {
                        scriptAdapter.SetVariable(parameter.Key, parameter.Value);
                    }
                }

                adapter = scriptAdapter;
            }
            else
            {
                adapter = new EmptyComponentAdapter();
            }

            context["adapter_uid"]     = adapterPackage?.Uid?.ToString();
            context["adapter_id"]      = adapterPackage?.Uid?.Id;
            context["adapter_version"] = adapterPackage?.Uid?.Version;

            if (string.IsNullOrEmpty(configuration.Logic?.Uid?.Id))
            {
                component.SetLogic(new EmptyComponentLogic(adapter));
            }
            else
            {
                var logicPackage = _packageManagerService.LoadPackage(configuration.Logic.Uid);

                var logic = new ScriptComponentLogic(_pythonScriptHostFactoryService, _componentRegistryService, _scriptComponentLogicLogger);
                adapter.MessagePublishedCallback      = message => logic.ProcessAdapterMessage(message);
                logic.AdapterMessagePublishedCallback = message => adapter.ProcessMessage(message);

                logic.Compile(component.Uid, logicPackage.Script);

                if (configuration.Logic.Variables != null)
                {
                    foreach (var parameter in configuration.Logic.Variables)
                    {
                        logic.SetVariable(parameter.Key, parameter.Value);
                    }
                }

                context["logic_uid"]     = logicPackage.Uid.ToString();
                context["logic_id"]      = logicPackage.Uid.Id;
                context["logic_version"] = logicPackage.Uid.Version;

                logic.AddToWirehomeWrapper("context", context);

                component.SetLogic(logic);
            }

            scriptAdapter?.AddToWirehomeWrapper("context", context);
        }