]> git.basschouten.com Git - openhab-addons.git/blob
4f2a3d7c0bddf6c71fe517997724991d7b2af368
[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.robonect.internal.model.cmd;
14
15 import org.openhab.binding.robonect.internal.RobonectClient;
16
17 /**
18  * 
19  * The mode commands sets the mower into the corresponding mode. In addition to the mowers standard modes
20  * (HOME, MAN, AUTO) the module supports following modes:
21  * 
22  * EOD (End Of Day): The mower is set into HOME mode until midnight. After midnight the module sets the mower in AUTO
23  * mode
24  * JOB: The JOB mode triggers a JOB and supports following additional parameter:
25  * * remoteStart: where to start the job (STANDARD, REMOTE_1 or REMOTE_2)
26  * * after: The mode to be set after the JOB is done. Allowed are all except JOB.
27  * * start: the start time in the form HH:MM (H=Hour,M=Minute)
28  * * end: the end time in the form HH:MM (H=Hour,M=Minute)
29  * * duration: mowing time in minutes (in combination with start or end time)
30  * 
31  * @author Marco Meyer - Initial contribution
32  */
33 public class ModeCommand implements Command {
34
35     /**
36      * The available modes. See class documentation for the meanings.
37      */
38     public enum Mode {
39         HOME(1, "home"),
40         EOD(2, "eod"),
41         MANUAL(3, "man"),
42         AUTO(4, "auto"),
43         JOB(5, "job");
44
45         int code;
46         String cmd;
47
48         Mode(int code, String cmd) {
49             this.code = code;
50             this.cmd = cmd;
51         }
52     }
53
54     /**
55      * The available remoteStart values.
56      */
57     public enum RemoteStart {
58
59         /**
60          * Start immediatly at the docking station.
61          */
62         STANDARD(0),
63
64         /**
65          * Start at the configured remote 1 location.
66          */
67         REMOTE_1(1),
68
69         /**
70          * Start at the conifugred remote 2 location.
71          */
72         REMOTE_2(2);
73
74         int code;
75
76         RemoteStart(int code) {
77             this.code = code;
78         }
79     }
80
81     private Mode mode;
82
83     private RemoteStart remoteStart;
84
85     private Mode after;
86
87     private String start;
88
89     private String end;
90
91     private Integer duration;
92
93     public ModeCommand(Mode mode) {
94         this.mode = mode;
95     }
96
97     /**
98      * sets the desired remoteStart option.
99      * 
100      * @param remoteStart - the remoteStart option.
101      * @return - the command instance.
102      */
103     public ModeCommand withRemoteStart(RemoteStart remoteStart) {
104         this.remoteStart = remoteStart;
105         return this;
106     }
107
108     /**
109      * set the mode after the job is done.
110      * 
111      * @param afterMode - the desired mode after job execution.
112      * @return - the command instance.
113      */
114     public ModeCommand withAfter(Mode afterMode) {
115         this.after = afterMode;
116         return this;
117     }
118
119     /**
120      * The desired start time in the format HH:MM (H=Hour, M=Minute)
121      * 
122      * @param startTime - the start time.
123      * @return - the command instance.
124      */
125     public ModeCommand withStart(String startTime) {
126         this.start = startTime;
127         return this;
128     }
129
130     /**
131      * The desired end time in the format HH:MM (H=Hour, M=Minute)
132      * 
133      * @param endTime - the end time.
134      * @return - the command instance.
135      */
136     public ModeCommand withEnd(String endTime) {
137         this.end = endTime;
138         return this;
139     }
140
141     /**
142      * Sets the duration in minutes.
143      * 
144      * @param durationInMinutes - the duration in minutes.
145      * @return - the command instance.
146      */
147     public ModeCommand withDuration(Integer durationInMinutes) {
148         this.duration = durationInMinutes;
149         return this;
150     }
151
152     /**
153      * {@inheritDoc}
154      * 
155      * @param baseURL - will be passed by the {@link RobonectClient} in the form
156      *            http://xxx.xxx.xxx/json?
157      * @return
158      */
159     @Override
160     public String toCommandURL(String baseURL) {
161         StringBuilder sb = new StringBuilder(baseURL);
162         sb.append("?cmd=mode&mode=");
163         sb.append(mode.cmd);
164         switch (mode) {
165             case EOD:
166             case MANUAL:
167             case AUTO:
168             case HOME:
169                 break;
170             case JOB:
171                 if (remoteStart != null) {
172                     sb.append("&remotestart=");
173                     sb.append(remoteStart.code);
174                 }
175                 if (after != null) {
176                     sb.append("&after=");
177                     sb.append(after.code);
178                 }
179                 if (start != null) {
180                     sb.append("&start=");
181                     sb.append(start);
182                 }
183                 if (end != null) {
184                     sb.append("&end=");
185                     sb.append(end);
186                 }
187                 if (duration != null) {
188                     sb.append("&duration=");
189                     sb.append(duration);
190                 }
191                 break;
192         }
193         return sb.toString();
194     }
195 }