2 * Copyright (c) 2010-2024 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.freeboxos.internal.action;
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;
27 * The {PlayerActions} class is responsible to call corresponding actions on Freebox Player
29 * @author Gaƫl L'hopital - Initial contribution
31 @ThingActionsScope(name = "freeboxos")
33 public class PlayerActions implements ThingActions {
34 private final Logger logger = LoggerFactory.getLogger(PlayerActions.class);
35 protected @Nullable PlayerHandler handler;
38 public void setThingHandler(@Nullable ThingHandler handler) {
39 if (handler instanceof PlayerHandler playerHandler) {
40 this.handler = playerHandler;
45 public @Nullable ThingHandler getThingHandler() {
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);
56 logger.warn("Freebox Player Action service ThingHandler is null");
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);
67 logger.warn("Freebox Player Action service ThingHandler is null");
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);
78 logger.warn("Freebox Player Action service ThingHandler is null");
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);
89 logger.warn("Freebox Player Action service ThingHandler is null");