From 3487753af176198faa63eb727db789ddfdc0ddf5 Mon Sep 17 00:00:00 2001 From: Patrick Koenemann Date: Mon, 22 Nov 2021 12:06:38 +0100 Subject: [PATCH] Further adjustments according to second review. Signed-off-by: Patrick Koenemann --- .../binding/anel/internal/AnelHandler.java | 18 ++++++++++++------ .../anel/internal/state/AnelStateUpdater.java | 7 +++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.anel/src/main/java/org/openhab/binding/anel/internal/AnelHandler.java b/bundles/org.openhab.binding.anel/src/main/java/org/openhab/binding/anel/internal/AnelHandler.java index 42a53b52364f2..1c9d56f4bd793 100644 --- a/bundles/org.openhab.binding.anel/src/main/java/org/openhab/binding/anel/internal/AnelHandler.java +++ b/bundles/org.openhab.binding.anel/src/main/java/org/openhab/binding/anel/internal/AnelHandler.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.anel.internal; +import java.io.IOException; import java.util.Map; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -97,7 +98,11 @@ private void initializeConnection() { // request initial state, 3 attempts for (int attempt = 1; attempt <= IAnelConstants.ATTEMPTS_WITH_COMMUNICATION_ERRORS && state == null; attempt++) { - newUdpConnector.send(IAnelConstants.BROADCAST_DISCOVERY_MSG); + try { + newUdpConnector.send(IAnelConstants.BROADCAST_DISCOVERY_MSG); + } catch (IOException e) { + // network or socket failure, also wait 2 sec and try again + } // answer expected within 50-600ms on a regular network; wait up to 2sec just to make sure for (int delay = 0; delay < 10 && state == null; delay++) { @@ -125,14 +130,13 @@ private void initializeConnection() { } catch (InterruptedException e) { - // OH shutdown - don't log anything, just clean up - dispose(); + // OH shutdown - don't log anything, Framework will call dispose() } catch (Exception e) { logger.debug("Connection to '{}' failed", config, e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, "Connection to '" + config - + "' failed with " + e.getClass().getSimpleName() + ": " + e.getMessage()); + + "' failed unexpectedly with " + e.getClass().getSimpleName() + ": " + e.getMessage()); dispose(); } } @@ -226,10 +230,12 @@ public void handleCommand(ChannelUID channelUID, Command command) { updateState(channelUID, lockedState); } else if (anelCommand == null) { - logger.info("Channel {} received command {} which is (currently) not supported", channelUID, command); + logger.info( + "Channel {} received command {} which is (currently) not supported; please check channel configuration.", + channelUID, command); } } else { - logger.info("Channel {} received command {} which is (currently) not supported", channelUID, command); + logger.info("Channel {} received command {} which is not supported", channelUID, command); } if (anelCommand != null) { diff --git a/bundles/org.openhab.binding.anel/src/main/java/org/openhab/binding/anel/internal/state/AnelStateUpdater.java b/bundles/org.openhab.binding.anel/src/main/java/org/openhab/binding/anel/internal/state/AnelStateUpdater.java index fccf190a22ef2..6234743a35a01 100644 --- a/bundles/org.openhab.binding.anel/src/main/java/org/openhab/binding/anel/internal/state/AnelStateUpdater.java +++ b/bundles/org.openhab.binding.anel/src/main/java/org/openhab/binding/anel/internal/state/AnelStateUpdater.java @@ -24,11 +24,10 @@ import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.StringType; +import org.openhab.core.library.unit.SIUnits; import org.openhab.core.types.State; import org.openhab.core.types.UnDefType; -import tech.units.indriya.unit.Units; - /** * Get updates for {@link AnelState}s. * @@ -177,7 +176,7 @@ public Map getChannelUpdates(@Nullable AnelState oldState, AnelSt return null; } final float floatValue = Float.parseFloat(value); - return QuantityType.valueOf(floatValue, Units.CELSIUS); + return QuantityType.valueOf(floatValue, SIUnits.CELSIUS); } private @Nullable State getSwitchState(@Nullable Boolean value) { @@ -193,7 +192,7 @@ public Map getChannelUpdates(@Nullable AnelState oldState, AnelSt } private @Nullable State getNewTemperatureState(@Nullable String oldValue, @Nullable String newValue) { - return getNewState(oldValue, newValue, value -> QuantityType.valueOf(Float.parseFloat(value), Units.CELSIUS)); + return getNewState(oldValue, newValue, value -> QuantityType.valueOf(Float.parseFloat(value), SIUnits.CELSIUS)); } private @Nullable State getNewSwitchState(@Nullable Boolean oldValue, @Nullable Boolean newValue) {