@@ 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)));
@@ 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);