Skip to content

Commit

Permalink
[miele] Fix supercool/superfreeze for fridges/fridge-freezers (openha…
Browse files Browse the repository at this point in the history
…b#11321)

* Fix typos.

Signed-off-by: Jacob Laursen <[email protected]>

* Do not expose getTypeClass through interface.

Signed-off-by: Jacob Laursen <[email protected]>

* Fix channel supercool for fridges and partially fix supercool/superfreeze for fridge-freezers.

Fixes openhab#11320

Signed-off-by: Jacob Laursen <[email protected]>

* Fix two-way channel synchronization for supercool/superfreeze for fridge-freezer.

Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur authored and thinkingstone committed Nov 7, 2021
1 parent 158330a commit d4a900f
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<? extends Type> getTypeClass();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ public String getChannelID() {
return channelID;
}

@Override
public Class<? extends Type> getTypeClass() {
return typeClass;
}

@Override
public boolean isProperty() {
return isProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ public String getChannelID() {
return channelID;
}

@Override
public Class<? extends Type> getTypeClass() {
return typeClass;
}

@Override
public boolean isProperty() {
return isProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -99,11 +101,6 @@ public String getChannelID() {
return channelID;
}

@Override
public Class<? extends Type> getTypeClass() {
return typeClass;
}

@Override
public boolean isProperty() {
return isProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -116,11 +119,6 @@ public String getChannelID() {
return channelID;
}

@Override
public Class<? extends Type> getTypeClass() {
return typeClass;
}

@Override
public boolean isProperty() {
return isProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,7 +39,7 @@ public class FridgeFreezerHandler extends MieleApplianceHandler<FridgeFreezerCha
private final Logger logger = LoggerFactory.getLogger(FridgeFreezerHandler.class);

public FridgeFreezerHandler(Thing thing) {
super(thing, FridgeFreezerChannelSelector.class, "FridgeFreezer");
super(thing, FridgeFreezerChannelSelector.class, MIELE_DEVICE_CLASS_FRIDGE_FREEZER);
}

@Override
Expand Down Expand Up @@ -89,4 +89,34 @@ 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/superfreeze is not exposed directly as property, but can be deduced from state.
OnOffType superCoolState, superFreezeState;
if (dp.Value.equals(String.valueOf(STATE_SUPER_COOLING))) {
superCoolState = OnOffType.ON;
superFreezeState = OnOffType.OFF;
} else if (dp.Value.equals(String.valueOf(STATE_SUPER_FREEZING))) {
superCoolState = OnOffType.OFF;
superFreezeState = OnOffType.ON;
} else {
superCoolState = OnOffType.OFF;
superFreezeState = OnOffType.OFF;
}

ChannelUID superCoolChannelUid = new ChannelUID(getThing().getUID(), SUPERCOOL_CHANNEL_ID);
logger.trace("Update state of {} to {} through '{}'", superCoolChannelUid, superCoolState, dp.Name);
updateState(superCoolChannelUid, superCoolState);

ChannelUID superFreezeChannelUid = new ChannelUID(getThing().getUID(), SUPERFREEZE_CHANNEL_ID);
logger.trace("Update state of {} to {} through '{}'", superFreezeChannelUid, superFreezeState, dp.Name);
updateState(superFreezeChannelUid, superFreezeState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
*/
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;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,7 +40,7 @@ public class FridgeHandler extends MieleApplianceHandler<FridgeChannelSelector>
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
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ public String getChannelID() {
return channelID;
}

@Override
public Class<? extends Type> getTypeClass() {
return typeClass;
}

@Override
public boolean isProperty() {
return isProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ public String getChannelID() {
return channelID;
}

@Override
public Class<? extends Type> getTypeClass() {
return typeClass;
}

@Override
public boolean isProperty() {
return isProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -387,7 +387,7 @@ public List<HomeDevice> getHomeDevices() {
break;
}
case "value": {
dp.Value = subparts[1];
dp.Value = StringUtils.trim(StringUtils.strip(subparts[1]));
break;
}
case "id": {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ public String getChannelID() {
return channelID;
}

@Override
public Class<? extends Type> getTypeClass() {
return typeClass;
}

@Override
public boolean isProperty() {
return isProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ public String getChannelID() {
return channelID;
}

@Override
public Class<? extends Type> getTypeClass() {
return typeClass;
}

@Override
public boolean isProperty() {
return isProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ public String getChannelID() {
return channelID;
}

@Override
public Class<? extends Type> getTypeClass() {
return typeClass;
}

@Override
public boolean isProperty() {
return isProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@
</channel-type>

<channel-type id="supercool" advanced="false">
<item-type>String</item-type>
<item-type>Switch</item-type>
<label>Super Cool</label>
<description>Start Super Cooling</description>
<state readOnly="true"></state>
<state readOnly="false"></state>
</channel-type>

<channel-type id="current" advanced="false">
Expand All @@ -136,10 +136,10 @@
</channel-type>

<channel-type id="superfreeze" advanced="false">
<item-type>String</item-type>
<item-type>Switch</item-type>
<label>Super Freeze</label>
<description>Start Super Freezing</description>
<state readOnly="true"></state>
<state readOnly="false"></state>
</channel-type>

<channel-type id="freezercurrent" advanced="false">
Expand Down

0 comments on commit d4a900f

Please sign in to comment.