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.osgi.service.component.annotations.Component;
24 import org.osgi.service.component.annotations.ServiceScope;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * The {PlayerActions} class is responsible to call corresponding actions on Freebox Player
31 * @author Gaƫl L'hopital - Initial contribution
33 @Component(scope = ServiceScope.PROTOTYPE, service = PlayerActions.class)
34 @ThingActionsScope(name = "freeboxos")
36 public class PlayerActions implements ThingActions {
37 private final Logger logger = LoggerFactory.getLogger(PlayerActions.class);
38 protected @Nullable PlayerHandler handler;
41 public void setThingHandler(@Nullable ThingHandler handler) {
42 if (handler instanceof PlayerHandler playerHandler) {
43 this.handler = playerHandler;
48 public @Nullable ThingHandler getThingHandler() {
52 @RuleAction(label = "send a key to player", description = "Sends a given key to the player")
53 public void sendKey(@ActionInput(name = "key") String key) {
54 logger.debug("Sending key {} to player", key);
55 PlayerHandler playerHandler = this.handler;
56 if (playerHandler != null) {
57 playerHandler.sendKey(key, false, 1);
59 logger.warn("Freebox Player Action service ThingHandler is null");
63 @RuleAction(label = "send a long key to player", description = "Sends a given key to the player and keep it pressed")
64 public void sendLongKey(@ActionInput(name = "key") String key) {
65 logger.debug("Sending long press key {} to player", key);
66 PlayerHandler playerHandler = this.handler;
67 if (playerHandler != null) {
68 playerHandler.sendKey(key, true, 1);
70 logger.warn("Freebox Player Action service ThingHandler is null");
74 @RuleAction(label = "send multiple keys to player", description = "Sends multiple keys to the player, comma separated")
75 public void sendMultipleKeys(@ActionInput(name = "keys") String keys) {
76 logger.debug("Sending keys {} to player", keys);
77 PlayerHandler playerHandler = this.handler;
78 if (playerHandler != null) {
79 playerHandler.sendMultipleKeys(keys);
81 logger.warn("Freebox Player Action service ThingHandler is null");
85 @RuleAction(label = "send repeating key to player", description = "Sends a given key multiple times to the player")
86 public void sendKeyRepeat(@ActionInput(name = "key") String key, @ActionInput(name = "count") int count) {
87 logger.debug("Sending key {} to player {} times", key, count);
88 PlayerHandler playerHandler = this.handler;
89 if (playerHandler != null) {
90 playerHandler.sendKey(key, false, count);
92 logger.warn("Freebox Player Action service ThingHandler is null");