From 1a9f5317e7bc98c3f9f4cbd75f226ab0d327dcc7 Mon Sep 17 00:00:00 2001 From: Matthew Skinner Date: Sat, 12 Aug 2023 17:46:46 +1000 Subject: [PATCH 01/14] Fix Program names are not parsed correctly in firmware 2.2.0 Signed-off-by: Matthew Skinner --- .../internal/api/OpenSprinklerApiFactory.java | 4 +- .../api/OpenSprinklerHttpApiV219.java | 2 +- .../api/OpenSprinklerHttpApiV220.java | 67 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerHttpApiV220.java diff --git a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerApiFactory.java b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerApiFactory.java index 4e6bad47d53a9..42fd39cde31da 100644 --- a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerApiFactory.java +++ b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerApiFactory.java @@ -70,8 +70,10 @@ public OpenSprinklerApi getHttpApi(OpenSprinklerHttpInterfaceConfig config) return new OpenSprinklerHttpApiV213(this.httpClient, config); } else if (version >= 217 && version < 219) { return new OpenSprinklerHttpApiV217(this.httpClient, config); - } else if (version >= 219) { + } else if (version >= 219 && version < 220) { return new OpenSprinklerHttpApiV219(this.httpClient, config); + } else if (version >= 220) { + return new OpenSprinklerHttpApiV220(this.httpClient, config); } else { /* Need to make sure we have an older OpenSprinkler device by checking the first station. */ try { diff --git a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerHttpApiV219.java b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerHttpApiV219.java index 23f1ae7f997c8..b2a9e2821c377 100644 --- a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerHttpApiV219.java +++ b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerHttpApiV219.java @@ -21,7 +21,7 @@ /** * The {@link OpenSprinklerHttpApiV219} class is used for communicating with - * the firmware versions 2.1.9 and up. + * the firmware versions 2.1.9 * * @author Matthew Skinner - Initial contribution */ diff --git a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerHttpApiV220.java b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerHttpApiV220.java new file mode 100644 index 0000000000000..4f2fe5c80bc6c --- /dev/null +++ b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerHttpApiV220.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.opensprinkler.internal.api; + +import static org.openhab.binding.opensprinkler.internal.OpenSprinklerBindingConstants.CMD_PROGRAM_DATA; + +import java.util.ArrayList; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jetty.client.HttpClient; +import org.openhab.binding.opensprinkler.internal.OpenSprinklerState.JpResponse; +import org.openhab.binding.opensprinkler.internal.api.exception.CommunicationApiException; +import org.openhab.binding.opensprinkler.internal.api.exception.GeneralApiException; +import org.openhab.binding.opensprinkler.internal.api.exception.UnauthorizedApiException; +import org.openhab.binding.opensprinkler.internal.config.OpenSprinklerHttpInterfaceConfig; +import org.openhab.core.types.StateOption; + +/** + * The {@link OpenSprinklerHttpApiV220} class is used for communicating with + * the firmware versions 2.2.0 and up. + * + * @author Matthew Skinner - Initial contribution + */ +@NonNullByDefault +public class OpenSprinklerHttpApiV220 extends OpenSprinklerHttpApiV219 { + + OpenSprinklerHttpApiV220(HttpClient httpClient, OpenSprinklerHttpInterfaceConfig config) + throws GeneralApiException, CommunicationApiException { + super(httpClient, config); + } + + @Override + public void getProgramData() throws CommunicationApiException, UnauthorizedApiException { + String returnContent; + try { + returnContent = http.sendHttpGet(getBaseUrl() + CMD_PROGRAM_DATA, getRequestRequiredOptions()); + } catch (CommunicationApiException exp) { + throw new CommunicationApiException( + "There was a problem in the HTTP communication with the OpenSprinkler API: " + exp.getMessage()); + } + JpResponse resp = gson.fromJson(returnContent, JpResponse.class); + if (resp != null && resp.pd.length > 0) { + state.programs = new ArrayList<>(); + int counter = 0; + for (Object x : resp.pd) { + String temp = x.toString(); + logger.trace("Program Data:{}", temp); + int end = temp.lastIndexOf('[') - 2; + int start = temp.lastIndexOf((','), end - 1) + 2; + if (start > -1 && end > -1) { + temp = temp.substring(start, end); + state.programs.add(new StateOption(Integer.toString(counter++), temp)); + } + } + } + } +} From ea72123a955f43957d9bc2aeb8cdb6e35e852e6f Mon Sep 17 00:00:00 2001 From: Matthew Skinner Date: Tue, 22 Aug 2023 21:17:03 +1000 Subject: [PATCH 02/14] Add new features. Signed-off-by: Matthew Skinner --- .../README.md | 23 ++++++----- .../OpenSprinklerBindingConstants.java | 3 ++ .../internal/OpenSprinklerState.java | 5 +++ .../internal/api/OpenSprinklerApi.java | 30 ++++++++++++++ .../api/OpenSprinklerHttpApiV100.java | 19 +++++++++ .../api/OpenSprinklerHttpApiV220.java | 5 +++ .../handler/OpenSprinklerDeviceHandler.java | 39 ++++++++++++++++++ .../resources/OH-INF/thing/thing-types.xml | 40 ++++++++++++++++++- 8 files changed, 153 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.opensprinkler/README.md b/bundles/org.openhab.binding.opensprinkler/README.md index d8502898916ed..53b8fc18d952a 100644 --- a/bundles/org.openhab.binding.opensprinkler/README.md +++ b/bundles/org.openhab.binding.opensprinkler/README.md @@ -61,22 +61,25 @@ NOTE: Some channels will only show up if the hardware has the required sensor an | Channel Type ID | Item Type | | Description | |-----------------|------------------------|----|------------------------------------------------------------------------------------| -| rainsensor | Switch | RO | This channel indicates whether rain is detected by the device or not. | -| sensor2 | Switch | RO | This channel is for the second sensor (if your hardware supports it). | +| cloudConnected | Switch | RO | If the device is fully connected to the OpenSprinkler cloud this will show as 'ON'.| | currentDraw | Number:ElectricCurrent | RO | Shows the current draw of the device. | -| waterlevel | Number:Dimensionless | RO | This channel shows the current water level in percent (0-250%). The water level is | -| | | | calculated based on the weather and influences the duration of the water programs. | -| signalStrength | Number | RO | Shows how strong the WiFi Signal is. | +| enablePrograms | Switch | RW | Allow programs to auto run. When OFF, manually started stations will still work. | | flowSensorCount | Number:Dimensionless | RO | Shows the number of pulses the optional water flow sensor has reported. | +| nextDuration | Number:Time | RW | The time the station will open for when any stations are selected from the | +| | | | `stations` channel. Defaults to 30 minutes if not set. | +| pausePrograms | Number:Time | RW | Sets/Shows the amount of time that programs will be paused for. | | programs | String | RW | Displays a list of the programs that are setup in your OpenSprinkler and when | | | | | selected will start that program for you. | +| rainDelay | Number:Time | RW | Sets/Shows the amount of time (hours) that rain has caused programs to be delayed. | +| rainsensor | Switch | RO | This channel indicates whether rain is detected by the device or not. | +| resetStations | Switch | RW | The ON command will stop all stations immediately, including those waiting to run. | +| sensor2 | Switch | RO | This channel is for the second sensor (if your hardware supports it). | +| signalStrength | Number | RO | Shows how strong the WiFi Signal is. | | stations | String | RW | Display a list of stations that can be run when selected to the length of time set | | | | | in the `nextDuration` channel. | -| nextDuration | Number:Time | RW | The time the station will open for when any stations are selected from the | -| | | | `stations` channel. Defaults to 30 minutes if not set. | -| resetStations | Switch | RW | The ON command will stop all stations immediately, including those waiting to run. | -| enablePrograms | Switch | RW | Allow programs to auto run. When OFF, manually started stations will still work. | -| rainDelay | Number:Time | RW | Sets/Shows the amount of time (hours) that rain has caused programs to be delayed. | +| waterlevel | Number:Dimensionless | RO | This channel shows the current water level in percent (0-250%). The water level is | +| | | | calculated based on the weather and influences the duration of the water programs. | +| queuedZones | Number:Dimensionless | RO | A count of how many zones are running and also waiting to run in the queue. | ## Textual Example diff --git a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/OpenSprinklerBindingConstants.java b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/OpenSprinklerBindingConstants.java index c698e4ec21887..d16fab814533e 100644 --- a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/OpenSprinklerBindingConstants.java +++ b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/OpenSprinklerBindingConstants.java @@ -82,4 +82,7 @@ public class OpenSprinklerBindingConstants { public static final String NEXT_DURATION = "nextDuration"; public static final String CHANNEL_IGNORE_RAIN = "ignoreRain"; public static final String CHANNEL_RAIN_DELAY = "rainDelay"; + public static final String CHANNEL_QUEUED_ZONES = "queuedZones"; + public static final String CHANNEL_CLOUD_CONNECTED = "cloudConnected"; + public static final String CHANNEL_PAUSE_PROGRAMS = "pausePrograms"; } diff --git a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/OpenSprinklerState.java b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/OpenSprinklerState.java index 7deed6cd6655c..853867f586ef3 100644 --- a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/OpenSprinklerState.java +++ b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/OpenSprinklerState.java @@ -63,6 +63,11 @@ public static class JcResponse { public int rssi = 1; public int flcrt = -1; public int curr = -1; + public int pq = -1; + public int pt = -1; + public int nq = -1; + public int otcs = -1; + public String dname = ""; } public static class JnResponse { diff --git a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerApi.java b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerApi.java index 42df1e5b687e6..d8ca8567670f1 100644 --- a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerApi.java +++ b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerApi.java @@ -253,4 +253,34 @@ public interface OpenSprinklerApi { * @return {@code QuantityType