]> git.basschouten.com Git - openhab-addons.git/blob
185ebadce6bc2e760fc72640da310f4f7fc477aa
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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(ThingActions actions, int durationMin) {
58         ((AutomowerActions) actions).start(durationMin);
59     }
60
61     @RuleAction(label = "@text/action-pause-label", description = "@text/action-pause-desc")
62     public void pause() {
63         AutomowerHandler automowerHandler = handler;
64         if (automowerHandler == null) {
65             logger.warn("Automower Action service ThingHandler is null!");
66         } else {
67             automowerHandler.sendAutomowerCommand(AutomowerCommand.PAUSE);
68         }
69     }
70
71     public static void pause(ThingActions actions) {
72         ((AutomowerActions) actions).pause();
73     }
74
75     @RuleAction(label = "@text/action-parkuntilnextschedule-label", description = "@text/action-parkuntilnextschedule-desc")
76     public void parkUntilNextSchedule() {
77         AutomowerHandler automowerHandler = handler;
78         if (automowerHandler == null) {
79             logger.warn("Automower Action service ThingHandler is null!");
80         } else {
81             automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK_UNTIL_NEXT_SCHEDULE);
82         }
83     }
84
85     public static void parkUntilNextSchedule(ThingActions actions) {
86         ((AutomowerActions) actions).parkUntilNextSchedule();
87     }
88
89     @RuleAction(label = "@text/action-parkuntilfurthernotice-label", description = "@text/action-parkuntilfurthernotice-desc")
90     public void parkUntilFurtherNotice() {
91         AutomowerHandler automowerHandler = handler;
92         if (automowerHandler == null) {
93             logger.warn("Automower Action service ThingHandler is null!");
94         } else {
95             automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK_UNTIL_FURTHER_NOTICE);
96         }
97     }
98
99     public static void parkUntilFurtherNotice(ThingActions actions) {
100         ((AutomowerActions) actions).parkUntilFurtherNotice();
101     }
102
103     @RuleAction(label = "@text/action-park-label", description = "@text/action-park-desc")
104     public void park(
105             @ActionInput(name = "duration", label = "@text/action-input-duration-label", description = "@text/action-input-duration-desc") int durationMin) {
106         AutomowerHandler automowerHandler = handler;
107         if (automowerHandler == null) {
108             logger.warn("Automower Action service ThingHandler is null!");
109         } else {
110             automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK, durationMin);
111         }
112     }
113
114     public static void park(ThingActions actions, int durationMin) {
115         ((AutomowerActions) actions).park(durationMin);
116     }
117
118     @RuleAction(label = "@text/action-resumeschedule-label", description = "@text/action-resumeschedule-desc")
119     public void resumeSchedule() {
120         AutomowerHandler automowerHandler = handler;
121         if (automowerHandler == null) {
122             logger.warn("Automower Action service ThingHandler is null!");
123         } else {
124             automowerHandler.sendAutomowerCommand(AutomowerCommand.RESUME_SCHEDULE);
125         }
126     }
127
128     public static void resumeSchedule(ThingActions actions) {
129         ((AutomowerActions) actions).resumeSchedule();
130     }
131 }