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

Influxdb bugfix for issue #2208 (restoring switch or contact state) #2211

Merged
merged 1 commit into from
Mar 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}

}