2 * Copyright (c) 2010-2020 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(@Nullable ThingActions actions, int durationMin) {
58 if (actions instanceof AutomowerActions) {
59 ((AutomowerActions) actions).start(durationMin);
61 throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
65 @RuleAction(label = "@text/action-pause-label", description = "@text/action-pause-desc")
67 AutomowerHandler automowerHandler = handler;
68 if (automowerHandler == null) {
69 logger.warn("Automower Action service ThingHandler is null!");
71 automowerHandler.sendAutomowerCommand(AutomowerCommand.PAUSE);
75 public static void pause(@Nullable ThingActions actions) {
76 if (actions instanceof AutomowerActions) {
77 ((AutomowerActions) actions).pause();
79 throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
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!");
89 automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK_UNTIL_NEXT_SCHEDULE);
93 public static void parkUntilNextSchedule(@Nullable ThingActions actions) {
94 if (actions instanceof AutomowerActions) {
95 ((AutomowerActions) actions).parkUntilNextSchedule();
97 throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
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!");
107 automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK_UNTIL_FURTHER_NOTICE);
111 public static void parkUntilFurtherNotice(@Nullable ThingActions actions) {
112 if (actions instanceof AutomowerActions) {
113 ((AutomowerActions) actions).parkUntilFurtherNotice();
115 throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
119 @RuleAction(label = "@text/action-park-label", description = "@text/action-park-desc")
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!");
126 automowerHandler.sendAutomowerCommand(AutomowerCommand.PARK, durationMin);
130 public static void park(@Nullable ThingActions actions, int durationMin) {
131 if (actions instanceof AutomowerActions) {
132 ((AutomowerActions) actions).park(durationMin);
134 throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");
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!");
144 automowerHandler.sendAutomowerCommand(AutomowerCommand.RESUME_SCHEDULE);
148 public static void resumeSchedule(@Nullable ThingActions actions) {
149 if (actions instanceof AutomowerActions) {
150 ((AutomowerActions) actions).resumeSchedule();
152 throw new IllegalArgumentException("Actions is not an instance of AutomowerActions");