]> git.basschouten.com Git - openhab-addons.git/blob
de3cf74ac44d629d4e087ba817946f0537a01afb
[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.deconz.internal.types;
14
15 import java.util.Arrays;
16 import java.util.Map;
17 import java.util.stream.Collectors;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * Thermostat mode as reported by the REST API for usage in {@link org.openhab.binding.deconz.internal.dto.SensorConfig}
25  *
26  * @author Lukas Agethen - Initial contribution
27  */
28 @NonNullByDefault
29 public enum ThermostatMode {
30     AUTO("auto"),
31     HEAT("heat"),
32     OFF("off"),
33     UNKNOWN("");
34
35     private static final Map<String, ThermostatMode> MAPPING = Arrays.stream(ThermostatMode.values())
36             .collect(Collectors.toMap(v -> v.deconzValue, v -> v));
37     private static final Logger LOGGER = LoggerFactory.getLogger(ThermostatMode.class);
38
39     private String deconzValue;
40
41     ThermostatMode(String deconzValue) {
42         this.deconzValue = deconzValue;
43     }
44
45     public String getDeconzValue() {
46         return deconzValue;
47     }
48
49     public static ThermostatMode fromString(String s) {
50         ThermostatMode thermostatMode = MAPPING.getOrDefault(s, UNKNOWN);
51         if (thermostatMode == UNKNOWN) {
52             LOGGER.debug("Unknown thermostat mode '{}' found. This should be reported.", s);
53         }
54         return thermostatMode;
55     }
56 }