]> git.basschouten.com Git - openhab-addons.git/blob
972afd645633c7f96a5f4c91b7b2dfcf84427c82
[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.lutron.internal.protocol;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 import com.google.gson.annotations.SerializedName;
18
19 /**
20  * Defines Lutron fan controller speed settings
21  *
22  * @author Bob Adair - Initial contribution
23  */
24 @NonNullByDefault
25 public enum FanSpeedType {
26     @SerializedName("High")
27     HIGH(100, "High"),
28     @SerializedName("MediumHigh")
29     MEDIUMHIGH(75, "MediumHigh"),
30     @SerializedName("Medium")
31     MEDIUM(50, "Medium"),
32     @SerializedName("Low")
33     LOW(25, "Low"),
34     @SerializedName("Off")
35     OFF(0, "Off");
36
37     /** Fan speed expressed as a percentage **/
38     private final int speed;
39
40     /** Fan speed expressed as a String (used by LEAP) **/
41     private final String leapValue;
42
43     FanSpeedType(int speed, String leapValue) {
44         this.speed = speed;
45         this.leapValue = leapValue;
46     }
47
48     public int speed() {
49         return speed;
50     }
51
52     public String leapValue() {
53         return leapValue;
54     }
55
56     @Override
57     public String toString() {
58         return leapValue;
59     }
60
61     public static FanSpeedType toFanSpeedType(int percentage) {
62         if (percentage == OFF.speed) {
63             return FanSpeedType.OFF;
64         } else if (percentage > OFF.speed && percentage <= LOW.speed) {
65             return FanSpeedType.LOW;
66         } else if (percentage > LOW.speed && percentage <= MEDIUM.speed) {
67             return FanSpeedType.MEDIUM;
68         } else if (percentage > MEDIUM.speed && percentage <= MEDIUMHIGH.speed) {
69             return FanSpeedType.MEDIUMHIGH;
70         } else {
71             return FanSpeedType.HIGH;
72         }
73     }
74
75     public static FanSpeedType toFanSpeedType(String speedString) {
76         for (FanSpeedType enumValue : FanSpeedType.values()) {
77             if (enumValue.leapValue.equalsIgnoreCase(speedString)) {
78                 return enumValue;
79             }
80         }
81         return OFF;
82     }
83 }