Skip to content

Commit

Permalink
Fix for openhab#8431: Handling of UBM for channels autoOn and autoOff
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Michels <markus7017@gmail.com>
  • Loading branch information
markus7017 committed Sep 8, 2020
1 parent e10f409 commit 1f5ef34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ public boolean handleDeviceCommand(ChannelUID channelUID, Command command) throw

case CHANNEL_TIMER_AUTOON:
logger.debug("{}: Set Auto-ON timer to {}", thingName, command);
api.setTimer(rIndex, SHELLY_TIMER_AUTOON, ((DecimalType) command).doubleValue());
api.setTimer(rIndex, SHELLY_TIMER_AUTOON, getNumber(command));
break;
case CHANNEL_TIMER_AUTOOFF:
logger.debug("{}: Set Auto-OFF timer to {}", thingName, command);
api.setTimer(rIndex, SHELLY_TIMER_AUTOOFF, ((DecimalType) command).doubleValue());
api.setTimer(rIndex, SHELLY_TIMER_AUTOOFF, getNumber(command));
break;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.UnDefType;
import org.openhab.binding.shelly.internal.api.ShellyApiException;
Expand Down Expand Up @@ -147,6 +148,16 @@ public static DecimalType getDecimal(@Nullable Long value) {
return new DecimalType((value != null ? value : 0));
}

public static Double getNumber(Command command) throws IllegalArgumentException {
if (command instanceof DecimalType) {
return ((DecimalType) command).doubleValue();
}
if (command instanceof QuantityType) {
return ((QuantityType<?>) command).doubleValue();
}
throw new IllegalArgumentException("Unable to convert number");
}

public static OnOffType getOnOff(@Nullable Boolean value) {
return (value != null ? value ? OnOffType.ON : OnOffType.OFF : OnOffType.OFF);
}
Expand Down

0 comments on commit 1f5ef34

Please sign in to comment.