From 076d0fb58eb95fc33fd4ddd1998d9834e866c97d Mon Sep 17 00:00:00 2001 From: jsetton Date: Thu, 21 Dec 2023 01:16:57 -0500 Subject: [PATCH] [tuya] Add dimmer reversed value support Signed-off-by: jsetton --- .../tuya/internal/config/ChannelConfiguration.java | 1 + .../binding/tuya/internal/handler/TuyaDeviceHandler.java | 9 ++++++++- .../src/main/resources/OH-INF/thing/thing-types.xml | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/config/ChannelConfiguration.java b/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/config/ChannelConfiguration.java index 092d723211..38d4e9ef42 100644 --- a/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/config/ChannelConfiguration.java +++ b/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/config/ChannelConfiguration.java @@ -25,6 +25,7 @@ public class ChannelConfiguration { public int dp2 = 0; public int min = Integer.MIN_VALUE; public int max = Integer.MAX_VALUE; + public boolean reversed = false; public String range = ""; public String irCode = ""; public int irSendDelay = 300; diff --git a/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/handler/TuyaDeviceHandler.java b/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/handler/TuyaDeviceHandler.java index 5d4f39bfc4..8529f0a879 100644 --- a/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/handler/TuyaDeviceHandler.java +++ b/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/handler/TuyaDeviceHandler.java @@ -172,7 +172,11 @@ private void processChannelStatus(Integer dp, Object value) { return; } else if (Double.class.isAssignableFrom(value.getClass()) && CHANNEL_TYPE_UID_DIMMER.equals(channelTypeUID)) { - updateState(channelId, ConversionUtil.brightnessDecode((double) value, 0, configuration.max)); + double brightness = (double) value; + if (configuration.reversed) { + brightness = configuration.max - brightness; + } + updateState(channelId, ConversionUtil.brightnessDecode(brightness, 0, configuration.max)); return; } else if (Double.class.isAssignableFrom(value.getClass()) && CHANNEL_TYPE_UID_NUMBER.equals(channelTypeUID)) { @@ -300,6 +304,9 @@ public void handleCommand(ChannelUID channelUID, Command command) { } else if (CHANNEL_TYPE_UID_DIMMER.equals(channelTypeUID)) { if (command instanceof PercentType) { int value = ConversionUtil.brightnessEncode((PercentType) command, 0, configuration.max); + if (configuration.reversed) { + value = configuration.max - value; + } if (value >= configuration.min) { commandRequest.put(configuration.dp, value); } diff --git a/bundles/org.smarthomej.binding.tuya/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.smarthomej.binding.tuya/src/main/resources/OH-INF/thing/thing-types.xml index d295cb733b..37de3165e3 100644 --- a/bundles/org.smarthomej.binding.tuya/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.smarthomej.binding.tuya/src/main/resources/OH-INF/thing/thing-types.xml @@ -149,6 +149,12 @@ + + + Changes the direction of the scale (e.g. 0 becomes 100, 100 becomes 0). + false + true +