-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[opensprinkler] Fix Program names and add new features for firmware 2.2.0 #15410
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1a9f531
Fix Program names are not parsed correctly in firmware 2.2.0
Skinah ea72123
Add new features.
Skinah 68b5732
spotless fixes
Skinah 2f8e17d
add dependancy
Skinah f5044e3
update i18n translations
Skinah 9b54626
remove dependancy.
Skinah c328245
remove dep from features.
Skinah 5cf82ed
Change channels to DecimalType and Number.
Skinah cbf20e5
tidy up channel commands
Skinah ea47a41
Add suggest param
Skinah 68d20cc
remove unused vars
Skinah 1d2e0f4
Fix suggestions.
Skinah 7d9901a
upgrade inst added.
Skinah f59d057
remove version.
Skinah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...rc/main/java/org/openhab/binding/opensprinkler/internal/api/OpenSprinklerHttpApiV220.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* 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); | ||
Skinah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void setPausePrograms(int seconds) throws UnauthorizedApiException, CommunicationApiException { | ||
http.sendHttpGet(getBaseUrl() + "pq", getRequestRequiredOptions() + "&dur=" + seconds); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am asking myself if a channel is really the good option.
The connection status should probably be something defining the thing status ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlaur : WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I need some more context. The binding is declared as
local
, so if I understand this correctly, this is just some information from the device whether it is also integrated with a cloud service in addition to being integrated through the local API?In that case, what would be the use of this channel? Perhaps it would be sufficient to provide this as a property? And also, in that case it probably shouldn't impact the thing status, since it wouldn't interfere with the openHAB integration in any way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe a property is wrong as it has a state that changes. Read only channel seemed to fit. Your thoughts are correct and I also do not see the use case, but was easy to add it when doing other channels instead of someone requesting it later. It could possibly be used to fault find why you can not use their cloud to connect and control the sprinkler. The binding is full local and it is perhaps strange that the device can do both without trying to force you to do one over the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to delete the channel then to spend any more time on changing or adding extra lines to add it to things that are missing the channel. I don't have a lot of spare time these days.