2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lcn.internal.converter;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.OnOffType;
17 import org.openhab.core.library.types.OpenClosedType;
18 import org.openhab.core.library.types.UpDownType;
19 import org.openhab.core.types.State;
22 * Converter for all states representing antonyms.
24 * @author Thomas Weiler - Initial Contribution
27 public class InversionConverter extends Converter {
29 * Converts a state into its antonym where applicable.
31 * @param state to be inverted
32 * @return inverted state
35 public State onStateUpdateFromHandler(State state) {
36 State convertedState = state;
38 if (state instanceof OpenClosedType) {
39 convertedState = state.equals(OpenClosedType.OPEN) ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
40 } else if (state instanceof OnOffType) {
41 convertedState = state.equals(OnOffType.ON) ? OnOffType.OFF : OnOffType.ON;
42 } else if (state instanceof UpDownType) {
43 convertedState = state.equals(UpDownType.UP) ? UpDownType.DOWN : UpDownType.UP;
46 return convertedState;