]> git.basschouten.com Git - openhab-addons.git/blob
2ec2bd009881780d7f175a8495fd5d5b82efd9d3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.PIDControllerTriggerHandler;
21 import org.openhab.core.automation.Module;
22 import org.openhab.core.automation.Trigger;
23 import org.openhab.core.automation.handler.BaseModuleHandlerFactory;
24 import org.openhab.core.automation.handler.ModuleHandler;
25 import org.openhab.core.automation.handler.ModuleHandlerFactory;
26 import org.openhab.core.events.EventPublisher;
27 import org.openhab.core.items.ItemRegistry;
28 import org.osgi.framework.BundleContext;
29 import org.osgi.service.component.annotations.Activate;
30 import org.osgi.service.component.annotations.Component;
31 import org.osgi.service.component.annotations.Reference;
32
33 /**
34  *
35  * @author Hilbrand Bouwkamp - Initial Contribution
36  */
37 @Component(service = ModuleHandlerFactory.class, configurationPid = "action.pidcontroller")
38 @NonNullByDefault
39 public class PIDControllerModuleHandlerFactory extends BaseModuleHandlerFactory {
40     private static final Collection<String> TYPES = Set.of(PIDControllerTriggerHandler.MODULE_TYPE_ID);
41     private ItemRegistry itemRegistry;
42     private EventPublisher eventPublisher;
43     private BundleContext bundleContext;
44
45     @Activate
46     public PIDControllerModuleHandlerFactory(@Reference ItemRegistry itemRegistry,
47             @Reference EventPublisher eventPublisher, BundleContext bundleContext) {
48         this.itemRegistry = itemRegistry;
49         this.eventPublisher = eventPublisher;
50         this.bundleContext = bundleContext;
51     }
52
53     @Override
54     public Collection<String> getTypes() {
55         return TYPES;
56     }
57
58     @Override
59     protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
60         switch (module.getTypeUID()) {
61             case PIDControllerTriggerHandler.MODULE_TYPE_ID:
62                 return new PIDControllerTriggerHandler((Trigger) module, itemRegistry, eventPublisher, bundleContext);
63         }
64
65         return null;
66     }
67 }