Skip to content

Commit

Permalink
[warmup] Set Dimension to QuantityType (openhab#17492)
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored Oct 1, 2024
1 parent 2535c6a commit 80fc5db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,8 +56,8 @@ public void setThingHandler(@Nullable ThingHandler handler) {

@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) {
Expand All @@ -64,8 +67,8 @@ public void setOverride(
}
}

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
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;
Expand Down Expand Up @@ -68,11 +72,11 @@ public void handleCommand(ChannelUID channelUID, Command command) {
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);
Expand Down Expand Up @@ -138,11 +142,11 @@ public Collection<Class<? extends ThingHandlerService>> getServices() {
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());
}

Expand All @@ -163,7 +167,7 @@ private void setOverride(final int temperature, final int duration) {
}
}

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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,7 +106,7 @@ protected State parseTemperature(@Nullable Integer temperature) {
* @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);
}

Expand Down

0 comments on commit 80fc5db

Please sign in to comment.