From 8d6ce024ef003e93d61679351f24bac8a20e6619 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 12 Mar 2024 22:35:33 +0100 Subject: [PATCH] Add laundry weight channel for washing machine (#16514) Signed-off-by: Jacob Laursen --- bundles/org.openhab.binding.miele/README.md | 1 + .../binding/miele/internal/MieleBindingConstants.java | 1 + .../internal/handler/WashingMachineChannelSelector.java | 3 ++- .../miele/internal/handler/WashingMachineHandler.java | 8 ++++++++ .../src/main/resources/OH-INF/i18n/miele.properties | 2 ++ .../src/main/resources/OH-INF/thing/channeltypes.xml | 7 +++++++ .../src/main/resources/OH-INF/thing/washingmachine.xml | 3 ++- .../src/main/resources/OH-INF/update/instructions.xml | 5 +++++ 8 files changed, 28 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.miele/README.md b/bundles/org.openhab.binding.miele/README.md index 4dabad4723..4100aa5dea 100644 --- a/bundles/org.openhab.binding.miele/README.md +++ b/bundles/org.openhab.binding.miele/README.md @@ -370,6 +370,7 @@ See oven. | spinningspeed | String | Read | Spinning speed in the program running on the appliance | | energyConsumption | Number:Energy | Read | Energy consumption by the currently running program on the appliance | | waterConsumption | Number:Volume | Read | Water consumption by the currently running program on the appliance | +| laundryWeight | Number:Mass | Read | Weight of the laundry inside the appliance | ##### Programs 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 6e2ca63271..43aaea984d 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 @@ -60,6 +60,7 @@ public class MieleBindingConstants { public static final String FINISH_CHANNEL_ID = "finish"; public static final String ENERGY_CONSUMPTION_CHANNEL_ID = "energyConsumption"; public static final String WATER_CONSUMPTION_CHANNEL_ID = "waterConsumption"; + public static final String LAUNDRY_WEIGHT_CHANNEL_ID = "laundryWeight"; // List of all Thing Type UIDs public static final ThingTypeUID THING_TYPE_XGW3000 = new ThingTypeUID(BINDING_ID, "xgw3000"); 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 b590e790fc..ff7b092abc 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 @@ -143,7 +143,8 @@ public enum WashingMachineChannelSelector implements ApplianceChannelSelector { ENERGY_CONSUMPTION(EXTENDED_DEVICE_STATE_PROPERTY_NAME, ENERGY_CONSUMPTION_CHANNEL_ID, QuantityType.class, false, true), WATER_CONSUMPTION(EXTENDED_DEVICE_STATE_PROPERTY_NAME, WATER_CONSUMPTION_CHANNEL_ID, QuantityType.class, false, - true); + true), + LAUNDRY_WEIGHT(EXTENDED_DEVICE_STATE_PROPERTY_NAME, LAUNDRY_WEIGHT_CHANNEL_ID, QuantityType.class, false, true); private final Logger logger = LoggerFactory.getLogger(WashingMachineChannelSelector.class); diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineHandler.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineHandler.java index 1100b9f8ac..e4e855f41e 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineHandler.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineHandler.java @@ -24,6 +24,7 @@ import org.openhab.core.i18n.TimeZoneProvider; import org.openhab.core.i18n.TranslationProvider; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.QuantityType; +import org.openhab.core.library.unit.SIUnits; import org.openhab.core.library.unit.Units; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; @@ -47,6 +48,7 @@ import com.google.gson.JsonElement; public class WashingMachineHandler extends MieleApplianceHandler implements ExtendedDeviceStateListener { + private static final int LAUNDRY_WEIGHT_BYTE_POSITION = 44; private static final int ENERGY_CONSUMPTION_BYTE_POSITION = 51; private static final int WATER_CONSUMPTION_BYTE_POSITION = 53; private static final int EXTENDED_STATE_MIN_SIZE_BYTES = 54; @@ -136,5 +138,11 @@ public class WashingMachineHandler extends MieleApplianceHandler(BigDecimal.valueOf(extendedDeviceState[WATER_CONSUMPTION_BYTE_POSITION] & 0xff), Units.LITRE); updateExtendedState(WATER_CONSUMPTION_CHANNEL_ID, litres); + + var weight = new QuantityType<>( + BigDecimal.valueOf(256 * (extendedDeviceState[LAUNDRY_WEIGHT_BYTE_POSITION] & 0xff) + + (extendedDeviceState[LAUNDRY_WEIGHT_BYTE_POSITION + 1] & 0xff)), + SIUnits.GRAM); + updateExtendedState(LAUNDRY_WEIGHT_CHANNEL_ID, weight); } } diff --git a/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/i18n/miele.properties b/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/i18n/miele.properties index bf5106ca86..598ff5392e 100644 --- a/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/i18n/miele.properties +++ b/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/i18n/miele.properties @@ -85,6 +85,8 @@ channel-type.miele.heat.label = Remaining Heat channel-type.miele.heat.description = Remaining heat level of the heating zone/plate channel-type.miele.info.label = Signal Information channel-type.miele.info.description = Signals information, check appliance for details +channel-type.miele.laundry-weight.label = Laundry Weight +channel-type.miele.laundry-weight.description = Weight of the laundry inside the appliance channel-type.miele.phase.label = Phase channel-type.miele.phase.description = Current phase of the program running on the appliance channel-type.miele.plates.label = Plates 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 5bfc1e0b02..2b871ca584 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 @@ -263,4 +263,11 @@ + + Number:Mass + + Weight of the laundry inside the appliance + + + diff --git a/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/thing/washingmachine.xml b/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/thing/washingmachine.xml index 1864491701..c34c88f64b 100644 --- a/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/thing/washingmachine.xml +++ b/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/thing/washingmachine.xml @@ -37,10 +37,11 @@ + - 2 + 3 uid diff --git a/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/update/instructions.xml b/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/update/instructions.xml index fdcf167635..c331c33144 100644 --- a/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/update/instructions.xml +++ b/bundles/org.openhab.binding.miele/src/main/resources/OH-INF/update/instructions.xml @@ -96,6 +96,11 @@ miele:failure + + + miele:laundry-weight + + -- 2.47.3