Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[miele] Temperature channel improvements: UoM, categories and descriptions #11329

Merged
merged 12 commits into from
Oct 2, 2021
Merged
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
/bundles/org.openhab.binding.meteoalerte/ @clinique
/bundles/org.openhab.binding.meteoblue/ @9037568
/bundles/org.openhab.binding.meteostick/ @cdjackson
/bundles/org.openhab.binding.miele/ @kgoderis
/bundles/org.openhab.binding.miele/ @kgoderis @jlaur
/bundles/org.openhab.binding.mielecloud/ @BjoernLange
/bundles/org.openhab.binding.mihome/ @pboos
/bundles/org.openhab.binding.miio/ @marcelrv
Expand Down
4 changes: 2 additions & 2 deletions bundles/org.openhab.binding.miele/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ demo.items:
```
String MieleFridgeState (gMiele,gMieleFridge) {channel="miele:fridge:dilbeek:fridge:state"}
Switch MieleFridgeSuperCool (gMiele,gMieleFridge) {channel="miele:fridge:dilbeek:fridge:supercool"}
Number MieleFridgeCurrent (gMiele,gMieleFridge) {channel="miele:fridge:dilbeek:fridge:current"}
Number MieleFridgeTarget (gMiele,gMieleFridge) {channel="miele:fridge:dilbeek:fridge:target"}
Number:Temperature MieleFridgeCurrent (gMiele,gMieleFridge) {channel="miele:fridge:dilbeek:fridge:current"}
Number:Temperature MieleFridgeTarget (gMiele,gMieleFridge) {channel="miele:fridge:dilbeek:fridge:target"}
Contact MieleFridgeDoor (gMiele,gMieleFridge) {channel="miele:fridge:dilbeek:fridge:door"}
Switch MieleFridgeStart (gMiele,gMieleFridge) {channel="miele:fridge:dilbeek:fridge:start"}
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

import java.nio.charset.StandardCharsets;

import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;

/**
* The {@link ExtendedDeviceStateUtil} class contains utility methods for parsing
* ExtendedDeviceState information
Expand All @@ -22,6 +27,7 @@
*/
public class ExtendedDeviceStateUtil {
private static final byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII);
private static final String TEMPERATURE_UNDEFINED = "32768";

/**
* Convert byte array to hex representation.
Expand All @@ -46,4 +52,15 @@ public static String bytesToHex(byte[] bytes) {
public static byte[] stringToBytes(String input) {
return input.getBytes(StandardCharsets.ISO_8859_1);
}

/**
* Convert string to Number:Temperature state with unit Celcius
*/
public static State getTemperatureState(String s) throws NumberFormatException {
if (TEMPERATURE_UNDEFINED.equals(s)) {
return UnDefType.UNDEF;
}
int temperature = Integer.parseInt(s);
return new QuantityType<>(temperature, SIUnits.CELSIUS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,24 @@ public class MieleBindingConstants {
public static final String MIELE_DEVICE_CLASS_FRIDGE_FREEZER = "FridgeFreezer";

// Miele appliance states
public static final int STATE_UNKNOWN = 0;
public static final int STATE_OFF = 1;
public static final int STATE_STAND_BY = 2;
public static final int STATE_PROGRAMMED = 3;
public static final int STATE_WAITING_TO_START = 4;
public static final int STATE_RUNNING = 5;
public static final int STATE_PAUSED = 6;
public static final int STATE_END = 7;
public static final int STATE_FAILURE = 8;
public static final int STATE_ABORT = 9;
public static final int STATE_IDLE = 10;
public static final int STATE_RINSE_HOLD = 11;
public static final int STATE_SERVICE = 12;
public static final int STATE_SUPER_FREEZING = 13;
public static final int STATE_SUPER_COOLING = 14;
public static final int STATE_SUPER_HEATING = 15;
public static final int STATE_LOCKED = 145;
public static final int STATE_NOT_CONNECTED = 255;

// Bridge config properties
public static final String HOST = "ipAddress";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
import java.lang.reflect.Method;
import java.util.Map.Entry;

import org.openhab.binding.miele.internal.ExtendedDeviceStateUtil;
import org.openhab.binding.miele.internal.handler.MieleBridgeHandler.DeviceMetaData;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.types.State;
import org.openhab.core.types.Type;
Expand All @@ -43,16 +44,16 @@ public enum FridgeChannelSelector implements ApplianceChannelSelector {
COMPANY_ID("companyId", "companyId", StringType.class, true),
STATE("state", "state", StringType.class, false),
SUPERCOOL(null, SUPERCOOL_CHANNEL_ID, OnOffType.class, false),
FRIDGECURRENTTEMP("currentTemperature", "current", DecimalType.class, false) {
FRIDGECURRENTTEMP("currentTemperature", "current", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
FRIDGETARGETTEMP("targetTemperature", "target", DecimalType.class, false) {
FRIDGETARGETTEMP("targetTemperature", "target", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
DOOR("signalDoor", "door", OpenClosedType.class, false) {
Expand Down Expand Up @@ -142,6 +143,15 @@ public State getState(String s) {
return null;
}

public State getTemperatureState(String s) {
try {
return ExtendedDeviceStateUtil.getTemperatureState(s);
} catch (NumberFormatException e) {
logger.warn("An exception occurred while converting '{}' into a State", s);
return UnDefType.UNDEF;
}
}

public String getMieleEnum(String s, DeviceMetaData dmd) {
if (dmd.MieleEnum != null) {
for (Entry<String, JsonElement> enumEntry : dmd.MieleEnum.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import java.lang.reflect.Method;
import java.util.Map.Entry;

import org.openhab.binding.miele.internal.ExtendedDeviceStateUtil;
import org.openhab.binding.miele.internal.handler.MieleBridgeHandler.DeviceMetaData;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.types.State;
import org.openhab.core.types.Type;
Expand All @@ -48,28 +49,28 @@ public enum FridgeFreezerChannelSelector implements ApplianceChannelSelector {
FRIDGESTATE("fridgeState", "fridgestate", StringType.class, false),
SUPERCOOL(null, SUPERCOOL_CHANNEL_ID, OnOffType.class, false),
SUPERFREEZE(null, SUPERFREEZE_CHANNEL_ID, OnOffType.class, false),
FREEZERCURRENTTEMP("freezerCurrentTemperature", "freezercurrent", DecimalType.class, false) {
FREEZERCURRENTTEMP("freezerCurrentTemperature", "freezercurrent", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
FREEZERTARGETTEMP("freezerTargetTemperature", "freezertarget", DecimalType.class, false) {
FREEZERTARGETTEMP("freezerTargetTemperature", "freezertarget", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
FRIDGECURRENTTEMP("fridgeCurrentTemperature", "fridgecurrent", DecimalType.class, false) {
FRIDGECURRENTTEMP("fridgeCurrentTemperature", "fridgecurrent", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
FRIDGETARGETTEMP("fridgeTargetTemperature", "fridgetarget", DecimalType.class, false) {
FRIDGETARGETTEMP("fridgeTargetTemperature", "fridgetarget", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
DOOR("signalDoor", "door", OpenClosedType.class, false) {
Expand Down Expand Up @@ -160,6 +161,15 @@ public State getState(String s) {
return null;
}

public State getTemperatureState(String s) {
try {
return ExtendedDeviceStateUtil.getTemperatureState(s);
} catch (NumberFormatException e) {
logger.warn("An exception occurred while converting '{}' into a State", s);
return UnDefType.UNDEF;
}
}

public String getMieleEnum(String s, DeviceMetaData dmd) {
if (dmd.MieleEnum != null) {
for (Entry<String, JsonElement> enumEntry : dmd.MieleEnum.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import java.util.Map.Entry;
import java.util.TimeZone;

import org.openhab.binding.miele.internal.ExtendedDeviceStateUtil;
import org.openhab.binding.miele.internal.handler.MieleBridgeHandler.DeviceMetaData;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.types.State;
import org.openhab.core.types.Type;
Expand Down Expand Up @@ -104,28 +105,28 @@ public State getState(String s, DeviceMetaData dmd) {
return getState(dateFormatter.format(date));
}
},
TARGET_TEMP("targetTemperature", "target", DecimalType.class, false) {
TARGET_TEMP("targetTemperature", "target", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
MEASURED_TEMP("measuredTemperature", "measured", DecimalType.class, false) {
MEASURED_TEMP("measuredTemperature", "measured", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
DEVICE_TEMP_ONE("deviceTemperature1", "temp1", DecimalType.class, false) {
DEVICE_TEMP_ONE("deviceTemperature1", "temp1", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
DEVICE_TEMP_TWO("deviceTemperature2", "temp2", DecimalType.class, false) {
DEVICE_TEMP_TWO("deviceTemperature2", "temp2", QuantityType.class, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
DOOR("signalDoor", "door", OpenClosedType.class, false) {
Expand Down Expand Up @@ -216,6 +217,15 @@ public State getState(String s) {
return null;
}

public State getTemperatureState(String s) {
try {
return ExtendedDeviceStateUtil.getTemperatureState(s);
} catch (NumberFormatException e) {
logger.warn("An exception occurred while converting '{}' into a State", s);
return UnDefType.UNDEF;
}
}

public String getMieleEnum(String s, DeviceMetaData dmd) {
if (dmd.MieleEnum != null) {
for (Entry<String, JsonElement> enumEntry : dmd.MieleEnum.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.TimeZone;

import org.apache.commons.lang3.StringUtils;
import org.openhab.binding.miele.internal.ExtendedDeviceStateUtil;
import org.openhab.binding.miele.internal.handler.MieleBridgeHandler.DeviceMetaData;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.library.types.QuantityType;
Expand Down Expand Up @@ -111,10 +111,10 @@ public State getState(String s, DeviceMetaData dmd) {
return getState(dateFormatter.format(date));
}
},
TARGET_TEMP("targetTemperature", "target", DecimalType.class, false, false) {
TARGET_TEMP("targetTemperature", "target", QuantityType.class, false, false) {
@Override
public State getState(String s, DeviceMetaData dmd) {
return getState(s);
return getTemperatureState(s);
}
},
SPINNING_SPEED("spinningSpeed", "spinningspeed", StringType.class, false, false) {
Expand All @@ -126,7 +126,7 @@ public State getState(String s, DeviceMetaData dmd) {
if ("256".equals(s)) {
return getState("Rinsing");
}
return getState(Integer.toString((Integer.valueOf(s) * 10)));
return getState(Integer.toString((Integer.valueOf(s))));
}
},
DOOR("signalDoor", "door", OpenClosedType.class, false, false) {
Expand Down Expand Up @@ -223,6 +223,15 @@ public State getState(String s) {
return null;
}

public State getTemperatureState(String s) {
try {
return ExtendedDeviceStateUtil.getTemperatureState(s);
} catch (NumberFormatException e) {
logger.warn("An exception occurred while converting '{}' into a State", s);
return UnDefType.UNDEF;
}
}

public String getMieleEnum(String s, DeviceMetaData dmd) {
if (dmd.MieleEnum != null) {
for (Entry<String, JsonElement> enumEntry : dmd.MieleEnum.entrySet()) {
Expand Down
Loading