From 5e2c5345eb1ba45d4eea9b220d1be4efc4a93ac2 Mon Sep 17 00:00:00 2001 From: HoLLe <760240+HerzScheisse@users.noreply.github.com> Date: Wed, 14 Oct 2020 19:08:57 +0200 Subject: [PATCH] [opensprinkler] fix nextDuration UoM transformation (#8727) Fixes #8541 Signed-off-by: Holger Eisold --- .../internal/handler/OpenSprinklerStationHandler.java | 6 +++--- .../src/main/resources/OH-INF/thing/thing-types.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/handler/OpenSprinklerStationHandler.java b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/handler/OpenSprinklerStationHandler.java index f0b5718760e..2ce7230f17c 100644 --- a/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/handler/OpenSprinklerStationHandler.java +++ b/bundles/org.openhab.binding.opensprinkler/src/main/java/org/openhab/binding/opensprinkler/internal/handler/OpenSprinklerStationHandler.java @@ -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.GeneralApiException; 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.QuantityType; import org.openhab.core.thing.Channel; @@ -85,13 +84,14 @@ public class OpenSprinklerStationHandler extends OpenSprinklerBaseHandler { updateChannels(); } + @SuppressWarnings("null") private void handleNextDurationCommand(ChannelUID channelUID, Command command) { if (!(command instanceof QuantityType)) { logger.info("Ignoring implausible non-QuantityType command for NEXT_DURATION"); return; } QuantityType quantity = (QuantityType) command; - this.nextDurationTime = quantity.toBigDecimal(); + this.nextDurationTime = quantity.toUnit(Units.SECOND).toBigDecimal(); updateState(channelUID, quantity); } @@ -204,7 +204,7 @@ public class OpenSprinklerStationHandler extends OpenSprinklerBaseHandler { case NEXT_DURATION: BigDecimal duration = nextDurationValue(); if (duration != null) { - updateState(channel, new DecimalType(duration)); + updateState(channel, new QuantityType<>(duration, Units.SECOND)); } break; case STATION_QUEUED: diff --git a/bundles/org.openhab.binding.opensprinkler/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.opensprinkler/src/main/resources/OH-INF/thing/thing-types.xml index 22afafaef1d..bea478715c3 100644 --- a/bundles/org.openhab.binding.opensprinkler/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.opensprinkler/src/main/resources/OH-INF/thing/thing-types.xml @@ -120,6 +120,6 @@ Number:Time The duration the station will be opened the next time it is switched on. - +