[somfytahoma] Improved handling of target temperature command (#10336)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
b707ffb8c4
commit
88022b1125
@ -14,9 +14,11 @@ package org.openhab.binding.somfytahoma.internal.handler;
|
|||||||
|
|
||||||
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.measure.Unit;
|
import javax.measure.Unit;
|
||||||
|
|
||||||
@ -231,6 +233,10 @@ public abstract class SomfyTahomaBaseThingHandler extends BaseThingHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Unit<?> getTemperatureUnit() {
|
||||||
|
return Objects.requireNonNull(units.get("Number:Temperature"));
|
||||||
|
}
|
||||||
|
|
||||||
private void updateUnits(List<SomfyTahomaState> attributes) {
|
private void updateUnits(List<SomfyTahomaState> attributes) {
|
||||||
for (SomfyTahomaState attr : attributes) {
|
for (SomfyTahomaState attr : attributes) {
|
||||||
if ("core:MeasuredValueType".equals(attr.getName()) && attr.getType() == TYPE_STRING) {
|
if ("core:MeasuredValueType".equals(attr.getName()) && attr.getType() == TYPE_STRING) {
|
||||||
@ -387,12 +393,7 @@ public abstract class SomfyTahomaBaseThingHandler extends BaseThingHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable SomfyTahomaState getStatusState(List<SomfyTahomaState> states) {
|
private @Nullable SomfyTahomaState getStatusState(List<SomfyTahomaState> states) {
|
||||||
for (SomfyTahomaState state : states) {
|
return getState(states, STATUS_STATE, TYPE_STRING);
|
||||||
if (STATUS_STATE.equals(state.getName()) && state.getType() == TYPE_STRING) {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateThingStatus(@Nullable SomfyTahomaState state) {
|
private void updateThingStatus(@Nullable SomfyTahomaState state) {
|
||||||
@ -456,4 +457,29 @@ public abstract class SomfyTahomaBaseThingHandler extends BaseThingHandler {
|
|||||||
public int toInteger(Command command) {
|
public int toInteger(Command command) {
|
||||||
return (command instanceof DecimalType) ? ((DecimalType) command).intValue() : 0;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ package org.openhab.binding.somfytahoma.internal.handler;
|
|||||||
|
|
||||||
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,6 +23,7 @@ import org.openhab.core.thing.Thing;
|
|||||||
*
|
*
|
||||||
* @author Ondrej Pecta - Initial contribution
|
* @author Ondrej Pecta - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class SomfyTahomaElectricitySensorHandler extends SomfyTahomaBaseThingHandler {
|
public class SomfyTahomaElectricitySensorHandler extends SomfyTahomaBaseThingHandler {
|
||||||
|
|
||||||
public SomfyTahomaElectricitySensorHandler(Thing thing) {
|
public SomfyTahomaElectricitySensorHandler(Thing thing) {
|
||||||
|
|||||||
@ -14,8 +14,9 @@ package org.openhab.binding.somfytahoma.internal.handler;
|
|||||||
|
|
||||||
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.core.library.types.QuantityType;
|
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
@ -47,10 +48,12 @@ public class SomfyTahomaValveHeatingSystemHandler extends SomfyTahomaBaseThingHa
|
|||||||
if (command instanceof RefreshType) {
|
if (command instanceof RefreshType) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (DEROGATED_TARGET_TEMPERATURE.equals(channelUID.getId()) && command instanceof QuantityType) {
|
if (DEROGATED_TARGET_TEMPERATURE.equals(channelUID.getId())) {
|
||||||
QuantityType type = (QuantityType) command;
|
BigDecimal temperature = toTemperature(command);
|
||||||
String param = "[" + type.doubleValue() + ", \"next_mode\"]";
|
if (temperature != null) {
|
||||||
sendCommand(COMMAND_SET_DEROGATION, param);
|
String param = "[" + temperature.toPlainString() + ", \"next_mode\"]";
|
||||||
|
sendCommand(COMMAND_SET_DEROGATION, param);
|
||||||
|
}
|
||||||
} else if (DEROGATION_HEATING_MODE.equals(channelUID.getId())) {
|
} else if (DEROGATION_HEATING_MODE.equals(channelUID.getId())) {
|
||||||
switch (command.toString()) {
|
switch (command.toString()) {
|
||||||
case "auto":
|
case "auto":
|
||||||
|
|||||||
@ -14,6 +14,8 @@ package org.openhab.binding.somfytahoma.internal.handler;
|
|||||||
|
|
||||||
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
@ -44,8 +46,11 @@ public class SomfyTahomaZwaveHeatingSystemHandler extends SomfyTahomaBaseThingHa
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (TARGET_TEMPERATURE.equals(channelUID.getId())) {
|
if (TARGET_TEMPERATURE.equals(channelUID.getId())) {
|
||||||
String param = "[" + command.toString() + "]";
|
BigDecimal temperature = toTemperature(command);
|
||||||
sendCommand("setTargetTemperature", param);
|
if (temperature != null) {
|
||||||
|
String param = "[" + temperature.toPlainString() + "]";
|
||||||
|
sendCommand("setTargetTemperature", param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user