]> git.basschouten.com Git - openhab-addons.git/blob
1d7256f6d6a160852f11a9fd8f63e1f71b230228
[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  */
37 @NonNullByDefault
38 @Component(service = ModuleHandlerFactory.class)
39 public class NotificationModuleHandlerFactory extends BaseModuleHandlerFactory {
40
41     private static final Collection<String> TYPES = List.of(SendNotificationActionHandler.TYPE_ID,
42             SendNotificationActionHandler.EXTENDED_TYPE_ID, SendBroadcastNotificationActionHandler.TYPE_ID,
43             SendBroadcastNotificationActionHandler.EXTENDED_TYPE_ID, SendLogNotificationActionHandler.TYPE_ID,
44             SendLogNotificationActionHandler.EXTENDED_TYPE_ID);
45     private final CloudService cloudService;
46
47     @Activate
48     public NotificationModuleHandlerFactory(final @Reference CloudService cloudService) {
49         this.cloudService = cloudService;
50     }
51
52     @Override
53     @Deactivate
54     protected void deactivate() {
55         super.deactivate();
56     }
57
58     @Override
59     public Collection<String> getTypes() {
60         return TYPES;
61     }
62
63     @Override
64     protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
65         if (module instanceof Action action) {
66             switch (module.getTypeUID()) {
67                 case SendNotificationActionHandler.TYPE_ID:
68                 case SendNotificationActionHandler.EXTENDED_TYPE_ID:
69                     return new SendNotificationActionHandler(action, cloudService);
70                 case SendBroadcastNotificationActionHandler.TYPE_ID:
71                 case SendBroadcastNotificationActionHandler.EXTENDED_TYPE_ID:
72                     return new SendBroadcastNotificationActionHandler(action, cloudService);
73                 case SendLogNotificationActionHandler.TYPE_ID:
74                 case SendLogNotificationActionHandler.EXTENDED_TYPE_ID:
75                     return new SendLogNotificationActionHandler(action, cloudService);
76                 default:
77                     break;
78             }
79         }
80         return null;
81     }
82 }