-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chromecast] Added play URL actions to chromecast binding (#10245)
* Added play url actions to chromeCast binding Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>
- Loading branch information
1 parent
849442c
commit 5f1dd38
Showing
5 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...ecast/src/main/java/org/openhab/binding/chromecast/internal/action/ChromecastActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.chromecast.internal.action; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.binding.chromecast.internal.handler.ChromecastHandler; | ||
import org.openhab.core.automation.annotation.ActionInput; | ||
import org.openhab.core.automation.annotation.ActionOutput; | ||
import org.openhab.core.automation.annotation.RuleAction; | ||
import org.openhab.core.thing.binding.ThingActions; | ||
import org.openhab.core.thing.binding.ThingActionsScope; | ||
import org.openhab.core.thing.binding.ThingHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link ChromecastActions} class defines rule actions for playing URLs | ||
* | ||
* @author Scott Hanson - Added Actions | ||
*/ | ||
@ThingActionsScope(name = "chromecast") | ||
@NonNullByDefault | ||
public class ChromecastActions implements ThingActions { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(ChromecastActions.class); | ||
|
||
private @Nullable ChromecastHandler handler; | ||
|
||
@RuleAction(label = "@text/playURLActionLabel", description = "@text/playURLActionDescription") | ||
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean playURL( | ||
@ActionInput(name = "url") @Nullable String url) { | ||
if (url == null) { | ||
logger.warn("Cannot Play as URL is missing."); | ||
return false; | ||
} | ||
|
||
final ChromecastHandler handler = this.handler; | ||
if (handler == null) { | ||
logger.warn("Handler is null, cannot play."); | ||
return false; | ||
} else { | ||
return handler.playURL(url, null); | ||
} | ||
} | ||
|
||
@RuleAction(label = "@text/playURLTypeActionLabel", description = "@text/playURLTypeActionDescription") | ||
public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean playURL( | ||
@ActionInput(name = "url") @Nullable String url, | ||
@ActionInput(name = "mediaType") @Nullable String mediaType) { | ||
if (url == null) { | ||
logger.warn("Cannot Play as URL is missing."); | ||
return false; | ||
} | ||
|
||
final ChromecastHandler handler = this.handler; | ||
if (handler == null) { | ||
logger.warn("Handler is null, cannot tweet."); | ||
return false; | ||
} else { | ||
return handler.playURL(url, mediaType); | ||
} | ||
} | ||
|
||
public static boolean playURL(ThingActions actions, @Nullable String url) { | ||
return ((ChromecastActions) actions).playURL(url); | ||
} | ||
|
||
public static boolean playURL(ThingActions actions, @Nullable String url, @Nullable String mediaType) { | ||
return ((ChromecastActions) actions).playURL(url, mediaType); | ||
} | ||
|
||
@Override | ||
public void setThingHandler(@Nullable ThingHandler handler) { | ||
if (handler instanceof ChromecastHandler) { | ||
this.handler = (ChromecastHandler) handler; | ||
} | ||
} | ||
|
||
@Override | ||
public @Nullable ThingHandler getThingHandler() { | ||
return handler; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
bundles/org.openhab.binding.chromecast/src/main/resources/OH-INF/i18n/chromecast.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# actions | ||
playURLActionLabel = play a URL | ||
playURLActionDescription = Plays a URL. | ||
|
||
playURLTypeActionLabel = play a URL with a media type | ||
playURLTypeActionDescription = Plays a URL with a defined media type attribute. |