]> git.basschouten.com Git - openhab-addons.git/blob
63affbd0da43f3ec1bc7faeb9141b80cf6fd185d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.ipcamera.internal;
14
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;
25
26 /**
27  * The {@link IpCameraActions} is responsible for Actions.
28  *
29  * @author Matthew Skinner - Initial contribution
30  */
31
32 @ThingActionsScope(name = "ipcamera")
33 @NonNullByDefault
34 public class IpCameraActions implements ThingActions {
35     public final Logger logger = LoggerFactory.getLogger(getClass());
36     private @Nullable IpCameraHandler handler;
37
38     @Override
39     public void setThingHandler(@Nullable ThingHandler handler) {
40         this.handler = (IpCameraHandler) handler;
41     }
42
43     @Override
44     public @Nullable ThingHandler getThingHandler() {
45         return handler;
46     }
47
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);
56         }
57     }
58
59     public static void recordMP4(ThingActions actions, @Nullable String filename, int secondsToRecord) {
60         ((IpCameraActions) actions).recordMP4(filename, secondsToRecord);
61     }
62
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);
71         }
72     }
73
74     public static void recordGIF(ThingActions actions, @Nullable String filename, int secondsToRecord) {
75         ((IpCameraActions) actions).recordGIF(filename, secondsToRecord);
76     }
77 }