forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from volkmarnissen/myenergi_binding1
[12251] [myenergi] Improved texts things.xml
- Loading branch information
Showing
12 changed files
with
238 additions
and
50 deletions.
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
85 changes: 85 additions & 0 deletions
85
...ergi/src/main/java/org/openhab/binding/myenergi/internal/MyEnergiGetHostFromDirector.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,85 @@ | ||
/** | ||
* Copyright (c) 2010-2021 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.myenergi.internal; | ||
|
||
import java.net.URL; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jetty.client.HttpClient; | ||
import org.eclipse.jetty.client.api.Authentication; | ||
import org.eclipse.jetty.client.api.ContentResponse; | ||
import org.eclipse.jetty.client.api.Request; | ||
import org.eclipse.jetty.client.util.DigestAuthentication; | ||
import org.eclipse.jetty.http.HttpField; | ||
import org.eclipse.jetty.http.HttpMethod; | ||
import org.openhab.binding.myenergi.internal.exception.ApiException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link MyEnergiGetHostFromDirector} is a helper class to get the hostname on | ||
* myenergi.net for the the myenergi API. | ||
* It finds the server for a given hub serial number | ||
* | ||
* @author Volkmar Nissen - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class MyEnergiGetHostFromDirector { | ||
private static final int SLEEP_BEFORE_REINIT_MS = 3000; | ||
public static final String MY_ENERGI_RESPONSE_FIELD = "X_MYENERGI-asn"; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(MyEnergiGetHostFromDirector.class); | ||
|
||
/** | ||
* Finds the server for a given hub serial number | ||
* | ||
* @param httpClientFactory the client to be used. | ||
* @throws ApiException | ||
*/ | ||
|
||
public String getHostName(@NotNull HttpClient httpClient, @NotNull String hubSerialNumber) throws ApiException { | ||
String directorHostname = "director.myenergi.net"; | ||
try { | ||
URL directorURL = new URL("https", directorHostname, "/"); | ||
// No password is needed at director.myenergie.net | ||
httpClient.getAuthenticationStore().addAuthentication( | ||
new DigestAuthentication(directorURL.toURI(), Authentication.ANY_REALM, hubSerialNumber, "")); | ||
int innerLoop = 0; | ||
while ((innerLoop < 2)) { | ||
innerLoop++; | ||
if (!httpClient.isStarted()) { | ||
httpClient.start(); | ||
} | ||
Request request = httpClient.newRequest(directorURL.toString()).method(HttpMethod.GET); | ||
logger.trace("sending get hostname request: {}", innerLoop); | ||
ContentResponse response = request.send(); | ||
String hostname = response.getHeaders().get(MY_ENERGI_RESPONSE_FIELD); | ||
if (null != hostname) { | ||
return hostname; | ||
} | ||
|
||
if (logger.isTraceEnabled()) { | ||
for (HttpField field : response.getHeaders()) { | ||
logger.trace("HTTP header: {}", field.toString()); | ||
} | ||
} | ||
} | ||
} catch (Exception e) { | ||
throw new ApiException("Exception caught during API execution", e); | ||
} | ||
// This code will never be executed, because the ApiException will be thrown earlier | ||
return ""; | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
bundles/org.openhab.binding.myenergi/src/main/resources/OH-INF/i18n/myenergi.properties
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# thing status description | ||
offline.conf-error-invalid-refresh-intervals = Invalid refresh intervals | ||
offline.conf-error-missing-username-or-password = Missing username or password | ||
offline.conf-error-missing-hubSerialNumber-or-password = Missing hubSerialNumber or password | ||
offline.conf-error-authentication = Authentication Error (Invalid API key or account number) | ||
offline.comm-error-general = General communication error with API |
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
Oops, something went wrong.