]> git.basschouten.com Git - openhab-addons.git/blob
812149c81435065dde13f46f684e2f81be710ee3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.openhabcloud.internal.actions;
14
15 import java.util.Collection;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.core.automation.Action;
21 import org.openhab.core.automation.Module;
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.io.openhabcloud.internal.CloudService;
26 import org.osgi.service.component.annotations.Activate;
27 import org.osgi.service.component.annotations.Component;
28 import org.osgi.service.component.annotations.Deactivate;
29 import org.osgi.service.component.annotations.Reference;
30
31 /**
32  * This class provides a {@link ModuleHandlerFactory} implementation to provide actions to send notifications via
33  * openHAB Cloud.
34  *
35  * @author Christoph Weitkamp - Initial contribution
36  * @author Dan Cunningham - Extended notification enhancements
37  */
38 @NonNullByDefault
39 @Component(service = ModuleHandlerFactory.class)
40 public class NotificationModuleHandlerFactory extends BaseModuleHandlerFactory {
41
42     private static final Collection<String> TYPES = List.of(SendNotificationActionHandler.TYPE_ID,
43             SendNotificationActionHandler.EXTENDED_TYPE_ID, SendNotificationActionHandler.EXTENDED2_TYPE_ID,
44             SendBroadcastNotificationActionHandler.TYPE_ID, SendBroadcastNotificationActionHandler.EXTENDED_TYPE_ID,
45             SendBroadcastNotificationActionHandler.EXTENDED2_TYPE_ID, SendLogNotificationActionHandler.TYPE_ID,
46             SendLogNotificationActionHandler.EXTENDED_TYPE_ID);
47     private final CloudService cloudService;
48
49     @Activate
50     public NotificationModuleHandlerFactory(final @Reference CloudService cloudService) {
51         this.cloudService = cloudService;
52     }
53
54     @Override
55     @Deactivate
56     protected void deactivate() {
57         super.deactivate();
58     }
59
60     @Override
61     public Collection<String> getTypes() {
62         return TYPES;
63     }
64
65     @Override
66     protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
67         if (module instanceof Action action) {
68             switch (module.getTypeUID()) {
69                 case SendNotificationActionHandler.TYPE_ID:
70                 case SendNotificationActionHandler.EXTENDED_TYPE_ID:
71                 case SendNotificationActionHandler.EXTENDED2_TYPE_ID:
72                     return new SendNotificationActionHandler(action, cloudService);
73                 case SendBroadcastNotificationActionHandler.TYPE_ID:
74                 case SendBroadcastNotificationActionHandler.EXTENDED_TYPE_ID:
75                 case SendBroadcastNotificationActionHandler.EXTENDED2_TYPE_ID:
76                     return new SendBroadcastNotificationActionHandler(action, cloudService);
77                 case SendLogNotificationActionHandler.TYPE_ID:
78                 case SendLogNotificationActionHandler.EXTENDED_TYPE_ID:
79                     return new SendLogNotificationActionHandler(action, cloudService);
80                 default:
81                     break;
82             }
83         }
84         return null;
85     }
86 }