Skip to content

Commit

Permalink
[tuya] Add dimmer reversed value support
Browse files Browse the repository at this point in the history
Signed-off-by: jsetton <jeremy.setton@gmail.com>
  • Loading branch information
jsetton committed Dec 23, 2023
1 parent d1ee7fd commit 076d0fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
<parameter name="max" type="integer">
<label>Maximum</label>
</parameter>
<parameter name="reversed" type="boolean">
<label>Reversed</label>
<description>Changes the direction of the scale (e.g. 0 becomes 100, 100 becomes 0).</description>
<default>false</default>
<advanced>true</advanced>
</parameter>
</config-description>
</channel-type>

Expand Down

0 comments on commit 076d0fb

Please sign in to comment.