2 * Copyright (c) 2010-2024 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.automower.internal.actions;
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;
28 * @author Markus Pfleger - Initial contribution
30 @ThingActionsScope(name = "automower")
32 public class AutomowerActions implements ThingActions {
33 private final Logger logger = LoggerFactory.getLogger(AutomowerActions.class);
34 private @Nullable AutomowerHandler handler;
37 public void setThingHandler(@Nullable ThingHandler handler) {
38 this.handler = (AutomowerHandler) handler;
42 public @Nullable AutomowerHandler getThingHandler() {
46 @RuleAction(label = "@text/action-start-label", description = "@text/action-start-desc")
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!");
53 automowerHandler.sendAutomowerCommand(AutomowerCommand.START, durationMin);
57 public static void start(ThingActions actions, int durationMin) {
58 ((AutomowerActions) actions).start(durationMin);
61 @RuleAction(label = "@text/action-pause-label", description = "@text/action-pause-desc")
63 AutomowerHandler automowerHandler = handler;
64 if (automowerHandler == null) {
65 logger.warn("Automower Action service ThingHandler is null!");
67 automowerHandler.sendAutomowerCommand(AutomowerCommand.PAUSE);
71 public static void pause(ThingActions actions) {
72 ((AutomowerActions) actions).pause();
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!");
81 automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK_UNTIL_NEXT_SCHEDULE);
85 public static void parkUntilNextSchedule(ThingActions actions) {
86 ((AutomowerActions) actions).parkUntilNextSchedule();
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!");
95 automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK_UNTIL_FURTHER_NOTICE);
99 public static void parkUntilFurtherNotice(ThingActions actions) {
100 ((AutomowerActions) actions).parkUntilFurtherNotice();
103 @RuleAction(label = "@text/action-park-label", description = "@text/action-park-desc")
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!");
110 automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK, durationMin);
114 public static void park(ThingActions actions, int durationMin) {
115 ((AutomowerActions) actions).park(durationMin);
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!");
124 automowerHandler.sendAutomowerCommand(AutomowerCommand.RESUME_SCHEDULE);
128 public static void resumeSchedule(ThingActions actions) {
129 ((AutomowerActions) actions).resumeSchedule();