]> git.basschouten.com Git - openhab-addons.git/blob
f8817bd6abd6f159f8dd39ece0aacd917776e722
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.automation.pidcontroller.internal.factory;
14
15 import java.util.Collection;
16 import java.util.Set;
17
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;
34
35 /**
36  *
37  * @author Hilbrand Bouwkamp - Initial Contribution
38  */
39 @Component(service = ModuleHandlerFactory.class, configurationPid = "action.pidcontroller")
40 @NonNullByDefault
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;
47
48     @Activate
49     public PIDControllerModuleHandlerFactory(@Reference ItemRegistry itemRegistry,
50             @Reference EventPublisher eventPublisher, BundleContext bundleContext) {
51         this.itemRegistry = itemRegistry;
52         this.eventPublisher = eventPublisher;
53         this.bundleContext = bundleContext;
54     }
55
56     @Override
57     public Collection<String> getTypes() {
58         return TYPES;
59     }
60
61     @Override
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);
68         }
69
70         return null;
71     }
72 }