[opensprinkler] fix nextDuration UoM transformation (#8727)

Fixes #8541 

Signed-off-by: Holger Eisold <kugelsicha@gmail.com>
This commit is contained in:
HoLLe 2020-10-14 19:08:57 +02:00 committed by GitHub
parent b9beaad5cd
commit 5e2c5345eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -25,7 +25,6 @@ import org.openhab.binding.opensprinkler.internal.api.OpenSprinklerApi;
import org.openhab.binding.opensprinkler.internal.api.exception.CommunicationApiException; import org.openhab.binding.opensprinkler.internal.api.exception.CommunicationApiException;
import org.openhab.binding.opensprinkler.internal.api.exception.GeneralApiException; import org.openhab.binding.opensprinkler.internal.api.exception.GeneralApiException;
import org.openhab.binding.opensprinkler.internal.config.OpenSprinklerStationConfig; import org.openhab.binding.opensprinkler.internal.config.OpenSprinklerStationConfig;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.QuantityType;
import org.openhab.core.thing.Channel; import org.openhab.core.thing.Channel;
@ -85,13 +84,14 @@ public class OpenSprinklerStationHandler extends OpenSprinklerBaseHandler {
updateChannels(); updateChannels();
} }
@SuppressWarnings("null")
private void handleNextDurationCommand(ChannelUID channelUID, Command command) { private void handleNextDurationCommand(ChannelUID channelUID, Command command) {
if (!(command instanceof QuantityType<?>)) { if (!(command instanceof QuantityType<?>)) {
logger.info("Ignoring implausible non-QuantityType command for NEXT_DURATION"); logger.info("Ignoring implausible non-QuantityType command for NEXT_DURATION");
return; return;
} }
QuantityType<?> quantity = (QuantityType<?>) command; QuantityType<?> quantity = (QuantityType<?>) command;
this.nextDurationTime = quantity.toBigDecimal(); this.nextDurationTime = quantity.toUnit(Units.SECOND).toBigDecimal();
updateState(channelUID, quantity); updateState(channelUID, quantity);
} }
@ -204,7 +204,7 @@ public class OpenSprinklerStationHandler extends OpenSprinklerBaseHandler {
case NEXT_DURATION: case NEXT_DURATION:
BigDecimal duration = nextDurationValue(); BigDecimal duration = nextDurationValue();
if (duration != null) { if (duration != null) {
updateState(channel, new DecimalType(duration)); updateState(channel, new QuantityType<>(duration, Units.SECOND));
} }
break; break;
case STATION_QUEUED: case STATION_QUEUED:

View File

@ -120,6 +120,6 @@
<item-type>Number:Time</item-type> <item-type>Number:Time</item-type>
<label>Next Open Duration</label> <label>Next Open Duration</label>
<description>The duration the station will be opened the next time it is switched on.</description> <description>The duration the station will be opened the next time it is switched on.</description>
<state readOnly="false" pattern="%.0f s"/> <state readOnly="false" pattern="%.0f min"/>
</channel-type> </channel-type>
</thing:thing-descriptions> </thing:thing-descriptions>