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.
52 void enterManualMode() throws CommunicationApiException, UnauthorizedApiException;
55 * Disables the manual mode, if it is enabled.
59 void leaveManualMode() throws CommunicationApiException, UnauthorizedApiException;
62 * Starts a station on the OpenSprinkler device for the specified duration.
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.
68 void openStation(int station, BigDecimal duration) throws CommunicationApiException, GeneralApiException;
71 * Closes a station on the OpenSprinkler device.
73 * @param station Index of the station to open starting at 0.
76 void closeStation(int station) throws CommunicationApiException, GeneralApiException;
79 * Returns the state of a station on the OpenSprinkler device.
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.
85 boolean isStationOpen(int station) throws CommunicationApiException, GeneralApiException;
88 * Returns the current program data of the requested station.
90 * @param station Index of the station to request data from
91 * @return StationProgram
94 StationProgram retrieveProgram(int station) throws CommunicationApiException;
97 * Returns the state of rain detection on the OpenSprinkler device.
99 * @return True if rain is detected, false if not or cannot determine.
102 boolean isRainDetected();
105 * Returns the current draw of all connected zones of the OpenSprinkler device in milliamperes.
107 * @return current draw in milliamperes or -1 if sensor not supported
112 * Returns the state of the second sensor.
114 * @return 1: sensor is active; 0: sensor is inactive; -1: no sensor.
116 int getSensor2State();
120 * @return The Wifi signal strength in -dB or 0 if not supported by firmware
122 int signalStrength();
126 * @return The pulses that the flow sensor has given in the last time period, -1 if not supported.
128 int flowSensorCount();
131 * CLOSES all stations turning them all off.
134 void resetStations() throws UnauthorizedApiException, CommunicationApiException;
137 * Returns true if the internal programs are allowed to auto start.
139 * @return true if enabled
141 boolean getIsEnabled();
143 void enablePrograms(Command command) throws UnauthorizedApiException, CommunicationApiException;
146 * Returns the water level in %.
148 * @return waterLevel in %
153 * Returns the number of total stations that are controllable from the OpenSprinkler
156 * @return Number of stations as an int.
158 int getNumberOfStations();
161 * Returns the firmware version number.
163 * @return The firmware version of the OpenSprinkler device as an int.
166 int getFirmwareVersion() throws CommunicationApiException, UnauthorizedApiException;
169 * Sends all the GET requests and stores/cache the responses for use by the API to prevent the need for multiple
172 * @throws CommunicationApiException
173 * @throws UnauthorizedApiException
175 void refresh() throws CommunicationApiException, UnauthorizedApiException;
178 * Ask the OpenSprinkler for the program names and store these for future use in a List.
180 * @throws CommunicationApiException
181 * @throws UnauthorizedApiException
183 void getProgramData() throws CommunicationApiException, UnauthorizedApiException;
186 * Returns a list of all internal programs as a list of StateOptions.
188 * @return List<StateOption>
190 List<StateOption> getPrograms();
193 * Return a list of all the stations the device has as List of StateOptions
195 * @return List<StateOption>
197 List<StateOption> getStations();
200 * Runs a Program that is setup and stored inside the OpenSprinkler
202 * @param Program index number that you wish to run.
204 * @throws CommunicationApiException
205 * @throws UnauthorizedApiException
207 void runProgram(Command command) throws CommunicationApiException, UnauthorizedApiException;
210 * Fetch the station names and place them in a list of List<StateOption>.
211 * Use getStations() to retrieve this list.
213 * @throws CommunicationApiException
214 * @throws UnauthorizedApiException
216 JnResponse getStationNames() throws CommunicationApiException, UnauthorizedApiException;
219 * Tells a single station to ignore the rain delay.
223 * @throws CommunicationApiException
224 * @throws UnauthorizedApiException
226 void ignoreRain(int station, boolean command) throws CommunicationApiException, UnauthorizedApiException;
229 * Asks if a single station is set to ignore rain delays.
234 boolean isIgnoringRain(int station);
237 * Sets how long the OpenSprinkler device will stop running programs for.
240 * @throws UnauthorizedApiException
241 * @throws CommunicationApiException
243 void setRainDelay(int hours) throws UnauthorizedApiException, CommunicationApiException;
246 * Gets the rain delay in hours from the OpenSprinkler device.
248 * @return QuantityType<Time>
250 QuantityType<Time> getRainDelay();