]> git.basschouten.com Git - openhab-addons.git/blob
99da566e0a403ddd3ab965b62556207256cdd4a8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.enocean.internal.config;
14
15 import java.security.InvalidParameterException;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  *
22  * @author Daniel Weber - Initial contribution
23  */
24 @NonNullByDefault
25 public class EnOceanChannelRockerSwitchConfigBase {
26
27     public String switchMode;
28     public String channel;
29
30     public enum SwitchMode {
31         Unkown(""),
32         RockerSwitch("rockerSwitch"),
33         ToggleDir1("toggleButtonDir1"),
34         ToggleDir2("toggleButtonDir2");
35
36         private String value;
37
38         SwitchMode(String value) {
39             this.value = value;
40         }
41
42         public String getValue() {
43             return value;
44         }
45
46         public static SwitchMode getSwitchMode(@Nullable String value) {
47             if (value == null) {
48                 return SwitchMode.Unkown;
49             }
50
51             for (SwitchMode t : SwitchMode.values()) {
52                 if (t.value.equals(value)) {
53                     return t;
54                 }
55             }
56
57             throw new InvalidParameterException("Unknown SwitchMode");
58         }
59     }
60
61     public enum Channel {
62         Unkown(""),
63         ChannelA("channelA"),
64         ChannelB("channelB");
65
66         private String value;
67
68         Channel(String value) {
69             this.value = value;
70         }
71
72         public static Channel getChannel(@Nullable String value) {
73             if (value == null) {
74                 return Channel.Unkown;
75             }
76
77             for (Channel t : Channel.values()) {
78                 if (t.value.equals(value)) {
79                     return t;
80                 }
81             }
82
83             throw new InvalidParameterException("Unknown Channel");
84         }
85     }
86
87     public EnOceanChannelRockerSwitchConfigBase() {
88         switchMode = "rockerSwitch";
89         channel = "channelA";
90     }
91
92     public SwitchMode getSwitchMode() {
93         return SwitchMode.getSwitchMode(switchMode);
94     }
95
96     public Channel getChannel() {
97         return Channel.getChannel(channel);
98     }
99 }