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

Commit

Permalink
Merge pull request #2211 from theoweiss/influxdb-2015-2
Browse files Browse the repository at this point in the history
Influxdb bugfix for issue #2208 (restoring switch or contact state)
  • Loading branch information
theoweiss committed Mar 3, 2015
2 parents 777ab73 + 977b29a commit b6f8e8a
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 b6f8e8a

Please sign in to comment.