2 * Copyright (c) 2010-2023 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.miot;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * Enum of the unitTypes used in the miio protocol
23 * Used to find the right {@link javax.measure.Unit} given the string of the unitType
25 * @author Marcel Verpaalen - Initial contribution
28 public enum MiIoQuantiyTypesConversion {
30 ANGLE("Angle", "arcdegrees", "radians"),
31 DENSITY("Density", "mg/m3"),
32 DIMENSIONLESS("Dimensionless", "percent", "percentage", "ppm"),
33 ELECTRIC_POTENTIAL("ElectricPotential", "volt"),
34 POWER("Power", "watt", "w"),
35 CURRENT("ElectricCurrent", "ampere", "mA"),
36 ILLUMINANCE("Illuminance", "lux"),
37 PRESSURE("Pressure", "pascal"),
38 TEMPERATURE("Temperature", "c", "celcius", "celsius", "f", "farenheith", "kelvin", "K"),
39 TIME("Time", "seconds", "minutes", "minute", "hour", "hours", "days", "Months"),
40 VOLUME("Volume", "litre", "liter", "m3");
43 * available options according to miot spec:
45 * Celsius degrees Celsius
50 * kelvin temperature scale
51 * pascal Pascal (atmospheric pressure unit)
52 * arcdegrees radians (angle units)
56 * ppm ppm concentration
57 * lux Lux (illuminance)
58 * mg/m3 milligrams per cubic meter
61 private final String unitType;
62 private final String[] aliasses;
64 private static Map<String, String> aliasMap() {
65 Map<String, String> aliassesMap = new HashMap<>();
66 for (MiIoQuantiyTypesConversion miIoQuantiyType : values()) {
67 for (String alias : miIoQuantiyType.getAliasses()) {
68 aliassesMap.put(alias.toLowerCase(), miIoQuantiyType.getunitType());
74 private MiIoQuantiyTypesConversion(String unitType, String... aliasses) {
75 this.unitType = unitType;
76 this.aliasses = aliasses;
79 public String getunitType() {
83 public String[] getAliasses() {
87 public static @Nullable String getType(@Nullable String unitTypeName) {
88 if (unitTypeName != null) {
89 return aliasMap().get(unitTypeName.toLowerCase());