Search in sources :

Example 1 with ZWaveThermostatSetpointValueEvent

use of org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveThermostatSetpointCommandClass.ZWaveThermostatSetpointValueEvent in project openhab1-addons by openhab.

the class ZWaveThermostatSetpointConverter method handleEvent.

/**
     * {@inheritDoc}
     */
@Override
void handleEvent(ZWaveCommandClassValueEvent event, Item item, Map<String, String> arguments) {
    ZWaveStateConverter<?, ?> converter = this.getStateConverter(item, event.getValue());
    String setpointType = arguments.get("setpoint_type");
    String scale = arguments.get("setpoint_scale");
    ZWaveThermostatSetpointValueEvent setpointEvent = (ZWaveThermostatSetpointValueEvent) event;
    if (converter == null) {
        logger.warn("NODE {}: No converter found for item = {} endpoint = {}, ignoring event.", event.getNodeId(), item.getName(), event.getEndpoint());
        return;
    }
    // Don't trigger event if this item is bound to another setpoint type
    if (setpointType != null && SetpointType.getSetpointType(Integer.parseInt(setpointType)) != setpointEvent.getSetpointType()) {
        return;
    }
    Object val = event.getValue();
    // Perform a scale conversion if needed
    if (scale != null && Integer.parseInt(scale) != setpointEvent.getScale()) {
        // For temperature, there are only two scales, so we simplify the conversion
        if (setpointEvent.getScale() == 0) {
            // Scale is celsius, convert to fahrenheit
            double c = ((BigDecimal) val).doubleValue();
            val = new BigDecimal((c * 9.0 / 5.0) + 32.0);
        } else if (setpointEvent.getScale() == 1) {
            // Scale is fahrenheit, convert to celsius
            double f = ((BigDecimal) val).doubleValue();
            val = new BigDecimal((f - 32.0) * 5.0 / 9.0);
        }
    }
    State state = converter.convertFromValueToState(val);
    this.getEventPublisher().postUpdate(item.getName(), state);
}
Also used : State(org.openhab.core.types.State) ZWaveThermostatSetpointValueEvent(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveThermostatSetpointCommandClass.ZWaveThermostatSetpointValueEvent) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 ZWaveThermostatSetpointValueEvent (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveThermostatSetpointCommandClass.ZWaveThermostatSetpointValueEvent)1 State (org.openhab.core.types.State)1