# HG changeset patch # User William Welliver # Date 1633990235 14400 # Mon Oct 11 18:10:35 2021 -0400 # Node ID e28bfb5f4b626465570d9ca05d5d6916ce67dd3a # Parent 8f2bacd44c9a609138c74b92caf66a93a30d8ab7 report shade levels according to openhab standards (ie, inverted from lutron's) diff --git a/pom.xml b/pom.xml --- a/pom.xml +++ b/pom.xml @@ -7,11 +7,11 @@ org.openhab.addons.bundles org.openhab.addons.reactor.bundles - 3.0.1 + 3.1.0 ../openhab-addons/bundles - 3.0.2-SNAPSHOT + 3.1.0 org.openhab.binding.lutronmqtt openHAB Add-ons :: Bundles :: Lutron-MQTT Binding diff --git a/src/main/history/dependencies.xml b/src/main/history/dependencies.xml --- a/src/main/history/dependencies.xml +++ b/src/main/history/dependencies.xml @@ -1,10 +1,10 @@ - + openhab-runtime-base openhab-transport-mqtt wrap - mvn:org.openhab.addons.bundles/org.openhab.binding.lutronmqtt/3.0.2-SNAPSHOT + mvn:org.openhab.addons.bundles/org.openhab.binding.lutronmqtt/3.1.0 wrap:mvn:org.lastnpe.eea/eea-all/2.2.1 diff --git a/src/main/java/org/openhab/binding/lutronmqtt/handler/LightStateConverter.java b/src/main/java/org/openhab/binding/lutronmqtt/handler/LightStateConverter.java --- a/src/main/java/org/openhab/binding/lutronmqtt/handler/LightStateConverter.java +++ b/src/main/java/org/openhab/binding/lutronmqtt/handler/LightStateConverter.java @@ -41,14 +41,16 @@ * on or off state * @return light state containing the 'on' value */ - public static int toOnOffLightState(OnOffType onOffType) { + public static int toOnOffLightState(OnOffType onOffType, boolean inverted) { int f = 0; if (onOffType == OnOffType.ON) f = 65535; + if (inverted) + f = 65535 - f; return f; } - public static int toPercentLightState(PercentType percentType) { + public static int toPercentLightState(PercentType percentType, boolean inverted) { int f = 0; if (PercentType.ZERO.equals(percentType)) f = 0; @@ -57,11 +59,13 @@ else { f = (int) Math.round(percentType.floatValue() * 65535 / 100); } + if (inverted) + f = 65535 - f; return f; } - public static Map toLightState(OnOffType onOffType, LutronDevice device) { - int level = toOnOffLightState(onOffType); + public static Map toLightState(OnOffType onOffType, LutronDevice device, boolean inverted) { + int level = toOnOffLightState(onOffType, inverted); Map m = makeGoToLevelCommand(level, device); return m; } @@ -89,24 +93,25 @@ * brightness represented as {@link PercentType} * @return light state containing the brightness and the 'on' value */ - public static Map toLightState(PercentType percentType, LutronDevice device) { - int level = toPercentLightState(percentType); + public static Map toLightState(PercentType percentType, LutronDevice device, boolean inverted) { + int level = toPercentLightState(percentType, inverted); Map m = makeGoToLevelCommand(level, device); return m; } - public static Map toLightState(IncreaseDecreaseType increaseDecreaseType, LutronDevice device) { - int level = toAdjustedBrightness(increaseDecreaseType, device.getProperty(LUTRON_PROPERTY_LEVEL)); + public static Map toLightState(IncreaseDecreaseType increaseDecreaseType, LutronDevice device, + boolean inverted) { + int level = toAdjustedBrightness(increaseDecreaseType, device.getProperty(LUTRON_PROPERTY_LEVEL), inverted); Map m = makeGoToLevelCommand(level, device); return m; } - public static Map toLightState(UpDownType upDownType, LutronDevice device) { - int level = toAdjustedBrightness(upDownType, device.getProperty(LUTRON_PROPERTY_LEVEL)); + public static Map toLightState(UpDownType upDownType, LutronDevice device, boolean inverted) { + int level = toAdjustedBrightness(upDownType, device.getProperty(LUTRON_PROPERTY_LEVEL), inverted); Map m = makeGoToLevelCommand(level, device); @@ -123,13 +128,15 @@ * The current brightness * @return The adjusted brightness value */ - public static int toAdjustedBrightness(IncreaseDecreaseType command, int currentBrightness) { + public static int toAdjustedBrightness(IncreaseDecreaseType command, int currentBrightness, boolean inverted) { int newBrightness; if (command == IncreaseDecreaseType.DECREASE) { newBrightness = Math.max(currentBrightness - DIM_STEPSIZE, 0); } else { newBrightness = Math.min(currentBrightness + DIM_STEPSIZE, 65535); } + if (inverted) + newBrightness = 65535 - newBrightness; return newBrightness; } @@ -143,13 +150,16 @@ * The current brightness * @return The adjusted brightness value */ - public static int toAdjustedBrightness(UpDownType command, int currentBrightness) { + public static int toAdjustedBrightness(UpDownType command, int currentBrightness, boolean inverted) { int newBrightness; if (command == UpDownType.DOWN) { newBrightness = Math.max(currentBrightness - DIM_STEPSIZE, 0); } else { newBrightness = Math.min(currentBrightness + DIM_STEPSIZE, 65535); } + + if (inverted) + newBrightness = 65535 - newBrightness; return newBrightness; } @@ -161,8 +171,10 @@ * lutron device * @return percent type representing the brightness */ - public static PercentType toBrightnessPercentType(LutronDevice device) { + public static PercentType toBrightnessPercentType(LutronDevice device, boolean inverted) { int percent = (int) Math.round(device.getProperty(LUTRON_PROPERTY_LEVEL) / (65535 / 100)); + if (inverted) + percent = 100 - percent; if (log.isTraceEnabled()) { log.trace("Converting " + device.getProperty(LUTRON_PROPERTY_LEVEL) + " -> " + percent + " -> " + new PercentType(restrictToBounds(percent))); diff --git a/src/main/java/org/openhab/binding/lutronmqtt/handler/LutronMQTTShadeHandler.java b/src/main/java/org/openhab/binding/lutronmqtt/handler/LutronMQTTShadeHandler.java --- a/src/main/java/org/openhab/binding/lutronmqtt/handler/LutronMQTTShadeHandler.java +++ b/src/main/java/org/openhab/binding/lutronmqtt/handler/LutronMQTTShadeHandler.java @@ -21,5 +21,6 @@ public LutronMQTTShadeHandler(Thing thing) { super(thing, CHANNEL_SHADE_LEVEL, CHANNEL_POWER_SWITCH); + inverted = true; } } diff --git a/src/main/java/org/openhab/binding/lutronmqtt/handler/PowerLevelDeviceHandler.java b/src/main/java/org/openhab/binding/lutronmqtt/handler/PowerLevelDeviceHandler.java --- a/src/main/java/org/openhab/binding/lutronmqtt/handler/PowerLevelDeviceHandler.java +++ b/src/main/java/org/openhab/binding/lutronmqtt/handler/PowerLevelDeviceHandler.java @@ -35,6 +35,9 @@ protected int objectId; // protected int deviceId; // // protected int integrationId; + + protected boolean inverted = false; + protected LutronDevice device; // last update received for this device. // protected int linkAddress; @@ -64,13 +67,13 @@ } if (powerLevelChannelName.equals(ch)) { if (command instanceof PercentType) { - lightState = LightStateConverter.toLightState((PercentType) command, getDevice()); + lightState = LightStateConverter.toLightState((PercentType) command, getDevice(), inverted); } else if (command instanceof OnOffType) { - lightState = LightStateConverter.toLightState((OnOffType) command, getDevice()); + lightState = LightStateConverter.toLightState((OnOffType) command, getDevice(), inverted); } else if (command instanceof IncreaseDecreaseType) { - lightState = LightStateConverter.toLightState((IncreaseDecreaseType) command, getDevice()); + lightState = LightStateConverter.toLightState((IncreaseDecreaseType) command, getDevice(), inverted); } else if (command instanceof UpDownType) { - lightState = LightStateConverter.toLightState((UpDownType) command, getDevice()); + lightState = LightStateConverter.toLightState((UpDownType) command, getDevice(), inverted); } else if (command == StopMoveType.STOP) { setAsIs = true; log.warn("STOPPING"); @@ -265,7 +268,7 @@ // TODO we should keep the previous state so that we don't send unnecessary updates. - PercentType percentType = LightStateConverter.toBrightnessPercentType(d); + PercentType percentType = LightStateConverter.toBrightnessPercentType(d, inverted); log.info("Lutron: " + d.getName() + " Light Level: " + percentType.intValue()); updateState(powerLevelChannelName, percentType);