]> git.basschouten.com Git - openhab-addons.git/blob
b1e7d619102c4e9a4867a4f6fdce1c216ae6760b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.freeboxos.internal.action;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.freeboxos.internal.handler.PlayerHandler;
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 {PlayerActions} class is responsible to call corresponding actions on Freebox Player
28  *
29  * @author GaĆ«l L'hopital - Initial contribution
30  */
31 @ThingActionsScope(name = "freeboxos")
32 @NonNullByDefault
33 public class PlayerActions implements ThingActions {
34     private final Logger logger = LoggerFactory.getLogger(PlayerActions.class);
35     protected @Nullable PlayerHandler handler;
36
37     @Override
38     public void setThingHandler(@Nullable ThingHandler handler) {
39         if (handler instanceof PlayerHandler playerHandler) {
40             this.handler = playerHandler;
41         }
42     }
43
44     @Override
45     public @Nullable ThingHandler getThingHandler() {
46         return this.handler;
47     }
48
49     @RuleAction(label = "send a key to player", description = "Sends a given key to the player")
50     public void sendKey(@ActionInput(name = "key") String key) {
51         logger.debug("Sending key {} to player", key);
52         PlayerHandler playerHandler = this.handler;
53         if (playerHandler != null) {
54             playerHandler.sendKey(key, false, 1);
55         } else {
56             logger.warn("Freebox Player Action service ThingHandler is null");
57         }
58     }
59
60     @RuleAction(label = "send a long key to player", description = "Sends a given key to the player and keep it pressed")
61     public void sendLongKey(@ActionInput(name = "key") String key) {
62         logger.debug("Sending long press key {} to player", key);
63         PlayerHandler playerHandler = this.handler;
64         if (playerHandler != null) {
65             playerHandler.sendKey(key, true, 1);
66         } else {
67             logger.warn("Freebox Player Action service ThingHandler is null");
68         }
69     }
70
71     @RuleAction(label = "send multiple keys to player", description = "Sends multiple keys to the player, comma separated")
72     public void sendMultipleKeys(@ActionInput(name = "keys") String keys) {
73         logger.debug("Sending keys {} to player", keys);
74         PlayerHandler playerHandler = this.handler;
75         if (playerHandler != null) {
76             playerHandler.sendMultipleKeys(keys);
77         } else {
78             logger.warn("Freebox Player Action service ThingHandler is null");
79         }
80     }
81
82     @RuleAction(label = "send repeating key to player", description = "Sends a given key multiple times to the player")
83     public void sendKeyRepeat(@ActionInput(name = "key") String key, @ActionInput(name = "count") int count) {
84         logger.debug("Sending key {} to player {} times", key, count);
85         PlayerHandler playerHandler = this.handler;
86         if (playerHandler != null) {
87             playerHandler.sendKey(key, false, count);
88         } else {
89             logger.warn("Freebox Player Action service ThingHandler is null");
90         }
91     }
92 }