]> git.basschouten.com Git - openhab-addons.git/blob
89f1b50059cb46d96a653cf97ba0ab193d114ac7
[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.nuvo.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.nuvo.internal.handler.NuvoHandler;
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  * Some automation actions to be used with a {@link NuvoThingActions}
28  *
29  * @author Michael Lobstein - initial contribution
30  */
31 @ThingActionsScope(name = "nuvo")
32 @NonNullByDefault
33 public class NuvoThingActions implements ThingActions {
34
35     private final Logger logger = LoggerFactory.getLogger(NuvoThingActions.class);
36
37     private @Nullable NuvoHandler handler;
38
39     @RuleAction(label = "send a raw command", description = "Send a raw command to the amplifier.")
40     public void sendNuvoCommand(@ActionInput(name = "sendNuvoCommand") String rawCommand) {
41         NuvoHandler localHandler = handler;
42         if (localHandler != null) {
43             localHandler.handleRawCommand(rawCommand);
44             logger.debug("sendNuvoCommand called with raw command: {}", rawCommand);
45         } else {
46             logger.warn("unable to send command, NuvoHandler was null");
47         }
48     }
49
50     /** Static alias to support the old DSL rules engine and make the action available there. */
51     public static void sendNuvoCommand(ThingActions actions, String rawCommand) {
52         ((NuvoThingActions) actions).sendNuvoCommand(rawCommand);
53     }
54
55     @Override
56     public void setThingHandler(@Nullable ThingHandler handler) {
57         this.handler = (NuvoHandler) handler;
58     }
59
60     @Override
61     public @Nullable ThingHandler getThingHandler() {
62         return handler;
63     }
64 }