]> git.basschouten.com Git - openhab-addons.git/blob
26ef622e7f7f511a4af24a34a01f5ef8aa317294
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.osgi.service.component.annotations.Component;
24 import org.osgi.service.component.annotations.ServiceScope;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * The {PlayerActions} class is responsible to call corresponding actions on Freebox Player
30  *
31  * @author GaĆ«l L'hopital - Initial contribution
32  */
33 @Component(scope = ServiceScope.PROTOTYPE, service = PlayerActions.class)
34 @ThingActionsScope(name = "freeboxos")
35 @NonNullByDefault
36 public class PlayerActions implements ThingActions {
37     private final Logger logger = LoggerFactory.getLogger(PlayerActions.class);
38     protected @Nullable PlayerHandler handler;
39
40     @Override
41     public void setThingHandler(@Nullable ThingHandler handler) {
42         if (handler instanceof PlayerHandler playerHandler) {
43             this.handler = playerHandler;
44         }
45     }
46
47     @Override
48     public @Nullable ThingHandler getThingHandler() {
49         return this.handler;
50     }
51
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);
58         } else {
59             logger.warn("Freebox Player Action service ThingHandler is null");
60         }
61     }
62
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);
69         } else {
70             logger.warn("Freebox Player Action service ThingHandler is null");
71         }
72     }
73
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);
80         } else {
81             logger.warn("Freebox Player Action service ThingHandler is null");
82         }
83     }
84
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);
91         } else {
92             logger.warn("Freebox Player Action service ThingHandler is null");
93         }
94     }
95 }