]> git.basschouten.com Git - openhab-addons.git/blob
d38596654b8e1ff1890ab8394e295d6faa4b34a7
[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
25  * {@link org.openhab.binding.deconz.internal.dto.SensorConfig}
26  *
27  * @author Lukas Agethen - Initial contribution
28  */
29 @NonNullByDefault
30 public enum ThermostatMode {
31     AUTO("auto"),
32     HEAT("heat"),
33     OFF("off"),
34     UNKNOWN("");
35
36     private static final Map<String, ThermostatMode> MAPPING = Arrays.stream(ThermostatMode.values())
37             .collect(Collectors.toMap(v -> v.deconzValue, v -> v));
38     private static final Logger LOGGER = LoggerFactory.getLogger(ThermostatMode.class);
39
40     private final String deconzValue;
41
42     ThermostatMode(String deconzValue) {
43         this.deconzValue = deconzValue;
44     }
45
46     public String getDeconzValue() {
47         return deconzValue;
48     }
49
50     public static ThermostatMode fromString(String s) {
51         ThermostatMode thermostatMode = MAPPING.getOrDefault(s, UNKNOWN);
52         if (thermostatMode == UNKNOWN) {
53             LOGGER.debug("Unknown thermostat mode '{}' found. This should be reported.", s);
54         }
55         return thermostatMode;
56     }
57 }