]> git.basschouten.com Git - openhab-addons.git/blob
51763626bd75070301ea507299780cca35082c4c
[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.sleepiq.internal.api.enums;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * The {@link Side} represents the possible sides of the bed (i.e. left and right).
20  *
21  * @author Mark Hilbush - Initial contribution
22  */
23 @NonNullByDefault
24 public enum Side {
25     LEFT(0),
26     RIGHT(1);
27
28     private final int side;
29
30     Side(final int side) {
31         this.side = side;
32     }
33
34     public int value() {
35         return side;
36     }
37
38     public static Side forValue(int value) {
39         for (Side s : Side.values()) {
40             if (s.side == value) {
41                 return s;
42             }
43         }
44         throw new IllegalArgumentException("Invalid side: " + value);
45     }
46
47     public static Side convertFromGroup(@Nullable String channelGroup) {
48         return "left".equalsIgnoreCase(channelGroup) ? Side.LEFT : Side.RIGHT;
49     }
50
51     @Override
52     public String toString() {
53         return side == 0 ? LEFT.name() : RIGHT.name();
54     }
55 }