Skip to content

Commit 80fc5db

Browse files
authored
[warmup] Set Dimension to QuantityType (openhab#17492)
Signed-off-by: Laurent Garnier <[email protected]>
1 parent 2535c6a commit 80fc5db

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

bundles/org.openhab.binding.warmup/src/main/java/org/openhab/binding/warmup/internal/action/WarmupActions.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
*/
1313
package org.openhab.binding.warmup.internal.action;
1414

15+
import javax.measure.quantity.Temperature;
16+
import javax.measure.quantity.Time;
17+
1518
import org.eclipse.jdt.annotation.NonNullByDefault;
1619
import org.eclipse.jdt.annotation.Nullable;
1720
import org.openhab.binding.warmup.internal.handler.RoomHandler;
@@ -53,8 +56,8 @@ public void setThingHandler(@Nullable ThingHandler handler) {
5356

5457
@RuleAction(label = "override", description = "Overrides the thermostat state for a specified time")
5558
public void setOverride(
56-
@ActionInput(name = "temperature", label = "Temperature") @Nullable QuantityType<?> temperature,
57-
@ActionInput(name = "duration", label = "Duration") @Nullable QuantityType<?> duration) {
59+
@ActionInput(name = "temperature", label = "Temperature") @Nullable QuantityType<Temperature> temperature,
60+
@ActionInput(name = "duration", label = "Duration") @Nullable QuantityType<Time> duration) {
5861
logger.debug("setOverride action called");
5962
RoomHandler handler = this.handler;
6063
if (handler != null && temperature != null && duration != null) {
@@ -64,8 +67,8 @@ public void setOverride(
6467
}
6568
}
6669

67-
public static void setOverride(@Nullable ThingActions actions, @Nullable QuantityType<?> temperature,
68-
@Nullable QuantityType<?> duration) {
70+
public static void setOverride(@Nullable ThingActions actions, @Nullable QuantityType<Temperature> temperature,
71+
@Nullable QuantityType<Time> duration) {
6972
if (actions instanceof WarmupActions warmupActions) {
7073
warmupActions.setOverride(temperature, duration);
7174
} else {

bundles/org.openhab.binding.warmup/src/main/java/org/openhab/binding/warmup/internal/handler/RoomHandler.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
import java.util.Map;
1919
import java.util.Set;
2020

21+
import javax.measure.quantity.Temperature;
22+
import javax.measure.quantity.Time;
23+
2124
import org.eclipse.jdt.annotation.NonNullByDefault;
2225
import org.eclipse.jdt.annotation.Nullable;
26+
import org.openhab.binding.warmup.internal.WarmupBindingConstants.RoomMode;
2327
import org.openhab.binding.warmup.internal.action.WarmupActions;
2428
import org.openhab.binding.warmup.internal.api.MyWarmupApi;
2529
import org.openhab.binding.warmup.internal.api.MyWarmupApiException;
@@ -68,11 +72,11 @@ public void handleCommand(ChannelUID channelUID, Command command) {
6872
super.handleCommand(channelUID, command);
6973
if (CHANNEL_TARGET_TEMPERATURE.equals(channelUID.getId())
7074
&& command instanceof QuantityType<?> quantityCommand) {
71-
setOverride(quantityCommand);
75+
setOverride((QuantityType<Temperature>) quantityCommand);
7276
}
7377
if (CHANNEL_FIXED_TEMPERATURE.equals(channelUID.getId())
7478
&& command instanceof QuantityType<?> quantityCommand) {
75-
setFixed(quantityCommand);
79+
setFixed((QuantityType<Temperature>) quantityCommand);
7680
}
7781
if (CHANNEL_FROST_PROTECTION_MODE.equals(channelUID.getId()) && command instanceof OnOffType onOffCommand) {
7882
toggleFrostProtectionMode(onOffCommand);
@@ -138,11 +142,11 @@ public Collection<Class<? extends ThingHandlerService>> getServices() {
138142
return Set.of(WarmupActions.class);
139143
}
140144

141-
private void setOverride(final QuantityType<?> command) {
145+
private void setOverride(final QuantityType<Temperature> command) {
142146
setOverride(command, new QuantityType<>(config.getOverrideDuration(), Units.MINUTE));
143147
}
144148

145-
public void setOverride(final QuantityType<?> temperature, final QuantityType<?> duration) {
149+
public void setOverride(final QuantityType<Temperature> temperature, final QuantityType<Time> duration) {
146150
setOverride(formatTemperature(temperature), duration.toUnit(Units.MINUTE).intValue());
147151
}
148152

@@ -163,7 +167,7 @@ private void setOverride(final int temperature, final int duration) {
163167
}
164168
}
165169

166-
private void setFixed(final QuantityType<?> command) {
170+
private void setFixed(final QuantityType<Temperature> command) {
167171
try {
168172
RoomCallout rc = getCallout();
169173
rc.api.setFixed(rc.locationId, rc.roomId, formatTemperature(command));

bundles/org.openhab.binding.warmup/src/main/java/org/openhab/binding/warmup/internal/handler/WarmupThingHandler.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package org.openhab.binding.warmup.internal.handler;
1414

15+
import javax.measure.quantity.Temperature;
16+
1517
import org.eclipse.jdt.annotation.NonNullByDefault;
1618
import org.eclipse.jdt.annotation.Nullable;
1719
import org.openhab.core.library.types.QuantityType;
@@ -104,7 +106,7 @@ protected State parseTemperature(@Nullable Integer temperature) {
104106
* @param temperature {@link QuantityType} a temperature
105107
* @return the temperature as an int in degrees C * 10. i.e. 21.5 degrees C = 215
106108
*/
107-
protected int formatTemperature(QuantityType<?> temperature) {
109+
protected int formatTemperature(QuantityType<Temperature> temperature) {
108110
return (int) (temperature.toUnit(SIUnits.CELSIUS).doubleValue() * 10);
109111
}
110112

0 commit comments

Comments
 (0)