mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[insteon] Add led brightness on level channel parameter (#17987)
Signed-off-by: jsetton <jeremy.setton@gmail.com>
This commit is contained in:
parent
bbdf3e3479
commit
24f4fc3d70
@ -532,7 +532,6 @@ public abstract class CommandHandler extends BaseFeatureHandler {
|
||||
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
|
||||
@ -1403,7 +1402,6 @@ public abstract class CommandHandler extends BaseFeatureHandler {
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.warn("{}: got unexpected alert type command: {}, ignoring request", nm(), cmd);
|
||||
return -1;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1412,6 +1410,8 @@ public abstract class CommandHandler extends BaseFeatureHandler {
|
||||
* LED brightness command handler
|
||||
*/
|
||||
public static class LEDBrightnessCommandHandler extends CommandHandler {
|
||||
private static final int DEFAULT_ON_LEVEL = 50;
|
||||
|
||||
LEDBrightnessCommandHandler(DeviceFeature feature) {
|
||||
super(feature);
|
||||
}
|
||||
@ -1424,7 +1424,8 @@ public abstract class CommandHandler extends BaseFeatureHandler {
|
||||
@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
|
||||
@ -1439,6 +1440,8 @@ public abstract class CommandHandler extends BaseFeatureHandler {
|
||||
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());
|
||||
}
|
||||
@ -1449,14 +1452,22 @@ public abstract class CommandHandler extends BaseFeatureHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private int getLevel(Command cmd) {
|
||||
int level;
|
||||
if (cmd instanceof PercentType percent) {
|
||||
level = percent.intValue();
|
||||
} else {
|
||||
level = OnOffType.OFF.equals(cmd) ? 0 : 100;
|
||||
private int getLevel(PercentType percent) {
|
||||
return (int) Math.round(percent.intValue() * 127.0 / 100);
|
||||
}
|
||||
return (int) Math.round(level * 127.0 / 100);
|
||||
|
||||
private PercentType getState(InsteonChannelConfiguration config, Command cmd) {
|
||||
if (cmd instanceof PercentType percent) {
|
||||
return percent;
|
||||
}
|
||||
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) {
|
||||
@ -2291,7 +2302,6 @@ public abstract class CommandHandler extends BaseFeatureHandler {
|
||||
* 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) {
|
||||
|
@ -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>
|
||||
|
@ -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.
|
||||
|
@ -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">
|
||||
|
@ -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 -->
|
||||
|
Loading…
Reference in New Issue
Block a user