2 * Copyright (c) 2010-2020 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.deconz.internal.types;
15 import java.util.Arrays;
17 import java.util.stream.Collectors;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The {@link ResourceType} defines an enum for websocket messages
26 * @author Jan N. Klug - Initial contribution
29 public enum ResourceType {
30 GROUPS("groups", "action"),
31 LIGHTS("lights", "state"),
32 SENSORS("sensors", "config"),
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);
39 private String identifier;
40 private String commandUrl;
42 ResourceType(String identifier, String commandUrl) {
43 this.identifier = identifier;
44 this.commandUrl = commandUrl;
48 * get the identifier string of this resource type
52 public String getIdentifier() {
57 * get the commandUrl part for this resource type
61 public String getCommandUrl() {
66 * get the resource type from a string
69 * @return the corresponding resource type (or UNKNOWN)
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);