mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-26 15:21:41 +01:00
[warmup] Set Dimension to QuantityType (#17492)
Signed-off-by: Laurent Garnier <lg.hc@free.fr> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
2ee86a07e9
commit
af9a48253b
@ -12,6 +12,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.warmup.internal.action;
|
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.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.warmup.internal.handler.RoomHandler;
|
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")
|
@RuleAction(label = "override", description = "Overrides the thermostat state for a specified time")
|
||||||
public void setOverride(
|
public void setOverride(
|
||||||
@ActionInput(name = "temperature", label = "Temperature") @Nullable QuantityType<?> temperature,
|
@ActionInput(name = "temperature", label = "Temperature") @Nullable QuantityType<Temperature> temperature,
|
||||||
@ActionInput(name = "duration", label = "Duration") @Nullable QuantityType<?> duration) {
|
@ActionInput(name = "duration", label = "Duration") @Nullable QuantityType<Time> duration) {
|
||||||
logger.debug("setOverride action called");
|
logger.debug("setOverride action called");
|
||||||
RoomHandler handler = this.handler;
|
RoomHandler handler = this.handler;
|
||||||
if (handler != null && temperature != null && duration != null) {
|
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,
|
public static void setOverride(@Nullable ThingActions actions, @Nullable QuantityType<Temperature> temperature,
|
||||||
@Nullable QuantityType<?> duration) {
|
@Nullable QuantityType<Time> duration) {
|
||||||
if (actions instanceof WarmupActions warmupActions) {
|
if (actions instanceof WarmupActions warmupActions) {
|
||||||
warmupActions.setOverride(temperature, duration);
|
warmupActions.setOverride(temperature, duration);
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,8 +18,12 @@ import java.util.Collection;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
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.action.WarmupActions;
|
||||||
import org.openhab.binding.warmup.internal.api.MyWarmupApi;
|
import org.openhab.binding.warmup.internal.api.MyWarmupApi;
|
||||||
import org.openhab.binding.warmup.internal.api.MyWarmupApiException;
|
import org.openhab.binding.warmup.internal.api.MyWarmupApiException;
|
||||||
@ -68,11 +72,11 @@ public class RoomHandler extends WarmupThingHandler implements WarmupRefreshList
|
|||||||
super.handleCommand(channelUID, command);
|
super.handleCommand(channelUID, command);
|
||||||
if (CHANNEL_TARGET_TEMPERATURE.equals(channelUID.getId())
|
if (CHANNEL_TARGET_TEMPERATURE.equals(channelUID.getId())
|
||||||
&& command instanceof QuantityType<?> quantityCommand) {
|
&& command instanceof QuantityType<?> quantityCommand) {
|
||||||
setOverride(quantityCommand);
|
setOverride((QuantityType<Temperature>) quantityCommand);
|
||||||
}
|
}
|
||||||
if (CHANNEL_FIXED_TEMPERATURE.equals(channelUID.getId())
|
if (CHANNEL_FIXED_TEMPERATURE.equals(channelUID.getId())
|
||||||
&& command instanceof QuantityType<?> quantityCommand) {
|
&& command instanceof QuantityType<?> quantityCommand) {
|
||||||
setFixed(quantityCommand);
|
setFixed((QuantityType<Temperature>) quantityCommand);
|
||||||
}
|
}
|
||||||
if (CHANNEL_FROST_PROTECTION_MODE.equals(channelUID.getId()) && command instanceof OnOffType onOffCommand) {
|
if (CHANNEL_FROST_PROTECTION_MODE.equals(channelUID.getId()) && command instanceof OnOffType onOffCommand) {
|
||||||
toggleFrostProtectionMode(onOffCommand);
|
toggleFrostProtectionMode(onOffCommand);
|
||||||
@ -138,11 +142,11 @@ public class RoomHandler extends WarmupThingHandler implements WarmupRefreshList
|
|||||||
return Set.of(WarmupActions.class);
|
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));
|
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());
|
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 {
|
try {
|
||||||
RoomCallout rc = getCallout();
|
RoomCallout rc = getCallout();
|
||||||
rc.api.setFixed(rc.locationId, rc.roomId, formatTemperature(command));
|
rc.api.setFixed(rc.locationId, rc.roomId, formatTemperature(command));
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.warmup.internal.handler;
|
package org.openhab.binding.warmup.internal.handler;
|
||||||
|
|
||||||
|
import javax.measure.quantity.Temperature;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.core.library.types.QuantityType;
|
import org.openhab.core.library.types.QuantityType;
|
||||||
@ -104,7 +106,7 @@ public class WarmupThingHandler extends BaseThingHandler {
|
|||||||
* @param temperature {@link QuantityType} a temperature
|
* @param temperature {@link QuantityType} a temperature
|
||||||
* @return the temperature as an int in degrees C * 10. i.e. 21.5 degrees C = 215
|
* @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);
|
return (int) (temperature.toUnit(SIUnits.CELSIUS).doubleValue() * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user