[somfytahoma] Improved handling of target temperature command (#10336)

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2021-03-21 14:23:07 +01:00 committed by GitHub
parent b707ffb8c4
commit 88022b1125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 13 deletions

View File

@ -14,9 +14,11 @@ package org.openhab.binding.somfytahoma.internal.handler;
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;
@ -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) {
for (SomfyTahomaState attr : attributes) {
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) {
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) {
@ -456,4 +457,29 @@ public abstract class SomfyTahomaBaseThingHandler extends BaseThingHandler {
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;
}
}

View File

@ -14,6 +14,7 @@ package org.openhab.binding.somfytahoma.internal.handler;
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.Thing;
/**
@ -22,6 +23,7 @@ import org.openhab.core.thing.Thing;
*
* @author Ondrej Pecta - Initial contribution
*/
@NonNullByDefault
public class SomfyTahomaElectricitySensorHandler extends SomfyTahomaBaseThingHandler {
public SomfyTahomaElectricitySensorHandler(Thing thing) {

View File

@ -14,8 +14,9 @@ package org.openhab.binding.somfytahoma.internal.handler;
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;
@ -47,10 +48,12 @@ public class SomfyTahomaValveHeatingSystemHandler extends SomfyTahomaBaseThingHa
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":

View File

@ -14,6 +14,8 @@ package org.openhab.binding.somfytahoma.internal.handler;
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;
@ -44,8 +46,11 @@ public class SomfyTahomaZwaveHeatingSystemHandler extends SomfyTahomaBaseThingHa
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);
}
}
}
}