2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.automation.pidcontroller.internal.factory;
15 import java.util.Collection;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.automation.pidcontroller.internal.handler.PIDControllerActionHandler;
21 import org.openhab.automation.pidcontroller.internal.handler.PIDControllerTriggerHandler;
22 import org.openhab.core.automation.Action;
23 import org.openhab.core.automation.Module;
24 import org.openhab.core.automation.Trigger;
25 import org.openhab.core.automation.handler.BaseModuleHandlerFactory;
26 import org.openhab.core.automation.handler.ModuleHandler;
27 import org.openhab.core.automation.handler.ModuleHandlerFactory;
28 import org.openhab.core.events.EventPublisher;
29 import org.openhab.core.items.ItemRegistry;
30 import org.osgi.framework.BundleContext;
31 import org.osgi.service.component.annotations.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
37 * @author Hilbrand Bouwkamp - Initial Contribution
39 @Component(service = ModuleHandlerFactory.class, configurationPid = "action.pidcontroller")
41 public class PIDControllerModuleHandlerFactory extends BaseModuleHandlerFactory {
42 private static final Collection<String> TYPES = Set.of(PIDControllerTriggerHandler.MODULE_TYPE_ID,
43 PIDControllerActionHandler.MODULE_TYPE_ID);
44 private ItemRegistry itemRegistry;
45 private EventPublisher eventPublisher;
46 private BundleContext bundleContext;
49 public PIDControllerModuleHandlerFactory(@Reference ItemRegistry itemRegistry,
50 @Reference EventPublisher eventPublisher, BundleContext bundleContext) {
51 this.itemRegistry = itemRegistry;
52 this.eventPublisher = eventPublisher;
53 this.bundleContext = bundleContext;
57 public Collection<String> getTypes() {
62 protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
63 switch (module.getTypeUID()) {
64 case PIDControllerTriggerHandler.MODULE_TYPE_ID:
65 return new PIDControllerTriggerHandler((Trigger) module, itemRegistry, eventPublisher, bundleContext);
66 case PIDControllerActionHandler.MODULE_TYPE_ID:
67 return new PIDControllerActionHandler((Action) module, itemRegistry, eventPublisher);