]> git.basschouten.com Git - openhab-addons.git/blob
f813bfec32121ac2c0c069c120f53e94436db22b
[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
17 /**
18  * The {@link FoundationPreset} represents preset bed positions for a bed side.
19  *
20  * @author Mark Hilbush - Initial contribution
21  */
22 @NonNullByDefault
23 public enum FoundationPreset {
24     NOT_AT_PRESET(0),
25     FAVORITE(1),
26     READ(2),
27     WATCH_TV(3),
28     FLAT(4),
29     ZERO_G(5),
30     SNORE(6);
31
32     private final int preset;
33
34     FoundationPreset(final int preset) {
35         this.preset = preset;
36     }
37
38     public int value() {
39         return preset;
40     }
41
42     public static FoundationPreset forValue(int value) {
43         for (FoundationPreset s : FoundationPreset.values()) {
44             if (s.preset == value) {
45                 return s;
46             }
47         }
48         throw new IllegalArgumentException("Invalid preset: " + value);
49     }
50
51     public static FoundationPreset convertFromStatus(String currentPositionPreset) {
52         FoundationPreset preset;
53         switch (currentPositionPreset.toLowerCase()) {
54             case "not at preset":
55                 preset = FoundationPreset.NOT_AT_PRESET;
56                 break;
57             case "favorite":
58                 preset = FoundationPreset.FAVORITE;
59                 break;
60             case "read":
61                 preset = FoundationPreset.READ;
62                 break;
63             case "watch tv":
64                 preset = FoundationPreset.WATCH_TV;
65                 break;
66             case "flat":
67                 preset = FoundationPreset.FLAT;
68                 break;
69             case "zero g":
70                 preset = FoundationPreset.ZERO_G;
71                 break;
72             case "snore":
73                 preset = FoundationPreset.SNORE;
74                 break;
75             default:
76                 throw new IllegalArgumentException("Unknown preset value: " + currentPositionPreset);
77         }
78         return preset;
79     }
80
81     @Override
82     public String toString() {
83         return String.valueOf(preset);
84     }
85 }