]> git.basschouten.com Git - openhab-addons.git/blob
6606513b944541647f81a48a81ef86a412ab877d
[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.io.hueemulation.internal.automation;
14
15 import java.util.Arrays;
16 import java.util.Collection;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.core.automation.Module;
21 import org.openhab.core.automation.Trigger;
22 import org.openhab.core.automation.handler.BaseModuleHandlerFactory;
23 import org.openhab.core.automation.handler.ModuleHandler;
24 import org.openhab.core.automation.handler.ModuleHandlerFactory;
25 import org.openhab.core.scheduler.Scheduler;
26 import org.osgi.service.component.annotations.Component;
27 import org.osgi.service.component.annotations.Deactivate;
28 import org.osgi.service.component.annotations.Reference;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * This factory is responsible for timer related module types.
34  *
35  * @author David Graeff - Initial contribution
36  */
37 @NonNullByDefault
38 @Component(service = ModuleHandlerFactory.class)
39 public class TimerModuleExHandlerFactory extends BaseModuleHandlerFactory {
40
41     private final Logger logger = LoggerFactory.getLogger(TimerModuleExHandlerFactory.class);
42
43     private static final Collection<String> TYPES = Arrays
44             .asList(new String[] { AbsoluteDateTimeTriggerHandler.MODULE_TYPE_ID, TimerTriggerHandler.MODULE_TYPE_ID });
45
46     @Reference
47     private @NonNullByDefault({}) Scheduler scheduler;
48
49     @Override
50     @Deactivate
51     public void deactivate() {
52         super.deactivate();
53     }
54
55     @Override
56     public Collection<String> getTypes() {
57         return TYPES;
58     }
59
60     @Override
61     protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
62         logger.trace("create {} -> {}", module.getId(), module.getTypeUID());
63         String moduleTypeUID = module.getTypeUID();
64         if (AbsoluteDateTimeTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Trigger) {
65             return new AbsoluteDateTimeTriggerHandler((Trigger) module, scheduler);
66         } else if (TimerTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Trigger) {
67             return new TimerTriggerHandler((Trigger) module, scheduler);
68         } else {
69             logger.error("The module handler type '{}' is not supported.", moduleTypeUID);
70         }
71         return null;
72     }
73 }