]> git.basschouten.com Git - openhab-addons.git/blob
a083205ac59edeb56e47d060f093cd2ff4f4461d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lcn.internal.converter;
14
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;
20
21 /**
22  * Converter for all states representing antonyms.
23  *
24  * @author Thomas Weiler - Initial Contribution
25  */
26 @NonNullByDefault
27 public class InversionConverter extends Converter {
28     /**
29      * Converts a state into its antonym where applicable.
30      *
31      * @param state to be inverted
32      * @return inverted state
33      */
34     @Override
35     public State onStateUpdateFromHandler(State state) {
36         State convertedState = state;
37
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;
44         }
45
46         return convertedState;
47     }
48 }