Skip to content

Commit

Permalink
Further adjustments according to second review.
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Koenemann <git@paphko.de>
  • Loading branch information
paphko committed Nov 22, 2021
1 parent 078f166 commit 3487753
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -177,7 +176,7 @@ public Map<String, State> 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) {
Expand All @@ -193,7 +192,7 @@ public Map<String, State> 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) {
Expand Down

0 comments on commit 3487753

Please sign in to comment.