2 * Copyright (c) 2010-2023 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.opensprinkler.internal.api;
15 import java.math.BigDecimal;
16 import java.util.List;
18 import javax.measure.quantity.Time;
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;
31 * The {@link OpenSprinklerApi} interface defines the functions which are
32 * controllable on the OpenSprinkler API interface.
34 * @author Chris Graham - Initial contribution
35 * @author Florian Schmidt - Refactoring
38 public interface OpenSprinklerApi {
41 * Whether the device entered manual mode and accepts API requests to control the stations.
43 * @return True if this API interface is connected to the Open Sprinkler API. False otherwise.
45 boolean isManualModeEnabled();
48 * Enters the "manual" mode of the device so that API requests are accepted.
50 * @throws CommunicationApiException
51 * @throws UnauthorizedApiException
53 void enterManualMode() throws CommunicationApiException, UnauthorizedApiException;
56 * Disables the manual mode, if it is enabled.
58 * @throws CommunicationApiException
59 * @throws UnauthorizedApiException
61 void leaveManualMode() throws CommunicationApiException, UnauthorizedApiException;
64 * Starts a station on the OpenSprinkler device for the specified duration.
66 * @param station Index of the station to open starting at 0.
67 * @param duration The duration in seconds for how long the station should be turned on.
68 * @throws CommunicationApiException
69 * @throws GeneralApiException
71 void openStation(int station, BigDecimal duration) throws CommunicationApiException, GeneralApiException;
74 * Closes a station on the OpenSprinkler device.
76 * @param station Index of the station to open starting at 0.
77 * @throws CommunicationApiException
78 * @throws GeneralApiException
80 void closeStation(int station) throws CommunicationApiException, GeneralApiException;
83 * Returns the state of a station on the OpenSprinkler device.
85 * @param station Index of the station to open starting at 0.
86 * @return True if the station is open, false if it is closed or cannot determine.
87 * @throws CommunicationApiException
88 * @throws GeneralApiException
90 boolean isStationOpen(int station) throws CommunicationApiException, GeneralApiException;
93 * Returns the current program data of the requested station.
95 * @param station Index of the station to request data from
96 * @return StationProgram
97 * @throws CommunicationApiException
99 StationProgram retrieveProgram(int station) throws CommunicationApiException;
102 * Returns the state of rain detection on the OpenSprinkler device.
104 * @return True if rain is detected, false if not or cannot determine.
106 boolean isRainDetected();
109 * Returns the current draw of all connected zones of the OpenSprinkler device in milliamperes.
111 * @return current draw in milliamperes or -1 if sensor not supported
116 * Returns the state of the second sensor.
118 * @return 1: sensor is active; 0: sensor is inactive; -1: no sensor.
120 int getSensor2State();
124 * @return The Wifi signal strength in -dB or 0 if not supported by firmware
126 int signalStrength();
130 * @return The pulses that the flow sensor has given in the last time period, -1 if not supported.
132 int flowSensorCount();
135 * CLOSES all stations turning them all off.
138 void resetStations() throws UnauthorizedApiException, CommunicationApiException;
141 * Returns true if the internal programs are allowed to auto start.
143 * @return true if enabled
145 boolean getIsEnabled();
147 void enablePrograms(Command command) throws UnauthorizedApiException, CommunicationApiException;
150 * Returns the water level in %.
152 * @return waterLevel in %
157 * Returns the number of total stations that are controllable from the OpenSprinkler
160 * @return Number of stations as an int.
162 int getNumberOfStations();
165 * Returns the firmware version number.
167 * @return The firmware version of the OpenSprinkler device as an int.
168 * @throws CommunicationApiException
169 * @throws UnauthorizedApiException
171 int getFirmwareVersion() throws CommunicationApiException, UnauthorizedApiException;
174 * Sends all the GET requests and stores/cache the responses for use by the API to prevent the need for multiple
177 * @throws CommunicationApiException
178 * @throws UnauthorizedApiException
180 void refresh() throws CommunicationApiException, UnauthorizedApiException;
183 * Ask the OpenSprinkler for the program names and store these for future use in a List.
185 * @throws CommunicationApiException
186 * @throws UnauthorizedApiException
188 void getProgramData() throws CommunicationApiException, UnauthorizedApiException;
191 * Returns a list of all internal programs as a list of StateOptions.
193 * @return {@code List<StateOption>}
195 List<StateOption> getPrograms();
198 * Return a list of all the stations the device has as List of StateOptions
200 * @return {@code List<StateOption>}
202 List<StateOption> getStations();
205 * Runs a Program that is setup and stored inside the OpenSprinkler
207 * @param command Program index number that you wish to run.
209 * @throws CommunicationApiException
210 * @throws UnauthorizedApiException
212 void runProgram(Command command) throws CommunicationApiException, UnauthorizedApiException;
215 * Fetch the station names and place them in a list of {@code List<StateOption>}.
216 * Use getStations() to retrieve this list.
218 * @throws CommunicationApiException
219 * @throws UnauthorizedApiException
221 JnResponse getStationNames() throws CommunicationApiException, UnauthorizedApiException;
224 * Tells a single station to ignore the rain delay.
228 * @throws CommunicationApiException
229 * @throws UnauthorizedApiException
231 void ignoreRain(int station, boolean command) throws CommunicationApiException, UnauthorizedApiException;
234 * Asks if a single station is set to ignore rain delays.
239 boolean isIgnoringRain(int station);
242 * Sets how long the OpenSprinkler device will stop running programs for.
245 * @throws UnauthorizedApiException
246 * @throws CommunicationApiException
248 void setRainDelay(int hours) throws UnauthorizedApiException, CommunicationApiException;
251 * Gets the rain delay in hours from the OpenSprinkler device.
253 * @return {@code QuantityType<Time>}
255 QuantityType<Time> getRainDelay();