]> git.basschouten.com Git - openhab-addons.git/blob
9c84aa7e6d851e17fc2cddccf3d86113e46035b2
[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.onkyo.internal.automation.modules;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.onkyo.internal.handler.OnkyoHandler;
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 OnkyoThingActions}
28  *
29  * @author David Masshardt - initial contribution
30  */
31 @ThingActionsScope(name = "onkyo")
32 @NonNullByDefault
33 public class OnkyoThingActions implements ThingActions {
34
35     private final Logger logger = LoggerFactory.getLogger(OnkyoThingActions.class);
36
37     private @Nullable OnkyoHandler handler;
38
39     @SuppressWarnings("null")
40     @RuleAction(label = "send a raw command", description = "Send a raw command to the receiver.")
41     public void sendRawCommand(@ActionInput(name = "command") @Nullable String command,
42             @ActionInput(name = "command") @Nullable String value) {
43         logger.debug("sendRawCommand called with raw command: {} value: {}", command, value);
44         if (handler == null) {
45             logger.warn("Onkyo Action service ThingHandler is null!");
46             return;
47         }
48         handler.sendRawCommand(command, value);
49     }
50
51     public static void sendRawCommand(@Nullable ThingActions actions, @Nullable String command,
52             @Nullable String value) {
53         if (actions instanceof OnkyoThingActions) {
54             ((OnkyoThingActions) actions).sendRawCommand(command, value);
55         } else {
56             throw new IllegalArgumentException("Actions is not an instance of OnkyoThingActions");
57         }
58     }
59
60     @Override
61     public void setThingHandler(@Nullable ThingHandler handler) {
62         if (handler instanceof OnkyoHandler) {
63             this.handler = (OnkyoHandler) handler;
64         }
65     }
66
67     @Override
68     public @Nullable ThingHandler getThingHandler() {
69         return handler;
70     }
71 }