Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pushover] Fix idle connection causing EOF exception #17348

Merged
merged 15 commits into from
Oct 7, 2024
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.pushover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ public class PushoverAccountConfiguration {
public int retry = 300;
public int expire = 3600;
public int timeout = 10;
public int idleTimeout = 300;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void initialize() {

if (configValid) {
updateStatus(ThingStatus.UNKNOWN);

httpClient.setIdleTimeout(config.idleTimeout * 1000);
connection = new PushoverAPIConnection(httpClient, config);
scheduler.submit(this::asyncValidateUser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>