From 904513268c31323d910176c355b58c5dadf1a652 Mon Sep 17 00:00:00 2001 From: jlaur Date: Thu, 30 Sep 2021 09:00:26 +0200 Subject: [PATCH] [miele] Fix supercool/superfreeze for fridges/fridge-freezers (#11321) * Fix typos. Signed-off-by: Jacob Laursen * Do not expose getTypeClass through interface. Signed-off-by: Jacob Laursen * Fix channel supercool for fridges and partially fix supercool/superfreeze for fridge-freezers. Fixes #11320 Signed-off-by: Jacob Laursen * Fix two-way channel synchronization for supercool/superfreeze for fridge-freezer. Signed-off-by: Jacob Laursen Signed-off-by: Nick Waterton --- .../internal/ExtendedDeviceStateUtil.java | 2 +- .../miele/internal/MieleBindingConstants.java | 9 +++++ .../handler/ApplianceChannelSelector.java | 6 ---- .../handler/ApplianceStatusListener.java | 4 +-- .../handler/CoffeeMachineChannelSelector.java | 5 --- .../handler/DishwasherChannelSelector.java | 5 --- .../handler/FridgeChannelSelector.java | 9 ++--- .../handler/FridgeFreezerChannelSelector.java | 12 +++---- .../handler/FridgeFreezerHandler.java | 36 +++++++++++++++++-- .../miele/internal/handler/FridgeHandler.java | 22 ++++++++++-- .../internal/handler/HobChannelSelector.java | 5 --- .../internal/handler/HoodChannelSelector.java | 5 --- .../handler/MieleApplianceHandler.java | 2 +- .../internal/handler/MieleBridgeHandler.java | 6 ++-- .../internal/handler/OvenChannelSelector.java | 5 --- .../handler/TumbleDryerChannelSelector.java | 5 --- .../WashingMachineChannelSelector.java | 5 --- .../resources/OH-INF/thing/channeltypes.xml | 8 ++--- 18 files changed, 80 insertions(+), 71 deletions(-) diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/ExtendedDeviceStateUtil.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/ExtendedDeviceStateUtil.java index 409c9fe23e4d7..f8c1692243ba0 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/ExtendedDeviceStateUtil.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/ExtendedDeviceStateUtil.java @@ -39,7 +39,7 @@ public static String bytesToHex(byte[] bytes) { /** * Convert string consisting of 8 bit characters to byte array. - * Note: This simple operation has been extracted and pure here to document + * Note: This simple operation has been extracted and put here to document * and ensure correct behavior for 8 bit characters that should be turned * into single bytes without any UTF-8 encoding. */ diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/MieleBindingConstants.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/MieleBindingConstants.java index 1c306cd9ee84d..97af65635dbfa 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/MieleBindingConstants.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/MieleBindingConstants.java @@ -32,8 +32,11 @@ public class MieleBindingConstants { public static final String PROTOCOL_PROPERTY_NAME = "protocol"; public static final String SERIAL_NUMBER_PROPERTY_NAME = "serialNumber"; public static final String EXTENDED_DEVICE_STATE_PROPERTY_NAME = "extendedDeviceState"; + public static final String STATE_PROPERTY_NAME = "state"; // Shared Channel ID's + public static final String SUPERCOOL_CHANNEL_ID = "supercool"; + public static final String SUPERFREEZE_CHANNEL_ID = "superfreeze"; public static final String POWER_CONSUMPTION_CHANNEL_ID = "powerConsumption"; public static final String WATER_CONSUMPTION_CHANNEL_ID = "waterConsumption"; @@ -51,6 +54,12 @@ public class MieleBindingConstants { // Miele devices classes public static final String MIELE_DEVICE_CLASS_COFFEE_SYSTEM = "CoffeeSystem"; + public static final String MIELE_DEVICE_CLASS_FRIDGE = "Fridge"; + public static final String MIELE_DEVICE_CLASS_FRIDGE_FREEZER = "FridgeFreezer"; + + // Miele appliance states + public static final int STATE_SUPER_FREEZING = 13; + public static final int STATE_SUPER_COOLING = 14; // Bridge config properties public static final String HOST = "ipAddress"; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/ApplianceChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/ApplianceChannelSelector.java index 260449f3b0ade..23b9fae8fc240 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/ApplianceChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/ApplianceChannelSelector.java @@ -14,7 +14,6 @@ import org.openhab.binding.miele.internal.handler.MieleBridgeHandler.DeviceMetaData; import org.openhab.core.types.State; -import org.openhab.core.types.Type; /** * The {@link ApplianceChannelSelector} class defines a common interface for @@ -62,9 +61,4 @@ public interface ApplianceChannelSelector { * @param dmd - the device meta data */ State getState(String s, DeviceMetaData dmd); - - /** - * Returns "compatible" Type for this datapoint - */ - Class getTypeClass(); } diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/ApplianceStatusListener.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/ApplianceStatusListener.java index 769417bf60cd6..9573812405df5 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/ApplianceStatusListener.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/ApplianceStatusListener.java @@ -52,14 +52,14 @@ public interface ApplianceStatusListener { void onAppliancePropertyChanged(String serialNumber, DeviceProperty dp); /** - * This method us called whenever an appliance is removed. + * This method is called whenever an appliance is removed. * * @param appliance The XGW homedevice definition of the appliance that was removed */ void onApplianceRemoved(HomeDevice appliance); /** - * This method us called whenever an appliance is added. + * This method is called whenever an appliance is added. * * @param appliance The XGW homedevice definition of the appliance that was removed */ diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/CoffeeMachineChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/CoffeeMachineChannelSelector.java index 2395f847091e8..44b0bf3bbd342 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/CoffeeMachineChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/CoffeeMachineChannelSelector.java @@ -89,11 +89,6 @@ public String getChannelID() { return channelID; } - @Override - public Class getTypeClass() { - return typeClass; - } - @Override public boolean isProperty() { return isProperty; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/DishwasherChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/DishwasherChannelSelector.java index d9b227bc00f41..a8c819a025c82 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/DishwasherChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/DishwasherChannelSelector.java @@ -160,11 +160,6 @@ public String getChannelID() { return channelID; } - @Override - public Class getTypeClass() { - return typeClass; - } - @Override public boolean isProperty() { return isProperty; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeChannelSelector.java index ceb8706356b36..5efdd859d9078 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeChannelSelector.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.miele.internal.handler; +import static org.openhab.binding.miele.internal.MieleBindingConstants.SUPERCOOL_CHANNEL_ID; + import java.lang.reflect.Method; import java.util.Map.Entry; @@ -40,7 +42,7 @@ public enum FridgeChannelSelector implements ApplianceChannelSelector { BRAND_ID("brandId", "brandId", StringType.class, true), COMPANY_ID("companyId", "companyId", StringType.class, true), STATE("state", "state", StringType.class, false), - SUPERCOOL(null, "supercool", OnOffType.class, false), + SUPERCOOL(null, SUPERCOOL_CHANNEL_ID, OnOffType.class, false), FRIDGECURRENTTEMP("currentTemperature", "current", DecimalType.class, false) { @Override public State getState(String s, DeviceMetaData dmd) { @@ -99,11 +101,6 @@ public String getChannelID() { return channelID; } - @Override - public Class getTypeClass() { - return typeClass; - } - @Override public boolean isProperty() { return isProperty; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeFreezerChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeFreezerChannelSelector.java index c2dbd7417cf28..26a32701408b1 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeFreezerChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeFreezerChannelSelector.java @@ -12,6 +12,9 @@ */ package org.openhab.binding.miele.internal.handler; +import static org.openhab.binding.miele.internal.MieleBindingConstants.SUPERCOOL_CHANNEL_ID; +import static org.openhab.binding.miele.internal.MieleBindingConstants.SUPERFREEZE_CHANNEL_ID; + import java.lang.reflect.Method; import java.util.Map.Entry; @@ -43,8 +46,8 @@ public enum FridgeFreezerChannelSelector implements ApplianceChannelSelector { STATE("state", "state", StringType.class, false), FREEZERSTATE("freezerState", "freezerstate", StringType.class, false), FRIDGESTATE("fridgeState", "fridgestate", StringType.class, false), - SUPERCOOL(null, "supercool", OnOffType.class, false), - SUPERFREEZE(null, "superfreeze", OnOffType.class, false), + SUPERCOOL(null, SUPERCOOL_CHANNEL_ID, OnOffType.class, false), + SUPERFREEZE(null, SUPERFREEZE_CHANNEL_ID, OnOffType.class, false), FREEZERCURRENTTEMP("freezerCurrentTemperature", "freezercurrent", DecimalType.class, false) { @Override public State getState(String s, DeviceMetaData dmd) { @@ -116,11 +119,6 @@ public String getChannelID() { return channelID; } - @Override - public Class getTypeClass() { - return typeClass; - } - @Override public boolean isProperty() { return isProperty; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeFreezerHandler.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeFreezerHandler.java index 24dd6f75980b3..a3f665cb684cc 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeFreezerHandler.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/FridgeFreezerHandler.java @@ -12,10 +12,10 @@ */ package org.openhab.binding.miele.internal.handler; -import static org.openhab.binding.miele.internal.MieleBindingConstants.APPLIANCE_ID; -import static org.openhab.binding.miele.internal.MieleBindingConstants.PROTOCOL_PROPERTY_NAME; +import static org.openhab.binding.miele.internal.MieleBindingConstants.*; import org.openhab.binding.miele.internal.FullyQualifiedApplianceIdentifier; +import org.openhab.binding.miele.internal.handler.MieleBridgeHandler.DeviceProperty; import org.openhab.core.library.types.OnOffType; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; @@ -39,7 +39,7 @@ public class FridgeFreezerHandler extends MieleApplianceHandler private final Logger logger = LoggerFactory.getLogger(FridgeHandler.class); public FridgeHandler(Thing thing) { - super(thing, FridgeChannelSelector.class, "Fridge"); + super(thing, FridgeChannelSelector.class, MIELE_DEVICE_CLASS_FRIDGE); } @Override @@ -89,4 +90,19 @@ public void handleCommand(ChannelUID channelUID, Command command) { channelID, command.toString()); } } + + @Override + protected void onAppliancePropertyChanged(DeviceProperty dp) { + super.onAppliancePropertyChanged(dp); + + if (!dp.Name.equals(STATE_PROPERTY_NAME)) { + return; + } + + // Supercool is not exposed directly as property, but can be deduced from state. + ChannelUID channelUid = new ChannelUID(getThing().getUID(), SUPERCOOL_CHANNEL_ID); + State state = dp.Value.equals(String.valueOf(STATE_SUPER_COOLING)) ? OnOffType.ON : OnOffType.OFF; + logger.trace("Update state of {} to {} through '{}'", channelUid, state, dp.Name); + updateState(channelUid, state); + } } diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/HobChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/HobChannelSelector.java index d588c9b11bb40..4c6f102162564 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/HobChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/HobChannelSelector.java @@ -119,11 +119,6 @@ public String getChannelID() { return channelID; } - @Override - public Class getTypeClass() { - return typeClass; - } - @Override public boolean isProperty() { return isProperty; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/HoodChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/HoodChannelSelector.java index c36f85711b94a..0c99dc5caffee 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/HoodChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/HoodChannelSelector.java @@ -86,11 +86,6 @@ public String getChannelID() { return channelID; } - @Override - public Class getTypeClass() { - return typeClass; - } - @Override public boolean isProperty() { return isProperty; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/MieleApplianceHandler.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/MieleApplianceHandler.java index b743d9864a910..9b7082433fe1b 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/MieleApplianceHandler.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/MieleApplianceHandler.java @@ -192,7 +192,7 @@ public void onAppliancePropertyChanged(FullyQualifiedApplianceIdentifier applica this.onAppliancePropertyChanged(dp); } - private void onAppliancePropertyChanged(DeviceProperty dp) { + protected void onAppliancePropertyChanged(DeviceProperty dp) { try { DeviceMetaData dmd = null; if (dp.Metadata == null) { diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/MieleBridgeHandler.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/MieleBridgeHandler.java index d40c19cf9c482..9f88b5f0075c4 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/MieleBridgeHandler.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/MieleBridgeHandler.java @@ -281,7 +281,7 @@ public void run() { listener.onApplianceStateChanged(applianceIdentifier, dco); } } catch (Exception e) { - logger.debug("An exception occurred while quering an appliance : '{}'", + logger.debug("An exception occurred while querying an appliance : '{}'", e.getMessage()); } } @@ -387,7 +387,7 @@ public List getHomeDevices() { break; } case "value": { - dp.Value = subparts[1]; + dp.Value = StringUtils.trim(StringUtils.strip(subparts[1])); break; } case "id": { @@ -600,7 +600,7 @@ public void onConnectionLost() { /** * This method is called whenever the connection to the given {@link MieleBridge} is resumed. * - * @param bridge the hue bridge the connection is resumed to + * @param bridge the Miele bridge the connection is resumed to */ public void onConnectionResumed() { updateStatus(ThingStatus.ONLINE); diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/OvenChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/OvenChannelSelector.java index 5749b303bc4c5..bf93d57e51566 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/OvenChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/OvenChannelSelector.java @@ -175,11 +175,6 @@ public String getChannelID() { return channelID; } - @Override - public Class getTypeClass() { - return typeClass; - } - @Override public boolean isProperty() { return isProperty; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/TumbleDryerChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/TumbleDryerChannelSelector.java index e6b2b5e2c0856..eec05044510cd 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/TumbleDryerChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/TumbleDryerChannelSelector.java @@ -157,11 +157,6 @@ public String getChannelID() { return channelID; } - @Override - public Class getTypeClass() { - return typeClass; - } - @Override public boolean isProperty() { return isProperty; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineChannelSelector.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineChannelSelector.java index d54c19236b91e..18b50e4f7cf40 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineChannelSelector.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineChannelSelector.java @@ -182,11 +182,6 @@ public String getChannelID() { return channelID; } - @Override - public Class getTypeClass() { - return typeClass; - } - @Override public boolean isProperty() { return isProperty; diff --git a/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/thing/channeltypes.xml b/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/thing/channeltypes.xml index 38b136e7dbe6a..72721267faf53 100644 --- a/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/thing/channeltypes.xml +++ b/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/thing/channeltypes.xml @@ -108,10 +108,10 @@ - String + Switch Start Super Cooling - + @@ -136,10 +136,10 @@ - String + Switch Start Super Freezing - +