Skip to content

Commit

Permalink
[Senec] Add request timeout (openhab#16611)
Browse files Browse the repository at this point in the history
Fixes openhab#12900. Add a timeout for requests to the local Senec device. Currently there may occur some endlessly hanging requests which basically freeze the values provided by the binding.

Signed-off-by: Stefan Sedlmaier <github@ssedlmaier.de>
  • Loading branch information
ssedlmaier authored Apr 4, 2024
1 parent 7f46869 commit bf486e3
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -81,7 +82,8 @@ public SenecHomeResponse getStatistics()
try {
String dataToSend = gson.toJson(new SenecHomeResponse());
logger.trace("data to send: {}", dataToSend);
response = request.method(HttpMethod.POST).content(new StringContentProvider(dataToSend)).send();
response = request.method(HttpMethod.POST).content(new StringContentProvider(dataToSend))
.timeout(15, TimeUnit.SECONDS).send();
if (response.getStatus() == HttpStatus.OK_200) {
String responseString = response.getContentAsString();
return Objects.requireNonNull(gson.fromJson(responseString, SenecHomeResponse.class));
Expand Down

0 comments on commit bf486e3

Please sign in to comment.