Skip to content

Commit

Permalink
[tuya] Add dimmer inverted 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 21, 2023
1 parent d1ee7fd commit ad3b473
Show file tree
Hide file tree
Showing 3 changed files with 14 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 inverted = Boolean.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.inverted) {
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.inverted) {
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,11 @@
<parameter name="max" type="integer">
<label>Maximum</label>
</parameter>
<parameter name="inverted" type="boolean">
<label>Inverted</label>
<default>false</default>
<advanced>true</advanced>
</parameter>
</config-description>
</channel-type>

Expand Down

0 comments on commit ad3b473

Please sign in to comment.