[pushover] Fix idle connection causing EOF exception (#17348)

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2024-10-07 23:36:26 +02:00 committed by GitHub
parent 31f6cda174
commit b36877ec6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 32 additions and 4 deletions

View 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

View 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");

View File

@ -47,4 +47,5 @@ public class PushoverAccountConfiguration {
public int retry = 300;
public int expire = 3600;
public int timeout = 10;
public int idleTimeout = 300;
}

View 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

View 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);
}

View File

@ -55,6 +55,12 @@
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>

View 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