]> git.basschouten.com Git - openhab-addons.git/commitdiff
Pushing PR #14123 to OH4 (#14140)
authorGaël L'hopital <gael@lhopital.org>
Mon, 2 Jan 2023 18:06:24 +0000 (19:06 +0100)
committerGitHub <noreply@github.com>
Mon, 2 Jan 2023 18:06:24 +0000 (19:06 +0100)
Signed-off-by: clinique <gael@lhopital.org>
bundles/org.openhab.binding.netatmo/README.md
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/config/ApiHandlerConfiguration.java
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/servlet/WebhookServlet.java
bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/config/config.xml
bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties

index 2b52dbd637b95cbc0a9beb6df0305138142e4116..7ec8be86b0c6b715ab55b0ceecfc403bf6433101 100644 (file)
@@ -47,6 +47,7 @@ The Account bridge has the following configuration elements:
 | clientId          | String | Yes      | Client ID provided for the application you created on <http://dev.netatmo.com/createapp>                               |
 | clientSecret      | String | Yes      | Client Secret provided for the application you created                                                                 |
 | webHookUrl        | String | No       | Protocol, public IP and port to access openHAB server from Internet                                                    |
+| webHookPostfix    | String | No       | String appended to the generated webhook address (should start with "/")                                               |
 | reconnectInterval | Number | No       | The reconnection interval to Netatmo API (in s)                                                                        |
 | refreshToken      | String | Yes*     | The refresh token provided by Netatmo API after the granting process. Can be saved in case of file based configuration |
 
@@ -100,14 +101,14 @@ Netatmo servers can send push notifications to the Netatmo Binding by using a ca
 The webhook URL is setup at Netatmo Account level using "Webhook Address" parameter.
 You will define here public way to access your openHAB server:
 
-```text
+```
 http(s)://xx.yy.zz.ww:443
 ```
 
 Your Netatmo App will be configured automatically by the bridge to the endpoint:
 
-```text
-http(s)://xx.yy.zz.ww:443/netatmo/webhook/<_CLIENT_ID_>
+```
+http(s)://xx.yy.zz.ww:443/netatmo/webhook/<_CLIENT_ID_><webHookPostfix>
 ```
 
 Please be aware of Netatmo own limits regarding webhook usage that lead to a 24h ban-time when webhook does not answer 5 times.
index b7a02105d5109f1cba258298c2859a3477949d70..fbafb472998176328cc3caac5964ab1a2262aef0 100644 (file)
@@ -29,6 +29,7 @@ public class ApiHandlerConfiguration {
     public String clientSecret = "";
     public String refreshToken = "";
     public String webHookUrl = "";
+    public String webHookPostfix = "";
     public int reconnectInterval = 300;
 
     public ConfigurationLevel check() {
index 38531f488e446eee75b4bf73a32cdaea75dcc725..eed7c979e605159eba8da03407db9d6c43f93290 100644 (file)
@@ -160,7 +160,7 @@ public class ApiBridgeHandler extends BaseBridgeHandler {
                         SecurityApi securityApi = getRestManager(SecurityApi.class);
                         if (securityApi != null) {
                             WebhookServlet servlet = new WebhookServlet(this, httpService, deserializer, securityApi,
-                                    configuration.webHookUrl);
+                                    configuration.webHookUrl, configuration.webHookPostfix);
                             servlet.startListening();
                             this.webHookServlet = servlet;
                         }
index 5720388d9bebf865af512be6fb8b8b518020b333..542efb768605010eb27172bddf6e38b04de37085 100644 (file)
@@ -50,21 +50,23 @@ public class WebhookServlet extends NetatmoServlet {
     private final SecurityApi securityApi;
     private final NADeserializer deserializer;
     private final String webHookUrl;
+    private final String webHookPostfix;
 
     private boolean hookSet = false;
 
     public WebhookServlet(ApiBridgeHandler handler, HttpService httpService, NADeserializer deserializer,
-            SecurityApi securityApi, String webHookUrl) {
+            SecurityApi securityApi, String webHookUrl, String webHookPostfix) {
         super(handler, httpService, "webhook");
         this.deserializer = deserializer;
         this.securityApi = securityApi;
         this.webHookUrl = webHookUrl;
+        this.webHookPostfix = webHookPostfix;
     }
 
     @Override
     public void startListening() {
         super.startListening();
-        URI uri = UriBuilder.fromUri(webHookUrl).path(path).build();
+        URI uri = UriBuilder.fromUri(webHookUrl).path(path + webHookPostfix).build();
         try {
             logger.info("Setting up WebHook at Netatmo to {}", uri.toString());
             hookSet = securityApi.addwebhook(uri);
index 944d73fd016282fd774ba7c896a725e7f44231f4..274d2e91073b8659106ba2b7c9a44bcfbcd1ad59 100644 (file)
                        <description>@text/config.webHookUrl.description</description>
                </parameter>
 
+               <parameter name="webHookPostfix" type="text" required="false">
+                       <label>@text/config.webHookPostfix.label</label>
+                       <description>@text/config.webHookPostfix.description</description>
+               </parameter>
+
                <parameter name="reconnectInterval" type="integer" unit="s">
                        <label>@text/config.reconnectInterval.label</label>
                        <description>@text/config.reconnectInterval.description</description>
index 2d075ccc0a84aa5764a8336d62247f3750d5ec29..4c8f8d870b4aeabf29e9b893c797798a7d7e9d50 100644 (file)
@@ -423,6 +423,8 @@ config.clientSecret.label = Client Secret
 config.clientSecret.description = Client Secret provided for the application you created.
 config.refreshToken.label = Refresh Token
 config.refreshToken.description = Refresh token provided by the oAuth2 authentication process.
+config.webHookPostfix.label = Webhook Postfix
+config.webHookPostfix.description = String appended to the generated webhook address (should start with `/`).
 config.webHookUrl.label = Webhook Address
 config.webHookUrl.description = Protocol, public IP or hostname and port to access openHAB server from Internet.
 config.reconnectInterval.label = Reconnect Interval