]> git.basschouten.com Git - openhab-addons.git/commitdiff
[pushover] Fix idle connection causing EOF exception (#17348)
authorlsiepel <leosiepel@gmail.com>
Mon, 7 Oct 2024 21:36:26 +0000 (23:36 +0200)
committerGitHub <noreply@github.com>
Mon, 7 Oct 2024 21:36:26 +0000 (23:36 +0200)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
bundles/org.openhab.binding.pushover/README.md
bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/PushoverBindingConstants.java
bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/config/PushoverAccountConfiguration.java
bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/factory/PushoverHandlerFactory.java
bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/handler/PushoverAccountHandler.java
bundles/org.openhab.binding.pushover/src/main/resources/OH-INF/config/config.xml
bundles/org.openhab.binding.pushover/src/main/resources/OH-INF/i18n/pushover.properties

index 2b7b93eb2c7e97a04e0563fd3b4c88be7841e265..228071ee3c74be3175bf953d187d5dd3eb413fdf 100644 (file)
@@ -26,6 +26,7 @@ You can reach it via [https://pushover.net/apps/clone/openHAB](https://pushover.
 | `retry`                 | integer | The retry parameter specifies how often (in seconds) the Pushover servers will send the same emergency-priority notification to the user (default: `300`). **advanced**                                                                                                                                       |
 | `expire`                | integer | The expire parameter specifies how long (in seconds) your emergency-priority notification will continue to be retried (default: `3600`). **advanced**                                                                                                                                                         |
 | `timeout`               | integer | The timeout parameter specifies maximum number of seconds a request to Pushover can take. **advanced**                                                                                                                                                                                                        |
+| `idleTimeout`           | integer | The idle-timeout parameter specifies maximum number of seconds a connection with Pushover can be idle (default: `300`). **advanced**                                                                                                                                                                          |
 
 ## Channels
 
@@ -74,7 +75,6 @@ For priority `2` only, the action returns a `String` value (the `receipt`) if th
 For other priorities, the action always returns an empty `String`.
 
 - `cancelPriorityMessage(String receipt)` - This method is used to cancel an emergency priority message.
-
 The action returns a `Boolean` value to indicate if the message was cancelled successfully or not.
 
 ## Full Example
index d041f14736fc9334be1c3882b6b366b4938841b3..342f07989e09ac152e405f4e865962a26ab1ba59 100644 (file)
@@ -23,7 +23,7 @@ import org.openhab.core.thing.ThingTypeUID;
 @NonNullByDefault
 public class PushoverBindingConstants {
 
-    private static final String BINDING_ID = "pushover";
+    public static final String BINDING_ID = "pushover";
 
     public static final ThingTypeUID PUSHOVER_ACCOUNT = new ThingTypeUID(BINDING_ID, "pushover-account");
 
index 7d9927eb43519b3dbe02f5f69303f4b4c25043c7..161940e36fabe5179a8bd8aee99e03b09929822e 100644 (file)
@@ -19,13 +19,16 @@ import java.util.Set;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jetty.client.HttpClient;
+import org.openhab.binding.pushover.internal.PushoverBindingConstants;
 import org.openhab.binding.pushover.internal.handler.PushoverAccountHandler;
 import org.openhab.core.io.net.http.HttpClientFactory;
+import org.openhab.core.io.net.http.HttpClientInitializationException;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingTypeUID;
 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
 import org.openhab.core.thing.binding.ThingHandler;
 import org.openhab.core.thing.binding.ThingHandlerFactory;
+import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
@@ -45,7 +48,23 @@ public class PushoverHandlerFactory extends BaseThingHandlerFactory {
 
     @Activate
     public PushoverHandlerFactory(final @Reference HttpClientFactory httpClientFactory) {
-        this.httpClient = httpClientFactory.getCommonHttpClient();
+        httpClient = httpClientFactory.createHttpClient(PushoverBindingConstants.BINDING_ID);
+        try {
+            httpClient.start();
+        } catch (final Exception e) {
+            throw new HttpClientInitializationException("Could not start HttpClient", e);
+        }
+    }
+
+    @Override
+    protected void deactivate(final ComponentContext componentContext) {
+        try {
+            httpClient.stop();
+        } catch (final Exception e) {
+            // Eat http client stop exception.
+        } finally {
+            super.deactivate(componentContext);
+        }
     }
 
     @Override
index c7d501bda2257808a45f89806e35a990e81219d1..a75a504031db153d857082435571049611af0f7a 100644 (file)
@@ -83,7 +83,7 @@ public class PushoverAccountHandler extends BaseThingHandler {
 
         if (configValid) {
             updateStatus(ThingStatus.UNKNOWN);
-
+            httpClient.setIdleTimeout(config.idleTimeout * 1000);
             connection = new PushoverAPIConnection(httpClient, config);
             scheduler.submit(this::asyncValidateUser);
         }
index 9f4be6e413423cb629ffac776783de094fde2357..01084a05bf67fd36aa58cd75b9077686ad85442f 100644 (file)
                                take.</description>
                        <default>10</default>
                </parameter>
+               <parameter name="idleTimeout" type="integer" min="0" max="10800" unit="s">
+                       <advanced>true</advanced>
+                       <label>Idle Timeout</label>
+                       <description>The idle-timeout parameter specifies maximum number of seconds a connection with Pushover can be idle.</description>
+                       <default>300</default>
+               </parameter>
        </config-description>
 
 </config-description:config-descriptions>
index be47aaa7cdb740bcadabbbfafcf38dd531caf0ec..68b5215d18f96feeecd8c981d2af9057a02301f7 100644 (file)
@@ -19,6 +19,8 @@ thing-type.config.pushover.pushover-account.format.description = The default for
 thing-type.config.pushover.pushover-account.format.option.none = None
 thing-type.config.pushover.pushover-account.format.option.html = HTML
 thing-type.config.pushover.pushover-account.format.option.monospace = monospace
+thing-type.config.pushover.pushover-account.idleTimeout.label = Idle Timeout
+thing-type.config.pushover.pushover-account.idleTimeout.description = The idle-timeout parameter specifies maximum number of seconds a connection with Pushover can be idle.
 thing-type.config.pushover.pushover-account.retry.label = Retry
 thing-type.config.pushover.pushover-account.retry.description = The retry parameter specifies how often the Pushover servers will send the same notification to the user.
 thing-type.config.pushover.pushover-account.sound.label = Notification Sound