]> git.basschouten.com Git - openhab-addons.git/blob
b610dc2f960d431a4494cb0881fd0910de2f60e1
[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.binding.dmx.internal.action;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.dmx.internal.DmxBridgeHandler;
18 import org.openhab.core.automation.annotation.ActionInput;
19 import org.openhab.core.automation.annotation.RuleAction;
20 import org.openhab.core.thing.binding.ThingActions;
21 import org.openhab.core.thing.binding.ThingActionsScope;
22 import org.openhab.core.thing.binding.ThingHandler;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * The {@link DmxActions} provides actions for DMX Bridges
28  *
29  * @author Jan N. Klug - Initial contribution
30  */
31 @ThingActionsScope(name = "dmx")
32 @NonNullByDefault
33 public class DmxActions implements ThingActions {
34
35     private final Logger logger = LoggerFactory.getLogger(DmxActions.class);
36
37     private @Nullable DmxBridgeHandler handler;
38
39     @RuleAction(label = "immediately fade channels", description = "Immediately performs fade on selected DMX channels.")
40     public void sendFade(@ActionInput(name = "channels") @Nullable String channels,
41             @ActionInput(name = "fade") @Nullable String fade,
42             @ActionInput(name = "resumeAfter") @Nullable Boolean resumeAfter) {
43         logger.debug("thingHandlerAction called with inputs: {} {} {}", channels, fade, resumeAfter);
44         DmxBridgeHandler handler = this.handler;
45
46         if (handler == null) {
47             logger.warn("DMX Action service ThingHandler is null!");
48             return;
49         }
50
51         if (channels == null) {
52             logger.debug("skipping immediate DMX action {} due to missing channel(s)", fade);
53             return;
54         }
55
56         if (fade == null) {
57             logger.debug("skipping immediate DMX action channel(s) {} due to missing fade", channels);
58             return;
59         }
60
61         if (resumeAfter == null) {
62             logger.debug("DMX action {} to channel(s) {} with default resumeAfter=false", fade, channels);
63             handler.immediateFade(channels, fade, false);
64         } else {
65             handler.immediateFade(channels, fade, resumeAfter);
66         }
67     }
68
69     public static void sendFade(ThingActions actions, @Nullable String channels, @Nullable String fade,
70             @Nullable Boolean resumeAfter) {
71         ((DmxActions) actions).sendFade(channels, fade, resumeAfter);
72     }
73
74     @Override
75     public void setThingHandler(@Nullable ThingHandler handler) {
76         if (handler instanceof DmxBridgeHandler bridgeHandler) {
77             this.handler = bridgeHandler;
78         }
79     }
80
81     @Override
82     public @Nullable ThingHandler getThingHandler() {
83         return handler;
84     }
85 }