]> git.basschouten.com Git - openhab-addons.git/blob
e383128230c7086909fca75c5a6a1ee5cffe5829
[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  * Type of a group as reported by the REST API for usage in
25  * {@link org.openhab.binding.deconz.internal.dto.LightMessage}
26  *
27  * @author Jan N. Klug - Initial contribution
28  */
29 @NonNullByDefault
30 public enum GroupType {
31     LIGHT_GROUP("LightGroup"),
32     LUMINAIRE("Luminaire"),
33     ROOM("Room"),
34     LIGHT_SOURCE("Lightsource"),
35     UNKNOWN("");
36
37     private static final Map<String, GroupType> MAPPING = Arrays.stream(GroupType.values())
38             .collect(Collectors.toMap(v -> v.type, v -> v));
39     private static final Logger LOGGER = LoggerFactory.getLogger(GroupType.class);
40
41     private final String type;
42
43     GroupType(String type) {
44         this.type = type;
45     }
46
47     public static GroupType fromString(String s) {
48         GroupType lightType = MAPPING.getOrDefault(s, UNKNOWN);
49         if (lightType == UNKNOWN) {
50             LOGGER.debug("Unknown group type '{}' found. This should be reported.", s);
51         }
52         return lightType;
53     }
54 }