From a5fc9b9523bfac5a98f9a0d44468963859ca12d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Mon, 2 Jan 2023 19:06:24 +0100 Subject: [PATCH] Pushing PR #14123 to OH4 (#14140) Signed-off-by: clinique --- bundles/org.openhab.binding.netatmo/README.md | 7 ++++--- .../netatmo/internal/config/ApiHandlerConfiguration.java | 1 + .../binding/netatmo/internal/handler/ApiBridgeHandler.java | 2 +- .../binding/netatmo/internal/servlet/WebhookServlet.java | 6 ++++-- .../src/main/resources/OH-INF/config/config.xml | 5 +++++ .../src/main/resources/OH-INF/i18n/netatmo.properties | 2 ++ 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.netatmo/README.md b/bundles/org.openhab.binding.netatmo/README.md index 2b52dbd637b95..7ec8be86b0c6b 100644 --- a/bundles/org.openhab.binding.netatmo/README.md +++ b/bundles/org.openhab.binding.netatmo/README.md @@ -47,6 +47,7 @@ The Account bridge has the following configuration elements: | clientId | String | Yes | Client ID provided for the application you created on | | 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_> ``` Please be aware of Netatmo own limits regarding webhook usage that lead to a 24h ban-time when webhook does not answer 5 times. diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/config/ApiHandlerConfiguration.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/config/ApiHandlerConfiguration.java index b7a02105d5109..fbafb47299817 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/config/ApiHandlerConfiguration.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/config/ApiHandlerConfiguration.java @@ -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() { diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java index 38531f488e446..eed7c979e6051 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java @@ -160,7 +160,7 @@ public void openConnection(@Nullable String code, @Nullable String redirectUri) 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; } diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/servlet/WebhookServlet.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/servlet/WebhookServlet.java index 5720388d9bebf..542efb7686050 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/servlet/WebhookServlet.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/servlet/WebhookServlet.java @@ -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); diff --git a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/config/config.xml index 944d73fd01628..274d2e91073b8 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/config/config.xml @@ -29,6 +29,11 @@ @text/config.webHookUrl.description + + + @text/config.webHookPostfix.description + + @text/config.reconnectInterval.description diff --git a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties index 2d075ccc0a84a..4c8f8d870b4ae 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties +++ b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties @@ -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