report shade levels according to openhab standards (ie, inverted from lutron's)
M pom.xml +2 -2
@@ 7,11 7,11 @@ 
   <parent>
     <groupId>org.openhab.addons.bundles</groupId>
     <artifactId>org.openhab.addons.reactor.bundles</artifactId>
-    <version>3.0.1</version>
+    <version>3.1.0</version>
     <relativePath>../openhab-addons/bundles</relativePath>
   </parent>
 
-  <version>3.0.2-SNAPSHOT</version>
+  <version>3.1.0</version>
 
   <artifactId>org.openhab.binding.lutronmqtt</artifactId>
   <name>openHAB Add-ons :: Bundles :: Lutron-MQTT Binding</name>

          
M src/main/history/dependencies.xml +2 -2
@@ 1,10 1,10 @@ 
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<features xmlns="http://karaf.apache.org/xmlns/features/v1.6.0" name="org.openhab.binding.lutronmqtt-3.0.2-SNAPSHOT">
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.6.0" name="org.openhab.binding.lutronmqtt-3.1.0">
     <feature version="0.0.0">
         <feature>openhab-runtime-base</feature>
         <feature>openhab-transport-mqtt</feature>
         <feature>wrap</feature>
-        <bundle>mvn:org.openhab.addons.bundles/org.openhab.binding.lutronmqtt/3.0.2-SNAPSHOT</bundle>
+        <bundle>mvn:org.openhab.addons.bundles/org.openhab.binding.lutronmqtt/3.1.0</bundle>
         <bundle>wrap:mvn:org.lastnpe.eea/eea-all/2.2.1</bundle>
     </feature>
 </features>

          
M src/main/java/org/openhab/binding/lutronmqtt/handler/LightStateConverter.java +25 -13
@@ 41,14 41,16 @@ public class LightStateConverter {
      *            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 @@ public class LightStateConverter {
         else {
             f = (int) Math.round(percentType.floatValue() * 65535 / 100);
         }
+        if (inverted)
+            f = 65535 - f;
         return f;
     }
 
-    public static Map<String, Object> toLightState(OnOffType onOffType, LutronDevice device) {
-        int level = toOnOffLightState(onOffType);
+    public static Map<String, Object> toLightState(OnOffType onOffType, LutronDevice device, boolean inverted) {
+        int level = toOnOffLightState(onOffType, inverted);
         Map<String, Object> m = makeGoToLevelCommand(level, device);
         return m;
     }

          
@@ 89,24 93,25 @@ public class LightStateConverter {
      *            brightness represented as {@link PercentType}
      * @return light state containing the brightness and the 'on' value
      */
-    public static Map<String, Object> toLightState(PercentType percentType, LutronDevice device) {
-        int level = toPercentLightState(percentType);
+    public static Map<String, Object> toLightState(PercentType percentType, LutronDevice device, boolean inverted) {
+        int level = toPercentLightState(percentType, inverted);
 
         Map<String, Object> m = makeGoToLevelCommand(level, device);
 
         return m;
     }
 
-    public static Map<String, Object> toLightState(IncreaseDecreaseType increaseDecreaseType, LutronDevice device) {
-        int level = toAdjustedBrightness(increaseDecreaseType, device.getProperty(LUTRON_PROPERTY_LEVEL));
+    public static Map<String, Object> toLightState(IncreaseDecreaseType increaseDecreaseType, LutronDevice device,
+            boolean inverted) {
+        int level = toAdjustedBrightness(increaseDecreaseType, device.getProperty(LUTRON_PROPERTY_LEVEL), inverted);
 
         Map<String, Object> m = makeGoToLevelCommand(level, device);
 
         return m;
     }
 
-    public static Map<String, Object> toLightState(UpDownType upDownType, LutronDevice device) {
-        int level = toAdjustedBrightness(upDownType, device.getProperty(LUTRON_PROPERTY_LEVEL));
+    public static Map<String, Object> toLightState(UpDownType upDownType, LutronDevice device, boolean inverted) {
+        int level = toAdjustedBrightness(upDownType, device.getProperty(LUTRON_PROPERTY_LEVEL), inverted);
 
         Map<String, Object> m = makeGoToLevelCommand(level, device);
 

          
@@ 123,13 128,15 @@ public class LightStateConverter {
      *            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 @@ public class LightStateConverter {
      *            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 @@ public class LightStateConverter {
      *            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)));

          
M src/main/java/org/openhab/binding/lutronmqtt/handler/LutronMQTTShadeHandler.java +1 -0
@@ 21,5 21,6 @@ public class LutronMQTTShadeHandler exte
 
     public LutronMQTTShadeHandler(Thing thing) {
         super(thing, CHANNEL_SHADE_LEVEL, CHANNEL_POWER_SWITCH);
+        inverted = true;
     }
 }

          
M src/main/java/org/openhab/binding/lutronmqtt/handler/PowerLevelDeviceHandler.java +8 -5
@@ 35,6 35,9 @@ public class PowerLevelDeviceHandler ext
     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 @@ public class PowerLevelDeviceHandler ext
         }
         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 @@ public class PowerLevelDeviceHandler ext
 
         // 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);