]> git.basschouten.com Git - openhab-addons.git/blob
6a5fad50bb925ecf2d8d4379058884840a31fcff
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.kaleidescape.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.kaleidescape.internal.handler.KaleidescapeHandler;
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 KaleidescapeThingActions}
28  *
29  * @author Michael Lobstein - initial contribution
30  */
31 @ThingActionsScope(name = "kaleidescape")
32 @NonNullByDefault
33 public class KaleidescapeThingActions implements ThingActions {
34     private final Logger logger = LoggerFactory.getLogger(KaleidescapeThingActions.class);
35
36     private @Nullable KaleidescapeHandler handler;
37
38     @RuleAction(label = "send a raw command", description = "Action that sends raw command to the kaleidescape zone.")
39     public void sendKCommand(@ActionInput(name = "sendKCommand") String kCommand) {
40         KaleidescapeHandler localHandler = handler;
41         if (localHandler != null) {
42             localHandler.handleRawCommand(kCommand);
43             logger.debug("sendKCommand called with command: {}", kCommand);
44         } else {
45             logger.warn("unable to send command, KaleidescapeHandler was null");
46         }
47     }
48
49     /** Static alias to support the old DSL rules engine and make the action available there. */
50     public static void sendKCommand(@Nullable ThingActions actions, String kCommand) throws IllegalArgumentException {
51         if (actions instanceof KaleidescapeThingActions) {
52             ((KaleidescapeThingActions) actions).sendKCommand(kCommand);
53         } else {
54             throw new IllegalArgumentException("Actions is not an instance of KaleidescapeThingActions");
55         }
56     }
57
58     @Override
59     public void setThingHandler(@Nullable ThingHandler handler) {
60         this.handler = (KaleidescapeHandler) handler;
61     }
62
63     @Override
64     public @Nullable ThingHandler getThingHandler() {
65         return handler;
66     }
67 }