[warmup] Set Dimension to QuantityType (#17492)

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2024-10-01 22:07:55 +02:00 committed by GitHub
parent 2535c6ada2
commit 80fc5db373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 10 deletions

View 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 {

View 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));

View 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);
}