diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/feature/CommandHandler.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/feature/CommandHandler.java index 4fbb396a79f..bd13c8de15f 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/feature/CommandHandler.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/feature/CommandHandler.java @@ -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; + 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) { @@ -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) { diff --git a/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/config/config.xml index f693176a3b5..8a2b77c0a1f 100644 --- a/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/config/config.xml @@ -32,5 +32,12 @@ + + + + LED brightness level to use when an ON command is received. Default to 50%. + 50 + + diff --git a/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/i18n/insteon.properties b/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/i18n/insteon.properties index 50fd41aee42..4288c388653 100644 --- a/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/i18n/insteon.properties +++ b/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/i18n/insteon.properties @@ -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. diff --git a/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/thing/channels.xml index 5d705322e4f..a46a745d4b1 100644 --- a/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.insteon/src/main/resources/OH-INF/thing/channels.xml @@ -332,6 +332,8 @@ Dimmer Set the device led(s) brightness level. + veto + diff --git a/bundles/org.openhab.binding.insteon/src/main/resources/device-features.xml b/bundles/org.openhab.binding.insteon/src/main/resources/device-features.xml index 9a8e5055f69..332a95b57bb 100644 --- a/bundles/org.openhab.binding.insteon/src/main/resources/device-features.xml +++ b/bundles/org.openhab.binding.insteon/src/main/resources/device-features.xml @@ -180,7 +180,6 @@ TriggerPollMsgHandler CustomPercentMsgHandler NoOpMsgHandler - CustomOnOffCommandHandler CustomPercentCommandHandler RefreshCommandHandler NoPollHandler