[froniuswattpilot] Improve dispose behaviour & Upgrade to wattpilot4j 1.3.0 (#18819)

Signed-off-by: Florian Hotze <dev@florianhotze.com>
This commit is contained in:
Florian Hotze
2025-06-22 15:31:25 +02:00
committed by GitHub
parent 1524ac1ed8
commit 200400de9d
3 changed files with 7 additions and 21 deletions
@@ -18,7 +18,7 @@
<dependency>
<groupId>com.florianhotze.sdk</groupId>
<artifactId>wattpilot4j</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
@@ -4,7 +4,7 @@
<feature name="openhab-binding-froniuswattpilot" description="Fronius Wattpilot Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:com.florianhotze.sdk/wattpilot4j/1.2.0</bundle>
<bundle dependency="true">mvn:com.florianhotze.sdk/wattpilot4j/1.3.0</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.froniuswattpilot/${project.version}</bundle>
</feature>
</features>
@@ -17,7 +17,6 @@ import static org.openhab.binding.froniuswattpilot.internal.FroniusWattpilotBind
import java.io.IOException;
import java.net.NoRouteToHostException;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -64,8 +63,6 @@ public class FroniusWattpilotHandler extends BaseThingHandler implements Wattpil
private final Logger logger = LoggerFactory.getLogger(FroniusWattpilotHandler.class);
private final WattpilotClient client;
private @Nullable CompletableFuture<@Nullable Void> awaitDisconnect;
private @Nullable FroniusWattpilotConfiguration config;
public FroniusWattpilotHandler(Thing thing, HttpClient httpClient) {
@@ -182,19 +179,12 @@ public class FroniusWattpilotHandler extends BaseThingHandler implements Wattpil
@Override
public void dispose() {
if (client.isConnected()) {
CompletableFuture<@Nullable Void> awaitDisconnect = this.awaitDisconnect;
if (awaitDisconnect != null) {
awaitDisconnect.cancel(true);
}
awaitDisconnect = this.awaitDisconnect = new CompletableFuture<>();
client.disconnect();
try {
awaitDisconnect.get(3, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error("Failed to wait for disconnect", e);
}
try {
client.disconnect().get(3, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error("Failed to disconnect", e);
}
client.removeListener(this);
}
@Override
@@ -205,10 +195,6 @@ public class FroniusWattpilotHandler extends BaseThingHandler implements Wattpil
@Override
public void disconnected(@Nullable String reason, @Nullable Throwable cause) {
CompletableFuture<@Nullable Void> awaitDisconnect = this.awaitDisconnect;
if (awaitDisconnect != null) {
awaitDisconnect.complete(null);
}
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, reason);
if (cause instanceof TimeoutException || cause instanceof NoRouteToHostException
|| cause instanceof EofException || cause instanceof Utf8Appendable.NotUtf8Exception) {