]> git.basschouten.com Git - openhab-addons.git/commitdiff
[warmup] Set Dimension to QuantityType (#17492)
authorlolodomo <lg.hc@free.fr>
Tue, 1 Oct 2024 20:07:55 +0000 (22:07 +0200)
committerGitHub <noreply@github.com>
Tue, 1 Oct 2024 20:07:55 +0000 (22:07 +0200)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.warmup/src/main/java/org/openhab/binding/warmup/internal/action/WarmupActions.java
bundles/org.openhab.binding.warmup/src/main/java/org/openhab/binding/warmup/internal/handler/RoomHandler.java
bundles/org.openhab.binding.warmup/src/main/java/org/openhab/binding/warmup/internal/handler/WarmupThingHandler.java

index 3960205068ca6f941cec1fd4c7b333c52eb48a16..964127926e6de41cd168750f460f7168e6f13f08 100644 (file)
@@ -12,6 +12,9 @@
  */
 package org.openhab.binding.warmup.internal.action;
 
+import javax.measure.quantity.Temperature;
+import javax.measure.quantity.Time;
+
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.warmup.internal.handler.RoomHandler;
@@ -53,8 +56,8 @@ public class WarmupActions implements ThingActions {
 
     @RuleAction(label = "override", description = "Overrides the thermostat state for a specified time")
     public void setOverride(
-            @ActionInput(name = "temperature", label = "Temperature") @Nullable QuantityType<?> temperature,
-            @ActionInput(name = "duration", label = "Duration") @Nullable QuantityType<?> duration) {
+            @ActionInput(name = "temperature", label = "Temperature") @Nullable QuantityType<Temperature> temperature,
+            @ActionInput(name = "duration", label = "Duration") @Nullable QuantityType<Time> duration) {
         logger.debug("setOverride action called");
         RoomHandler handler = this.handler;
         if (handler != null && temperature != null && duration != null) {
@@ -64,8 +67,8 @@ public class WarmupActions implements ThingActions {
         }
     }
 
-    public static void setOverride(@Nullable ThingActions actions, @Nullable QuantityType<?> temperature,
-            @Nullable QuantityType<?> duration) {
+    public static void setOverride(@Nullable ThingActions actions, @Nullable QuantityType<Temperature> temperature,
+            @Nullable QuantityType<Time> duration) {
         if (actions instanceof WarmupActions warmupActions) {
             warmupActions.setOverride(temperature, duration);
         } else {
index 9840d8a72b2b63211d6c8ad3bcff6f62c0d2e62e..9f8fbf2a9058072e954fd134810bb65f8997ecc9 100644 (file)
@@ -18,8 +18,12 @@ import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
 
+import javax.measure.quantity.Temperature;
+import javax.measure.quantity.Time;
+
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.warmup.internal.WarmupBindingConstants.RoomMode;
 import org.openhab.binding.warmup.internal.action.WarmupActions;
 import org.openhab.binding.warmup.internal.api.MyWarmupApi;
 import org.openhab.binding.warmup.internal.api.MyWarmupApiException;
@@ -68,11 +72,11 @@ public class RoomHandler extends WarmupThingHandler implements WarmupRefreshList
         super.handleCommand(channelUID, command);
         if (CHANNEL_TARGET_TEMPERATURE.equals(channelUID.getId())
                 && command instanceof QuantityType<?> quantityCommand) {
-            setOverride(quantityCommand);
+            setOverride((QuantityType<Temperature>) quantityCommand);
         }
         if (CHANNEL_FIXED_TEMPERATURE.equals(channelUID.getId())
                 && command instanceof QuantityType<?> quantityCommand) {
-            setFixed(quantityCommand);
+            setFixed((QuantityType<Temperature>) quantityCommand);
         }
         if (CHANNEL_FROST_PROTECTION_MODE.equals(channelUID.getId()) && command instanceof OnOffType onOffCommand) {
             toggleFrostProtectionMode(onOffCommand);
@@ -138,11 +142,11 @@ public class RoomHandler extends WarmupThingHandler implements WarmupRefreshList
         return Set.of(WarmupActions.class);
     }
 
-    private void setOverride(final QuantityType<?> command) {
+    private void setOverride(final QuantityType<Temperature> command) {
         setOverride(command, new QuantityType<>(config.getOverrideDuration(), Units.MINUTE));
     }
 
-    public void setOverride(final QuantityType<?> temperature, final QuantityType<?> duration) {
+    public void setOverride(final QuantityType<Temperature> temperature, final QuantityType<Time> duration) {
         setOverride(formatTemperature(temperature), duration.toUnit(Units.MINUTE).intValue());
     }
 
@@ -163,7 +167,7 @@ public class RoomHandler extends WarmupThingHandler implements WarmupRefreshList
         }
     }
 
-    private void setFixed(final QuantityType<?> command) {
+    private void setFixed(final QuantityType<Temperature> command) {
         try {
             RoomCallout rc = getCallout();
             rc.api.setFixed(rc.locationId, rc.roomId, formatTemperature(command));
index faafbb5bc966dc5d291636c9d2e4867d1df52340..b05c2cfe303599af7d222ea6f16602a9d8ac9e8f 100644 (file)
@@ -12,6 +12,8 @@
  */
 package org.openhab.binding.warmup.internal.handler;
 
+import javax.measure.quantity.Temperature;
+
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.core.library.types.QuantityType;
@@ -104,7 +106,7 @@ public class WarmupThingHandler extends BaseThingHandler {
      * @param temperature {@link QuantityType} a temperature
      * @return the temperature as an int in degrees C * 10. i.e. 21.5 degrees C = 215
      */
-    protected int formatTemperature(QuantityType<?> temperature) {
+    protected int formatTemperature(QuantityType<Temperature> temperature) {
         return (int) (temperature.toUnit(SIUnits.CELSIUS).doubleValue() * 10);
     }