]> git.basschouten.com Git - openhab-addons.git/blob
1d32407c6c1fcdf229479c5db5bec881477d4cb3
[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.openuv.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.DecimalType;
17 import org.openhab.core.types.State;
18 import org.openhab.core.types.UnDefType;
19
20 /**
21  * The {@link AlertLevel} enum defines alert level in regard of the UV Index
22  *
23  * @author GaĆ«l L'hopital - Initial contribution
24  */
25 @NonNullByDefault
26 public enum AlertLevel {
27     GREEN(DecimalType.ZERO, "3a8b2f"),
28     YELLOW(new DecimalType(1), "f9a825"),
29     ORANGE(new DecimalType(2), "ef6c00"),
30     RED(new DecimalType(3), "b71c1c"),
31     PURPLE(new DecimalType(4), "6a1b9a"),
32     UNKNOWN(UnDefType.NULL, "b3b3b3");
33
34     public final State state;
35     public final String color;
36
37     AlertLevel(State state, String color) {
38         this.state = state;
39         this.color = color;
40     }
41
42     public static AlertLevel fromUVIndex(double uv) {
43         if (uv >= 11) {
44             return PURPLE;
45         } else if (uv >= 8) {
46             return RED;
47         } else if (uv >= 6) {
48             return ORANGE;
49         } else if (uv >= 3) {
50             return YELLOW;
51         } else if (uv > 0) {
52             return GREEN;
53         }
54         return UNKNOWN;
55     }
56 }