mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-26 15:21:41 +01:00
[Senec] Add request timeout (#16611)
Fixes #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> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
637c1301b2
commit
1edb47a937
@ -15,6 +15,7 @@ package org.openhab.binding.senechome.internal;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
@ -81,7 +82,8 @@ public class SenecHomeApi {
|
|||||||
try {
|
try {
|
||||||
String dataToSend = gson.toJson(new SenecHomeResponse());
|
String dataToSend = gson.toJson(new SenecHomeResponse());
|
||||||
logger.trace("data to send: {}", dataToSend);
|
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) {
|
if (response.getStatus() == HttpStatus.OK_200) {
|
||||||
String responseString = response.getContentAsString();
|
String responseString = response.getContentAsString();
|
||||||
return Objects.requireNonNull(gson.fromJson(responseString, SenecHomeResponse.class));
|
return Objects.requireNonNull(gson.fromJson(responseString, SenecHomeResponse.class));
|
||||||
|
Loading…
Reference in New Issue
Block a user