import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
+import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import javax.measure.Unit;
}
}
+ protected Unit<?> getTemperatureUnit() {
+ return Objects.requireNonNull(units.get("Number:Temperature"));
+ }
+
private void updateUnits(List<SomfyTahomaState> attributes) {
for (SomfyTahomaState attr : attributes) {
if ("core:MeasuredValueType".equals(attr.getName()) && attr.getType() == TYPE_STRING) {
}
private @Nullable SomfyTahomaState getStatusState(List<SomfyTahomaState> states) {
- for (SomfyTahomaState state : states) {
- if (STATUS_STATE.equals(state.getName()) && state.getType() == TYPE_STRING) {
- return state;
- }
- }
- return null;
+ return getState(states, STATUS_STATE, TYPE_STRING);
}
private void updateThingStatus(@Nullable SomfyTahomaState state) {
public int toInteger(Command command) {
return (command instanceof DecimalType) ? ((DecimalType) command).intValue() : 0;
}
+
+ public @Nullable BigDecimal toTemperature(Command command) {
+ BigDecimal temperature = null;
+ if (command instanceof QuantityType<?>) {
+ QuantityType<?> quantity = (QuantityType<?>) command;
+ QuantityType<?> convertedQuantity = quantity.toUnit(getTemperatureUnit());
+ if (convertedQuantity != null) {
+ quantity = convertedQuantity;
+ }
+ temperature = quantity.toBigDecimal();
+ } else if (command instanceof DecimalType) {
+ temperature = ((DecimalType) command).toBigDecimal();
+ }
+ return temperature;
+ }
+
+ public static @Nullable SomfyTahomaState getState(List<SomfyTahomaState> states, String stateName,
+ @Nullable Integer stateType) {
+ for (SomfyTahomaState state : states) {
+ if (stateName.equals(state.getName()) && (stateType == null || stateType == state.getType())) {
+ return state;
+ }
+ }
+ return null;
+ }
}
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
+import java.math.BigDecimal;
+
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.openhab.core.library.types.QuantityType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.Command;
if (command instanceof RefreshType) {
return;
} else {
- if (DEROGATED_TARGET_TEMPERATURE.equals(channelUID.getId()) && command instanceof QuantityType) {
- QuantityType type = (QuantityType) command;
- String param = "[" + type.doubleValue() + ", \"next_mode\"]";
- sendCommand(COMMAND_SET_DEROGATION, param);
+ if (DEROGATED_TARGET_TEMPERATURE.equals(channelUID.getId())) {
+ BigDecimal temperature = toTemperature(command);
+ if (temperature != null) {
+ String param = "[" + temperature.toPlainString() + ", \"next_mode\"]";
+ sendCommand(COMMAND_SET_DEROGATION, param);
+ }
} else if (DEROGATION_HEATING_MODE.equals(channelUID.getId())) {
switch (command.toString()) {
case "auto":
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
+import java.math.BigDecimal;
+
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
return;
} else {
if (TARGET_TEMPERATURE.equals(channelUID.getId())) {
- String param = "[" + command.toString() + "]";
- sendCommand("setTargetTemperature", param);
+ BigDecimal temperature = toTemperature(command);
+ if (temperature != null) {
+ String param = "[" + temperature.toPlainString() + "]";
+ sendCommand("setTargetTemperature", param);
+ }
}
}
}