Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Influxdb bugfix for issue #2208 (restoring switch or contact state)
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo Weiss committed Feb 28, 2015
1 parent 507e274 commit 977b29a
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,13 @@ private State objectToState(Object value, String itemName) {
try {
Item item = itemRegistry.getItem(itemName);
if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
return valueStr.equals(DIGITAL_VALUE_OFF) ? OnOffType.OFF : OnOffType.ON;
return string2DigitalValue(valueStr).equals(DIGITAL_VALUE_OFF)
? OnOffType.OFF
: OnOffType.ON;
} else if (item instanceof ContactItem) {
return valueStr.equals(DIGITAL_VALUE_OFF) ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
return string2DigitalValue(valueStr).equals(DIGITAL_VALUE_OFF)
? OpenClosedType.CLOSED
: OpenClosedType.OPEN;
}
} catch (ItemNotFoundException e) {
logger.warn("Could not find item '{}' in registry", itemName);
Expand All @@ -485,4 +489,22 @@ private State objectToState(Object value, String itemName) {
return new DecimalType(valueStr);
}

/**
* Maps a string value which expresses a {@link BigDecimal.ZERO } to DIGITAL_VALUE_OFF, all others
* to DIGITAL_VALUE_ON
*
* @param value to be mapped
* @return
*/
private String string2DigitalValue(String value) {
BigDecimal num = new BigDecimal(value);
if (num.compareTo(BigDecimal.ZERO) == 0) {
logger.trace("digitalvalue {}", DIGITAL_VALUE_OFF);
return DIGITAL_VALUE_OFF;
} else {
logger.trace("digitalvalue {}", DIGITAL_VALUE_ON);
return DIGITAL_VALUE_ON;
}
}

}

0 comments on commit 977b29a

Please sign in to comment.