]> git.basschouten.com Git - openhab-addons.git/blob
66996dc50e15992cd48c24e8215acdc24d4348d9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.freeathomesystem.internal.valuestateconverter;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.StopMoveType;
17 import org.openhab.core.library.types.StringType;
18 import org.openhab.core.library.types.UpDownType;
19 import org.openhab.core.types.Command;
20 import org.openhab.core.types.State;
21
22 /**
23  * The {@link ShuttercontrolValueStateConverter} is a value converter for shutter movement
24  *
25  * @author Andras Uhrin - Initial contribution
26  *
27  */
28 @NonNullByDefault
29 public class ShuttercontrolValueStateConverter implements ValueStateConverter {
30
31     @Override
32     public State convertToState(String value) {
33         State ret = UpDownType.DOWN;
34
35         switch (value) {
36             default:
37             case "0":
38                 ret = new StringType("STOP");
39                 break;
40             case "2":
41                 ret = UpDownType.UP;
42                 break;
43             case "3":
44                 ret = UpDownType.DOWN;
45                 break;
46         }
47
48         return ret;
49     }
50
51     @Override
52     public String convertToValueString(State state) {
53         String valueString = "0";
54         String stateString = "STOP";
55
56         if (state instanceof UpDownType) {
57             stateString = ((UpDownType) state).toString();
58         }
59
60         if (((Command) state) instanceof StopMoveType) {
61             stateString = "STOP";
62         }
63
64         switch (stateString) {
65             default:
66             case "STOP":
67                 valueString = "0";
68                 break;
69             case "UP":
70                 valueString = "0";
71                 break;
72             case "DOWN":
73                 valueString = "1";
74                 break;
75         }
76
77         return valueString;
78     }
79 }