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

Signed-off-by: jsetton <jeremy.setton@gmail.com>
This commit is contained in:
Jeremy 2024-12-26 18:19:58 -05:00 committed by GitHub
parent bbdf3e3479
commit 24f4fc3d70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 11 deletions

View File

@ -532,7 +532,6 @@ public abstract class CommandHandler extends BaseFeatureHandler {
if (level == -1) { if (level == -1) {
State state = getInsteonDevice().getFeatureState(FEATURE_ON_LEVEL); State state = getInsteonDevice().getFeatureState(FEATURE_ON_LEVEL);
level = (state instanceof PercentType percent ? percent : PercentType.HUNDRED).intValue(); level = (state instanceof PercentType percent ? percent : PercentType.HUNDRED).intValue();
} }
logger.trace("{}: using on level {}%", nm(), level); logger.trace("{}: using on level {}%", nm(), level);
return (int) Math.ceil(level * 255.0 / 100); // round up return (int) Math.ceil(level * 255.0 / 100); // round up
@ -1403,7 +1402,6 @@ public abstract class CommandHandler extends BaseFeatureHandler {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.warn("{}: got unexpected alert type command: {}, ignoring request", nm(), cmd); logger.warn("{}: got unexpected alert type command: {}, ignoring request", nm(), cmd);
return -1; return -1;
} }
} }
} }
@ -1412,6 +1410,8 @@ public abstract class CommandHandler extends BaseFeatureHandler {
* LED brightness command handler * LED brightness command handler
*/ */
public static class LEDBrightnessCommandHandler extends CommandHandler { public static class LEDBrightnessCommandHandler extends CommandHandler {
private static final int DEFAULT_ON_LEVEL = 50;
LEDBrightnessCommandHandler(DeviceFeature feature) { LEDBrightnessCommandHandler(DeviceFeature feature) {
super(feature); super(feature);
} }
@ -1424,7 +1424,8 @@ public abstract class CommandHandler extends BaseFeatureHandler {
@Override @Override
public void handleCommand(InsteonChannelConfiguration config, Command cmd) { public void handleCommand(InsteonChannelConfiguration config, Command cmd) {
try { try {
int level = getLevel(cmd); PercentType state = getState(config, cmd);
int level = getLevel(state);
int userData2 = getParameterAsInteger("d2", -1); int userData2 = getParameterAsInteger("d2", -1);
if (userData2 != -1) { if (userData2 != -1) {
// set led on/off // set led on/off
@ -1439,6 +1440,8 @@ public abstract class CommandHandler extends BaseFeatureHandler {
logger.debug("{}: sent led brightness level {} request to {}", nm(), logger.debug("{}: sent led brightness level {} request to {}", nm(),
HexUtils.getHexString(level), address); HexUtils.getHexString(level), address);
} }
// update state since led brightness channel not automatically updated by the framework
feature.updateState(state);
} else { } else {
logger.warn("{}: no d2 parameter specified in command handler", nm()); logger.warn("{}: no d2 parameter specified in command handler", nm());
} }
@ -1449,14 +1452,22 @@ public abstract class CommandHandler extends BaseFeatureHandler {
} }
} }
private int getLevel(Command cmd) { private int getLevel(PercentType percent) {
int level; return (int) Math.round(percent.intValue() * 127.0 / 100);
}
private PercentType getState(InsteonChannelConfiguration config, Command cmd) {
if (cmd instanceof PercentType percent) { if (cmd instanceof PercentType percent) {
level = percent.intValue(); return percent;
} else {
level = OnOffType.OFF.equals(cmd) ? 0 : 100;
} }
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) { private void setLEDOnOff(InsteonChannelConfiguration config, Command cmd) {
@ -2291,7 +2302,6 @@ public abstract class CommandHandler extends BaseFeatureHandler {
* X10 percent command handler * X10 percent command handler
*/ */
public static class X10PercentCommandHandler extends X10CommandHandler { 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 }; 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) { X10PercentCommandHandler(DeviceFeature feature) {

View File

@ -32,5 +32,12 @@
</options> </options>
</parameter> </parameter>
</config-description> </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> </config-description:config-descriptions>

View File

@ -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.onLevel.description = Override the dimmer on level local setting.
channel-type.config.insteon.dimmer.rampRate.label = Ramp Rate 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.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.label = Related Devices
channel-type.config.insteon.legacy-button.related.description = List of related Insteon devices separated by a '+' sign. channel-type.config.insteon.legacy-button.related.description = List of related Insteon devices separated by a '+' sign.

View File

@ -332,6 +332,8 @@
<item-type>Dimmer</item-type> <item-type>Dimmer</item-type>
<label>LED Brightness Level</label> <label>LED Brightness Level</label>
<description>Set the device led(s) brightness level.</description> <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>
<channel-type id="led-on-off" advanced="true"> <channel-type id="led-on-off" advanced="true">

View File

@ -180,7 +180,6 @@
<message-handler command="0x19">TriggerPollMsgHandler</message-handler> <!-- poll after cmd request reply ack --> <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 command="0x2E" ext="1" cmd1="0x2E" cmd2="0x00" d2="0x01" field="userData8">CustomPercentMsgHandler</message-handler>
<message-handler default="true">NoOpMsgHandler</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="PercentType" ext="1" cmd1="0x2E" d2="0x06" field="userData3">CustomPercentCommandHandler</command-handler>
<command-handler command="RefreshType">RefreshCommandHandler</command-handler> <command-handler command="RefreshType">RefreshCommandHandler</command-handler>
<poll-handler>NoPollHandler</poll-handler> <!-- polled by ExtDataGroup --> <poll-handler>NoPollHandler</poll-handler> <!-- polled by ExtDataGroup -->