From c5b65f4dded5720f985f5b860d31ce290c1af2c2 Mon Sep 17 00:00:00 2001 From: jlaur Date: Sat, 25 Sep 2021 16:50:24 +0200 Subject: [PATCH] Fix coffee machine auto-discovery. (#11302) Fixes #8779 Signed-off-by: Jacob Laursen --- .../miele/internal/MieleBindingConstants.java | 3 +++ .../MieleApplianceDiscoveryService.java | 24 +++++++++++++++---- .../handler/CoffeeMachineHandler.java | 3 ++- 3 files changed, 24 insertions(+), 6 deletions(-) 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 b435fc7c723df..df74fceaa225f 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 @@ -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"; diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/discovery/MieleApplianceDiscoveryService.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/discovery/MieleApplianceDiscoveryService.java index 703c5549b5439..e604686cbe4b5 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/discovery/MieleApplianceDiscoveryService.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/discovery/MieleApplianceDiscoveryService.java @@ -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()); @@ -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); + } } diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/CoffeeMachineHandler.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/CoffeeMachineHandler.java index 0b0cbc34c3b06..2b5083d362120 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/CoffeeMachineHandler.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/CoffeeMachineHandler.java @@ -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; @@ -39,7 +40,7 @@ public class CoffeeMachineHandler extends MieleApplianceHandler