]> git.basschouten.com Git - openhab-addons.git/blob
303c62bab03eab40886807eb65fb21b03fbb60d7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.miio.internal;
14
15 import java.util.Arrays;
16 import java.util.Map;
17 import java.util.stream.Collectors;
18
19 import javax.measure.Unit;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.library.unit.ImperialUnits;
24 import org.openhab.core.library.unit.SIUnits;
25 import org.openhab.core.library.unit.SmartHomeUnits;
26
27 /**
28  * Enum of the units used in the miio protocol
29  * Used to find the right {@link javax.measure.Unit} given the string of the unit
30  *
31  * @author Marcel Verpaalen - Initial contribution
32  */
33 @NonNullByDefault
34 public enum MiIoQuantiyTypes {
35
36     CELCIUS(SIUnits.CELSIUS),
37     FAHRENHEIT(ImperialUnits.FAHRENHEIT),
38     SECOND(SmartHomeUnits.SECOND),
39     MINUTE(SmartHomeUnits.MINUTE),
40     HOUR(SmartHomeUnits.HOUR),
41     AMPERE(SmartHomeUnits.AMPERE),
42     WATT(SmartHomeUnits.WATT);
43
44     private final Unit<?> unit;
45
46     private static Map<String, Unit<?>> stringMap = Arrays.stream(values())
47             .collect(Collectors.toMap(Enum::toString, MiIoQuantiyTypes::getUnit));
48
49     private MiIoQuantiyTypes(Unit<?> unit) {
50         this.unit = unit;
51     }
52
53     public Unit<?> getUnit() {
54         return unit;
55     }
56
57     public static @Nullable Unit<?> get(String unitName) {
58         return stringMap.get(unitName.toUpperCase());
59     }
60 }