2 * Copyright (c) 2010-2023 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.chromecast.internal.action;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.chromecast.internal.handler.ChromecastHandler;
18 import org.openhab.core.automation.annotation.ActionInput;
19 import org.openhab.core.automation.annotation.ActionOutput;
20 import org.openhab.core.automation.annotation.RuleAction;
21 import org.openhab.core.thing.binding.ThingActions;
22 import org.openhab.core.thing.binding.ThingActionsScope;
23 import org.openhab.core.thing.binding.ThingHandler;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * The {@link ChromecastActions} class defines rule actions for playing URLs
30 * @author Scott Hanson - Initial contribution
32 @ThingActionsScope(name = "chromecast")
34 public class ChromecastActions implements ThingActions {
36 private final Logger logger = LoggerFactory.getLogger(ChromecastActions.class);
38 private @Nullable ChromecastHandler handler;
40 @RuleAction(label = "@text/playURLActionLabel", description = "@text/playURLActionDescription")
41 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean playURL(
42 @ActionInput(name = "url") @Nullable String url) {
44 logger.warn("Cannot Play as URL is missing.");
48 final ChromecastHandler handler = this.handler;
49 if (handler == null) {
50 logger.warn("Handler is null, cannot play.");
53 return handler.playURL(null, url, null);
57 @RuleAction(label = "@text/playURLTypeActionLabel", description = "@text/playURLTypeActionDescription")
58 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean playURL(
59 @ActionInput(name = "url") @Nullable String url,
60 @ActionInput(name = "mediaType") @Nullable String mediaType) {
62 logger.warn("Cannot Play as URL is missing.");
66 final ChromecastHandler handler = this.handler;
67 if (handler == null) {
68 logger.warn("Handler is null, cannot tweet.");
71 return handler.playURL(null, url, mediaType);
75 public static boolean playURL(ThingActions actions, @Nullable String url) {
76 return ((ChromecastActions) actions).playURL(url);
79 public static boolean playURL(ThingActions actions, @Nullable String url, @Nullable String mediaType) {
80 return ((ChromecastActions) actions).playURL(url, mediaType);
84 public void setThingHandler(@Nullable ThingHandler handler) {
85 if (handler instanceof ChromecastHandler chromecastHandler) {
86 this.handler = chromecastHandler;
91 public @Nullable ThingHandler getThingHandler() {