@Override
public void handleEvent(ZWaveCommandClassValueEvent event, Item item, Map<String,String> arguments) {
ZWaveStateConverter<?,?> converter = this.getStateConverter(item, event.getValue());
String sensorType = arguments.get("sensor_type");
String sensorScale = arguments.get("sensor_scale");
ZWaveMultiLevelSensorValueEvent sensorEvent = (ZWaveMultiLevelSensorValueEvent)event;
if (converter == null) {
logger.warn("No converter found for item = {}, node = {} endpoint = {}, ignoring event.", item.getName(), event.getNodeId(), event.getEndpoint());
return;
}
// Don't trigger event if this item is bound to another sensor type
if (sensorType != null && SensorType.getSensorType(Integer.parseInt(sensorType)) != sensorEvent.getSensorType())
return;
Object val = event.getValue();
// Perform a scale conversion if needed
if (sensorScale != null && Integer.parseInt(sensorScale) != sensorEvent.getSensorScale()) {
switch(SensorType.getSensorType(Integer.parseInt(sensorType))) {
case TEMPERATURE:
// For temperature, there are only two scales, so we simplify the conversion
if(sensorEvent.getSensorScale() == 0) {
// Scale is celsius, convert to fahrenheit
double c = ((BigDecimal)val).doubleValue();
val = new BigDecimal((c * 9.0 / 5.0) + 32.0 );
}
else if(sensorEvent.getSensorScale() == 1) {
// Scale is fahrenheit, convert to celsius
double f = ((BigDecimal)val).doubleValue();
val = new BigDecimal((f - 32.0) * 5.0 / 9.0 );
}
break;