2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.miio.internal;
15 import java.util.Arrays;
17 import java.util.stream.Collectors;
19 import javax.measure.Unit;
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;
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
31 * @author Marcel Verpaalen - Initial contribution
34 public enum MiIoQuantiyTypes {
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);
44 private final Unit<?> unit;
46 private static Map<String, Unit<?>> stringMap = Arrays.stream(values())
47 .collect(Collectors.toMap(Enum::toString, MiIoQuantiyTypes::getUnit));
49 private MiIoQuantiyTypes(Unit<?> unit) {
53 public Unit<?> getUnit() {
57 public static @Nullable Unit<?> get(String unitName) {
58 return stringMap.get(unitName.toUpperCase());