]> git.basschouten.com Git - openhab-addons.git/blob
eace11a85124da23eecd4471ee271147f9a42cfd
[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.opensprinkler.internal.api;
14
15 import java.math.BigDecimal;
16 import java.util.List;
17
18 import javax.measure.quantity.Time;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.opensprinkler.internal.OpenSprinklerState.JnResponse;
22 import org.openhab.binding.opensprinkler.internal.api.exception.CommunicationApiException;
23 import org.openhab.binding.opensprinkler.internal.api.exception.GeneralApiException;
24 import org.openhab.binding.opensprinkler.internal.api.exception.UnauthorizedApiException;
25 import org.openhab.binding.opensprinkler.internal.model.StationProgram;
26 import org.openhab.core.library.types.QuantityType;
27 import org.openhab.core.types.Command;
28 import org.openhab.core.types.StateOption;
29
30 /**
31  * The {@link OpenSprinklerApi} interface defines the functions which are
32  * controllable on the OpenSprinkler API interface.
33  *
34  * @author Chris Graham - Initial contribution
35  * @author Florian Schmidt - Refactoring
36  */
37 @NonNullByDefault
38 public interface OpenSprinklerApi {
39
40     /**
41      * Whether the device entered manual mode and accepts API requests to control the stations.
42      *
43      * @return True if this API interface is connected to the Open Sprinkler API. False otherwise.
44      */
45     boolean isManualModeEnabled();
46
47     /**
48      * Enters the "manual" mode of the device so that API requests are accepted.
49      *
50      * @throws Exception
51      */
52     void enterManualMode() throws CommunicationApiException, UnauthorizedApiException;
53
54     /**
55      * Disables the manual mode, if it is enabled.
56      *
57      * @throws Exception
58      */
59     void leaveManualMode() throws CommunicationApiException, UnauthorizedApiException;
60
61     /**
62      * Starts a station on the OpenSprinkler device for the specified duration.
63      *
64      * @param station Index of the station to open starting at 0.
65      * @param duration The duration in seconds for how long the station should be turned on.
66      * @throws Exception
67      */
68     void openStation(int station, BigDecimal duration) throws CommunicationApiException, GeneralApiException;
69
70     /**
71      * Closes a station on the OpenSprinkler device.
72      *
73      * @param station Index of the station to open starting at 0.
74      * @throws Exception
75      */
76     void closeStation(int station) throws CommunicationApiException, GeneralApiException;
77
78     /**
79      * Returns the state of a station on the OpenSprinkler device.
80      *
81      * @param station Index of the station to open starting at 0.
82      * @return True if the station is open, false if it is closed or cannot determine.
83      * @throws Exception
84      */
85     boolean isStationOpen(int station) throws CommunicationApiException, GeneralApiException;
86
87     /**
88      * Returns the current program data of the requested station.
89      *
90      * @param station Index of the station to request data from
91      * @return StationProgram
92      * @throws Exception
93      */
94     StationProgram retrieveProgram(int station) throws CommunicationApiException;
95
96     /**
97      * Returns the state of rain detection on the OpenSprinkler device.
98      *
99      * @return True if rain is detected, false if not or cannot determine.
100      * @throws Exception
101      */
102     boolean isRainDetected();
103
104     /**
105      * Returns the current draw of all connected zones of the OpenSprinkler device in milliamperes.
106      *
107      * @return current draw in milliamperes or -1 if sensor not supported
108      */
109     int currentDraw();
110
111     /**
112      * Returns the state of the second sensor.
113      *
114      * @return 1: sensor is active; 0: sensor is inactive; -1: no sensor.
115      */
116     int getSensor2State();
117
118     /**
119      *
120      * @return The Wifi signal strength in -dB or 0 if not supported by firmware
121      */
122     int signalStrength();
123
124     /**
125      *
126      * @return The pulses that the flow sensor has given in the last time period, -1 if not supported.
127      */
128     int flowSensorCount();
129
130     /**
131      * CLOSES all stations turning them all off.
132      *
133      */
134     void resetStations() throws UnauthorizedApiException, CommunicationApiException;
135
136     /**
137      * Returns true if the internal programs are allowed to auto start.
138      *
139      * @return true if enabled
140      */
141     boolean getIsEnabled();
142
143     void enablePrograms(Command command) throws UnauthorizedApiException, CommunicationApiException;
144
145     /**
146      * Returns the water level in %.
147      *
148      * @return waterLevel in %
149      */
150     int waterLevel();
151
152     /**
153      * Returns the number of total stations that are controllable from the OpenSprinkler
154      * device.
155      *
156      * @return Number of stations as an int.
157      */
158     int getNumberOfStations();
159
160     /**
161      * Returns the firmware version number.
162      *
163      * @return The firmware version of the OpenSprinkler device as an int.
164      * @throws Exception
165      */
166     int getFirmwareVersion() throws CommunicationApiException, UnauthorizedApiException;
167
168     /**
169      * Sends all the GET requests and stores/cache the responses for use by the API to prevent the need for multiple
170      * requests.
171      *
172      * @throws CommunicationApiException
173      * @throws UnauthorizedApiException
174      */
175     void refresh() throws CommunicationApiException, UnauthorizedApiException;
176
177     /**
178      * Ask the OpenSprinkler for the program names and store these for future use in a List.
179      *
180      * @throws CommunicationApiException
181      * @throws UnauthorizedApiException
182      */
183     void getProgramData() throws CommunicationApiException, UnauthorizedApiException;
184
185     /**
186      * Returns a list of all internal programs as a list of StateOptions.
187      *
188      * @return List<StateOption>
189      */
190     List<StateOption> getPrograms();
191
192     /**
193      * Return a list of all the stations the device has as List of StateOptions
194      *
195      * @return List<StateOption>
196      */
197     List<StateOption> getStations();
198
199     /**
200      * Runs a Program that is setup and stored inside the OpenSprinkler
201      *
202      * @param Program index number that you wish to run.
203      *
204      * @throws CommunicationApiException
205      * @throws UnauthorizedApiException
206      */
207     void runProgram(Command command) throws CommunicationApiException, UnauthorizedApiException;
208
209     /**
210      * Fetch the station names and place them in a list of List<StateOption>.
211      * Use getStations() to retrieve this list.
212      *
213      * @throws CommunicationApiException
214      * @throws UnauthorizedApiException
215      */
216     JnResponse getStationNames() throws CommunicationApiException, UnauthorizedApiException;
217
218     /**
219      * Tells a single station to ignore the rain delay.
220      *
221      * @param station
222      * @param command
223      * @throws CommunicationApiException
224      * @throws UnauthorizedApiException
225      */
226     void ignoreRain(int station, boolean command) throws CommunicationApiException, UnauthorizedApiException;
227
228     /**
229      * Asks if a single station is set to ignore rain delays.
230      *
231      * @param station
232      * @return
233      */
234     boolean isIgnoringRain(int station);
235
236     /**
237      * Sets how long the OpenSprinkler device will stop running programs for.
238      *
239      * @param hours
240      * @throws UnauthorizedApiException
241      * @throws CommunicationApiException
242      */
243     void setRainDelay(int hours) throws UnauthorizedApiException, CommunicationApiException;
244
245     /**
246      * Gets the rain delay in hours from the OpenSprinkler device.
247      *
248      * @return QuantityType<Time>
249      */
250     QuantityType<Time> getRainDelay();
251 }