Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[insteon] Add led brightness on level channel parameter #17987

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ private int getOnLevel(InsteonChannelConfiguration config) {
if (level == -1) {
State state = getInsteonDevice().getFeatureState(FEATURE_ON_LEVEL);
level = (state instanceof PercentType percent ? percent : PercentType.HUNDRED).intValue();

}
logger.trace("{}: using on level {}%", nm(), level);
return (int) Math.ceil(level * 255.0 / 100); // round up
Expand Down Expand Up @@ -1403,7 +1402,6 @@ protected double getValue(Command cmd) {
} catch (IllegalArgumentException e) {
logger.warn("{}: got unexpected alert type command: {}, ignoring request", nm(), cmd);
return -1;

}
}
}
Expand All @@ -1412,6 +1410,8 @@ protected double getValue(Command cmd) {
* LED brightness command handler
*/
public static class LEDBrightnessCommandHandler extends CommandHandler {
private static final int DEFAULT_ON_LEVEL = 50;

LEDBrightnessCommandHandler(DeviceFeature feature) {
super(feature);
}
Expand All @@ -1424,7 +1424,8 @@ public boolean canHandle(Command cmd) {
@Override
public void handleCommand(InsteonChannelConfiguration config, Command cmd) {
try {
int level = getLevel(cmd);
PercentType state = getState(config, cmd);
int level = getLevel(state);
int userData2 = getParameterAsInteger("d2", -1);
if (userData2 != -1) {
// set led on/off
Expand All @@ -1439,6 +1440,8 @@ public void handleCommand(InsteonChannelConfiguration config, Command cmd) {
logger.debug("{}: sent led brightness level {} request to {}", nm(),
HexUtils.getHexString(level), address);
}
// update state since led brightness channel not automatically updated by the framework
feature.updateState(state);
} else {
logger.warn("{}: no d2 parameter specified in command handler", nm());
}
Expand All @@ -1449,14 +1452,22 @@ public void handleCommand(InsteonChannelConfiguration config, Command cmd) {
}
}

private int getLevel(Command cmd) {
int level;
private int getLevel(PercentType percent) {
return (int) Math.round(percent.intValue() * 127.0 / 100);
}

private PercentType getState(InsteonChannelConfiguration config, Command cmd) {
if (cmd instanceof PercentType percent) {
level = percent.intValue();
} else {
level = OnOffType.OFF.equals(cmd) ? 0 : 100;
return percent;
}
return (int) Math.round(level * 127.0 / 100);
if (OnOffType.OFF.equals(cmd)) {
return PercentType.ZERO;
}
int level = config.getOnLevel();
if (level == -1) {
level = DEFAULT_ON_LEVEL;
}
return new PercentType(level);
}

private void setLEDOnOff(InsteonChannelConfiguration config, Command cmd) {
Expand Down Expand Up @@ -2291,7 +2302,6 @@ protected int getCommandCode(Command cmd, byte houseCode) {
* X10 percent command handler
*/
public static class X10PercentCommandHandler extends X10CommandHandler {

private static final int[] X10_LEVEL_CODES = { 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 };

X10PercentCommandHandler(DeviceFeature feature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@
</options>
</parameter>
</config-description>
<config-description uri="channel-type:insteon:led-brightness">
<parameter name="onLevel" type="integer" min="0" max="100">
<label>On Level</label>
<description>LED brightness level to use when an ON command is received. Default to 50%.</description>
<default>50</default>
</parameter>
</config-description>

</config-description:config-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ channel-type.config.insteon.dimmer.onLevel.label = On Level
channel-type.config.insteon.dimmer.onLevel.description = Override the dimmer on level local setting.
channel-type.config.insteon.dimmer.rampRate.label = Ramp Rate
channel-type.config.insteon.dimmer.rampRate.description = Override the dimmer ramp rate local setting.
channel-type.config.insteon.led-brightness.onLevel.label = On Level
channel-type.config.insteon.led-brightness.onLevel.description = LED brightness level to use when an ON command is received. Default to 50%.

channel-type.config.insteon.legacy-button.related.label = Related Devices
channel-type.config.insteon.legacy-button.related.description = List of related Insteon devices separated by a '+' sign.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@
<item-type>Dimmer</item-type>
<label>LED Brightness Level</label>
<description>Set the device led(s) brightness level.</description>
<autoUpdatePolicy>veto</autoUpdatePolicy> <!-- binding controls state updates -->
<config-description-ref uri="channel-type:insteon:led-brightness"/>
</channel-type>

<channel-type id="led-on-off" advanced="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
<message-handler command="0x19">TriggerPollMsgHandler</message-handler> <!-- poll after cmd request reply ack -->
<message-handler command="0x2E" ext="1" cmd1="0x2E" cmd2="0x00" d2="0x01" field="userData8">CustomPercentMsgHandler</message-handler>
<message-handler default="true">NoOpMsgHandler</message-handler>
<command-handler command="OnOffType" ext="1" cmd1="0x2E" d2="0x06" field="userData3">CustomOnOffCommandHandler</command-handler>
<command-handler command="PercentType" ext="1" cmd1="0x2E" d2="0x06" field="userData3">CustomPercentCommandHandler</command-handler>
<command-handler command="RefreshType">RefreshCommandHandler</command-handler>
<poll-handler>NoPollHandler</poll-handler> <!-- polled by ExtDataGroup -->
Expand Down