Search in sources :

Example 1 with StateComparator

use of org.openhab.binding.zwave.internal.converter.state.StateComparator in project openhab1-addons by openhab.

the class ZWaveConverterBase method getStateConverter.

/**
     * Gets a {@link ZWaveStateConverter} that is suitable for this {@link CommandClass} and the data types supported by
     * the {@link Item}
     *
     * @param commandClass the {@link CommandClass} that sent the value.
     * @param item the {@link Item} that has to receive the State;
     * @return a converter object that converts between the value and the state;
     */
protected ZWaveStateConverter<?, ?> getStateConverter(Item item, Object value) {
    if (item == null) {
        return null;
    }
    List<Class<? extends State>> list = new ArrayList<Class<? extends State>>(item.getAcceptedDataTypes());
    Collections.sort(list, new StateComparator());
    for (Class<? extends State> stateClass : list) {
        ZWaveStateConverter<?, ?> result = stateConverters.get(stateClass);
        if (result == null || !result.getType().isInstance(value)) {
            continue;
        }
        return result;
    }
    return null;
}
Also used : State(org.openhab.core.types.State) ArrayList(java.util.ArrayList) CommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass.CommandClass) StateComparator(org.openhab.binding.zwave.internal.converter.state.StateComparator)

Aggregations

ArrayList (java.util.ArrayList)1 StateComparator (org.openhab.binding.zwave.internal.converter.state.StateComparator)1 CommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass.CommandClass)1 State (org.openhab.core.types.State)1