]> git.basschouten.com Git - openhab-addons.git/blob
cd8c917b1404042a15a96ec9dcc7813130ba5d9f
[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 static org.openhab.binding.sleepiq.internal.SleepIQBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link FoundationOutlet} represents the outlets available on the foundation.
21  *
22  * @author Mark Hilbush - Initial contribution
23  */
24 @NonNullByDefault
25 public enum FoundationOutlet {
26     RIGHT_NIGHT_STAND(1),
27     LEFT_NIGHT_STAND(2),
28     RIGHT_UNDER_BED_LIGHT(3),
29     LEFT_UNDER_BED_LIGHT(4);
30
31     private final int outlet;
32
33     FoundationOutlet(final int outlet) {
34         this.outlet = outlet;
35     }
36
37     public int value() {
38         return outlet;
39     }
40
41     public static FoundationOutlet forValue(int value) {
42         for (FoundationOutlet s : FoundationOutlet.values()) {
43             if (s.outlet == value) {
44                 return s;
45             }
46         }
47         throw new IllegalArgumentException("Invalid outlet: " + value);
48     }
49
50     public static FoundationOutlet convertFromChannelId(String channelId) {
51         FoundationOutlet localOutlet;
52         switch (channelId) {
53             case CHANNEL_RIGHT_NIGHT_STAND_OUTLET:
54                 localOutlet = FoundationOutlet.RIGHT_NIGHT_STAND;
55                 break;
56             case CHANNEL_LEFT_NIGHT_STAND_OUTLET:
57                 localOutlet = FoundationOutlet.LEFT_NIGHT_STAND;
58                 break;
59             case CHANNEL_RIGHT_UNDER_BED_LIGHT:
60                 localOutlet = FoundationOutlet.RIGHT_UNDER_BED_LIGHT;
61                 break;
62             case CHANNEL_LEFT_UNDER_BED_LIGHT:
63                 localOutlet = FoundationOutlet.LEFT_UNDER_BED_LIGHT;
64                 break;
65             default:
66                 throw new IllegalArgumentException("Can't convert channel to outlet: " + channelId);
67         }
68         return localOutlet;
69     }
70
71     @Override
72     public String toString() {
73         return String.valueOf(outlet);
74     }
75 }