]> git.basschouten.com Git - openhab-addons.git/blob
1086a0bfcaf1ef0c0e96afbbf1c3a1d190565ea3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.automower.internal.actions;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.automower.internal.things.AutomowerCommand;
18 import org.openhab.binding.automower.internal.things.AutomowerHandler;
19 import org.openhab.core.automation.annotation.ActionInput;
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;
26
27 /**
28  * @author Markus Pfleger - Initial contribution
29  */
30 @ThingActionsScope(name = "automower")
31 @NonNullByDefault
32 public class AutomowerActions implements ThingActions {
33     private final Logger logger = LoggerFactory.getLogger(AutomowerActions.class);
34     private @Nullable AutomowerHandler handler;
35
36     @Override
37     public void setThingHandler(@Nullable ThingHandler handler) {
38         this.handler = (AutomowerHandler) handler;
39     }
40
41     @Override
42     public @Nullable AutomowerHandler getThingHandler() {
43         return handler;
44     }
45
46     @RuleAction(label = "@text/action-start-label", description = "@text/action-start-desc")
47     public void start(
48             @ActionInput(name = "duration", label = "@text/action-input-duration-label", description = "@text/action-input-duration-desc") int durationMin) {
49         AutomowerHandler automowerHandler = handler;
50         if (automowerHandler == null) {
51             logger.warn("Automower Action service ThingHandler is null!");
52         } else {
53             automowerHandler.sendAutomowerCommand(AutomowerCommand.START, durationMin);
54         }
55     }
56
57     public static void start(@Nullable ThingActions actions, int durationMin) {
58         if (actions instanceof AutomowerActions) {
59             ((AutomowerActions) actions).start(durationMin);
60         } else {
61             throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
62         }
63     }
64
65     @RuleAction(label = "@text/action-pause-label", description = "@text/action-pause-desc")
66     public void pause() {
67         AutomowerHandler automowerHandler = handler;
68         if (automowerHandler == null) {
69             logger.warn("Automower Action service ThingHandler is null!");
70         } else {
71             automowerHandler.sendAutomowerCommand(AutomowerCommand.PAUSE);
72         }
73     }
74
75     public static void pause(@Nullable ThingActions actions) {
76         if (actions instanceof AutomowerActions) {
77             ((AutomowerActions) actions).pause();
78         } else {
79             throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
80         }
81     }
82
83     @RuleAction(label = "@text/action-parkuntilnextschedule-label", description = "@text/action-parkuntilnextschedule-desc")
84     public void parkUntilNextSchedule() {
85         AutomowerHandler automowerHandler = handler;
86         if (automowerHandler == null) {
87             logger.warn("Automower Action service ThingHandler is null!");
88         } else {
89             automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK_UNTIL_NEXT_SCHEDULE);
90         }
91     }
92
93     public static void parkUntilNextSchedule(@Nullable ThingActions actions) {
94         if (actions instanceof AutomowerActions) {
95             ((AutomowerActions) actions).parkUntilNextSchedule();
96         } else {
97             throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
98         }
99     }
100
101     @RuleAction(label = "@text/action-parkuntilfurthernotice-label", description = "@text/action-parkuntilfurthernotice-desc")
102     public void parkUntilFurtherNotice() {
103         AutomowerHandler automowerHandler = handler;
104         if (automowerHandler == null) {
105             logger.warn("Automower Action service ThingHandler is null!");
106         } else {
107             automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK_UNTIL_FURTHER_NOTICE);
108         }
109     }
110
111     public static void parkUntilFurtherNotice(@Nullable ThingActions actions) {
112         if (actions instanceof AutomowerActions) {
113             ((AutomowerActions) actions).parkUntilFurtherNotice();
114         } else {
115             throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
116         }
117     }
118
119     @RuleAction(label = "@text/action-park-label", description = "@text/action-park-desc")
120     public void park(
121             @ActionInput(name = "duration", label = "@text/action-input-duration-label", description = "@text/action-input-duration-desc") int durationMin) {
122         AutomowerHandler automowerHandler = handler;
123         if (automowerHandler == null) {
124             logger.warn("Automower Action service ThingHandler is null!");
125         } else {
126             automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK, durationMin);
127         }
128     }
129
130     public static void park(@Nullable ThingActions actions, int durationMin) {
131         if (actions instanceof AutomowerActions) {
132             ((AutomowerActions) actions).park(durationMin);
133         } else {
134             throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
135         }
136     }
137
138     @RuleAction(label = "@text/action-resumeschedule-label", description = "@text/action-resumeschedule-desc")
139     public void resumeSchedule() {
140         AutomowerHandler automowerHandler = handler;
141         if (automowerHandler == null) {
142             logger.warn("Automower Action service ThingHandler is null!");
143         } else {
144             automowerHandler.sendAutomowerCommand(AutomowerCommand.RESUME_SCHEDULE);
145         }
146     }
147
148     public static void resumeSchedule(@Nullable ThingActions actions) {
149         if (actions instanceof AutomowerActions) {
150             ((AutomowerActions) actions).resumeSchedule();
151         } else {
152             throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
153         }
154     }
155 }