Skip to content

Commit

Permalink
Fix coffee machine auto-discovery. (openhab#11302)
Browse files Browse the repository at this point in the history
Fixes openhab#8779

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
  • Loading branch information
jlaur authored and thinkingstone committed Nov 7, 2021
1 parent 656c340 commit e3dcc40
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class MieleBindingConstants {
public static final ThingTypeUID THING_TYPE_WASHINGMACHINE = new ThingTypeUID(BINDING_ID, "washingmachine");
public static final ThingTypeUID THING_TYPE_COFFEEMACHINE = new ThingTypeUID(BINDING_ID, "coffeemachine");

// Miele devices classes
public static final String MIELE_DEVICE_CLASS_COFFEE_SYSTEM = "CoffeeSystem";

// Bridge config properties
public static final String HOST = "ipAddress";
public static final String INTERFACE = "interface";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,18 @@ public void onAppliancePropertyChanged(String serialNumber, DeviceProperty dp) {

private ThingUID getThingUID(HomeDevice appliance) {
ThingUID bridgeUID = mieleBridgeHandler.getThing().getUID();
String modelID = null;
String modelId = null;

for (JsonElement dc : appliance.DeviceClasses) {
String dcStr = dc.getAsString();
if (dcStr.contains(MIELE_CLASS) && !dcStr.equals(MIELE_APPLIANCE_CLASS)) {
modelID = dcStr.substring(MIELE_CLASS.length());
modelId = dcStr.substring(MIELE_CLASS.length());
break;
}
}

if (modelID != null) {
ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID,
modelID.replaceAll("[^a-zA-Z0-9_]", "_").toLowerCase());
if (modelId != null) {
ThingTypeUID thingTypeUID = getThingTypeUidFromModelId(modelId);

if (getSupportedThingTypes().contains(thingTypeUID)) {
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, appliance.getApplianceIdentifier().getId());
Expand All @@ -177,4 +176,19 @@ private ThingUID getThingUID(HomeDevice appliance) {
return null;
}
}

private ThingTypeUID getThingTypeUidFromModelId(String modelId) {
/*
* Coffee machine CVA 6805 is reported as CoffeeSystem, but thing type is
* coffeemachine. At least until it is known if any models are actually reported
* as CoffeeMachine, we need this special mapping.
*/
if (modelId.equals(MIELE_DEVICE_CLASS_COFFEE_SYSTEM)) {
return THING_TYPE_COFFEEMACHINE;
}

String thingTypeId = modelId.replaceAll("[^a-zA-Z0-9_]", "_").toLowerCase();

return new ThingTypeUID(BINDING_ID, thingTypeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.MIELE_DEVICE_CLASS_COFFEE_SYSTEM;
import static org.openhab.binding.miele.internal.MieleBindingConstants.PROTOCOL_PROPERTY_NAME;

import org.openhab.binding.miele.internal.FullyQualifiedApplianceIdentifier;
Expand All @@ -39,7 +40,7 @@ public class CoffeeMachineHandler extends MieleApplianceHandler<CoffeeMachineCha
private final Logger logger = LoggerFactory.getLogger(CoffeeMachineHandler.class);

public CoffeeMachineHandler(Thing thing) {
super(thing, CoffeeMachineChannelSelector.class, "CoffeeSystem");
super(thing, CoffeeMachineChannelSelector.class, MIELE_DEVICE_CLASS_COFFEE_SYSTEM);
}

@Override
Expand Down

0 comments on commit e3dcc40

Please sign in to comment.