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.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 a 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 IpCameraHandler localHandler = handler;
54 if (localHandler != null) {
55 localHandler.recordMp4(filename != null ? filename : "ipcamera", secondsToRecord);
59 public static void recordMP4(ThingActions actions, @Nullable String filename, int secondsToRecord) {
60 ((IpCameraActions) actions).recordMP4(filename, secondsToRecord);
63 @RuleAction(label = "record a GIF", description = "Record GIF to a set filename if given, or if filename is null to ipcamera.gif")
64 public void recordGIF(
65 @ActionInput(name = "filename", label = "Filename", description = "Name that the recording will have once created, don't include the .mp4.") @Nullable String filename,
66 @ActionInput(name = "secondsToRecord", label = "Seconds to Record", description = "Enter a number of how many seconds to record.") int secondsToRecord) {
67 logger.debug("Recording {}.gif for {} seconds.", filename, secondsToRecord);
68 IpCameraHandler localHandler = handler;
69 if (localHandler != null) {
70 localHandler.recordGif(filename != null ? filename : "ipcamera", secondsToRecord);
74 public static void recordGIF(ThingActions actions, @Nullable String filename, int secondsToRecord) {
75 ((IpCameraActions) actions).recordGIF(filename, secondsToRecord);