2 * Copyright (c) 2010-2020 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.ipcamera.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.ipcamera.internal.handler.IpCameraHandler;
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 {@link IpCameraActions} is responsible for Actions.
29 * @author Matthew Skinner - Initial contribution
32 @ThingActionsScope(name = "ipcamera")
34 public class IpCameraActions implements ThingActions {
35 public final Logger logger = LoggerFactory.getLogger(getClass());
36 private @Nullable IpCameraHandler handler;
39 public void setThingHandler(@Nullable ThingHandler handler) {
40 this.handler = (IpCameraHandler) handler;
44 public @Nullable ThingHandler getThingHandler() {
48 @RuleAction(label = "record an MP4", description = "Record MP4 to a set filename if given, or if filename is null to ipcamera.mp4")
49 public void recordMP4(
50 @ActionInput(name = "filename", label = "Filename", description = "Name that the recording will have once created, don't include the .mp4.") @Nullable String filename,
51 @ActionInput(name = "secondsToRecord", label = "Seconds to Record", description = "Enter a number of how many seconds to record.") int secondsToRecord) {
52 logger.debug("Recording {}.mp4 for {} seconds.", filename, secondsToRecord);
53 if (filename == null && handler != null) {
54 handler.recordMp4("ipcamera", secondsToRecord);
55 } else if (handler != null && filename != null) {
56 handler.recordMp4(filename, secondsToRecord);
60 public static void recordMP4(ThingActions actions, @Nullable String filename, int secondsToRecord) {
61 ((IpCameraActions) actions).recordMP4(filename, secondsToRecord);
64 @RuleAction(label = "record a GIF", description = "Record GIF to a set filename if given, or if filename is null to ipcamera.gif")
65 public void recordGIF(
66 @ActionInput(name = "filename", label = "Filename", description = "Name that the recording will have once created, don't include the .mp4.") @Nullable String filename,
67 @ActionInput(name = "secondsToRecord", label = "Seconds to Record", description = "Enter a number of how many seconds to record.") int secondsToRecord) {
68 logger.debug("Recording {}.gif for {} seconds.", filename, secondsToRecord);
69 if (filename == null && handler != null) {
70 handler.recordGif("ipcamera", secondsToRecord);
71 } else if (handler != null && filename != null) {
72 handler.recordGif(filename, secondsToRecord);
76 public static void recordGIF(ThingActions actions, @Nullable String filename, int secondsToRecord) {
77 ((IpCameraActions) actions).recordGIF(filename, secondsToRecord);