]> git.basschouten.com Git - openhab-addons.git/blob
0014d9179f716e4c0e63d71b5c867f57812251a4
[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.pwm.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.pwm.internal.handler.PWMTriggerHandler;
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.items.ItemRegistry;
27 import org.osgi.framework.BundleContext;
28 import org.osgi.service.component.annotations.Activate;
29 import org.osgi.service.component.annotations.Component;
30 import org.osgi.service.component.annotations.Reference;
31
32 /**
33  * Factory for the PWM automation module.
34  *
35  * @author Fabian Wolter - Initial Contribution
36  */
37 @NonNullByDefault
38 @Component(service = ModuleHandlerFactory.class, configurationPid = "automation.pwm")
39 public class PWMModuleHandlerFactory extends BaseModuleHandlerFactory {
40     private static final Collection<String> TYPES = Set.of(PWMTriggerHandler.MODULE_TYPE_ID);
41     private ItemRegistry itemRegistry;
42     private BundleContext bundleContext;
43
44     @Activate
45     public PWMModuleHandlerFactory(@Reference ItemRegistry itemRegistry, BundleContext bundleContext) {
46         this.itemRegistry = itemRegistry;
47         this.bundleContext = bundleContext;
48     }
49
50     @Override
51     public Collection<String> getTypes() {
52         return TYPES;
53     }
54
55     @Override
56     protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
57         switch (module.getTypeUID()) {
58             case PWMTriggerHandler.MODULE_TYPE_ID:
59                 return new PWMTriggerHandler((Trigger) module, itemRegistry, bundleContext, ruleUID);
60         }
61
62         return null;
63     }
64 }