2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.dmx.internal.action;
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;
27 * The {@link DmxActions} provides actions for DMX Bridges
29 * @author Jan N. Klug - Initial contribution
31 @ThingActionsScope(name = "dmx")
33 public class DmxActions implements ThingActions {
35 private final Logger logger = LoggerFactory.getLogger(DmxActions.class);
37 private @Nullable DmxBridgeHandler handler;
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;
46 if (handler == null) {
47 logger.warn("DMX Action service ThingHandler is null!");
51 if (channels == null) {
52 logger.debug("skipping immediate DMX action {} due to missing channel(s)", fade);
57 logger.debug("skipping immediate DMX action channel(s) {} due to missing fade", channels);
61 if (resumeAfter == null) {
62 logger.debug("DMX action {} to channel(s) {} with default resumeAfter=false", fade, channels);
63 handler.immediateFade(channels, fade, false);
65 handler.immediateFade(channels, fade, resumeAfter);
69 public static void sendFade(ThingActions actions, @Nullable String channels, @Nullable String fade,
70 @Nullable Boolean resumeAfter) {
71 ((DmxActions) actions).sendFade(channels, fade, resumeAfter);
75 public void setThingHandler(@Nullable ThingHandler handler) {
76 if (handler instanceof DmxBridgeHandler bridgeHandler) {
77 this.handler = bridgeHandler;
82 public @Nullable ThingHandler getThingHandler() {