]> git.basschouten.com Git - openhab-addons.git/blob
02ddf78c49389064f4e7473ebc2603d373038414
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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  * The {@link ResourceType} defines an enum for websocket messages
25  *
26  * @author Jan N. Klug - Initial contribution
27  */
28 @NonNullByDefault
29 public enum ResourceType {
30     GROUPS("groups", "action"),
31     LIGHTS("lights", "state"),
32     SENSORS("sensors", "config"),
33     UNKNOWN("", "");
34
35     private static final Map<String, ResourceType> MAPPING = Arrays.stream(ResourceType.values())
36             .collect(Collectors.toMap(v -> v.identifier, v -> v));
37     private static final Logger LOGGER = LoggerFactory.getLogger(ResourceType.class);
38
39     private String identifier;
40     private String commandUrl;
41
42     ResourceType(String identifier, String commandUrl) {
43         this.identifier = identifier;
44         this.commandUrl = commandUrl;
45     }
46
47     /**
48      * get the identifier string of this resource type
49      *
50      * @return
51      */
52     public String getIdentifier() {
53         return identifier;
54     }
55
56     /**
57      * get the commandUrl part for this resource type
58      *
59      * @return
60      */
61     public String getCommandUrl() {
62         return commandUrl;
63     }
64
65     /**
66      * get the resource type from a string
67      *
68      * @param s the string
69      * @return the corresponding resource type (or UNKNOWN)
70      */
71     public static ResourceType fromString(String s) {
72         ResourceType lightType = MAPPING.getOrDefault(s, UNKNOWN);
73         if (lightType == UNKNOWN) {
74             LOGGER.debug("Unknown resource type '{}' found. This should be reported.", s);
75         }
76         return lightType;
77     }
78 }