2 * Copyright (c) 2010-2023 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.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.deconz.internal.dto.DeconzBaseMessage;
22 import org.openhab.binding.deconz.internal.dto.GroupMessage;
23 import org.openhab.binding.deconz.internal.dto.LightMessage;
24 import org.openhab.binding.deconz.internal.dto.SensorMessage;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * The {@link ResourceType} defines an enum for websocket messages
31 * @author Jan N. Klug - Initial contribution
34 public enum ResourceType {
35 GROUPS("groups", "action", GroupMessage.class),
36 LIGHTS("lights", "state", LightMessage.class),
37 SENSORS("sensors", "config", SensorMessage.class),
38 UNKNOWN("", "", null);
40 private static final Map<String, ResourceType> MAPPING = Arrays.stream(ResourceType.values())
41 .collect(Collectors.toMap(v -> v.identifier, v -> v));
42 private static final Logger LOGGER = LoggerFactory.getLogger(ResourceType.class);
44 private String identifier;
45 private String commandUrl;
46 private @Nullable Class<? extends DeconzBaseMessage> expectedMessageType;
48 ResourceType(String identifier, String commandUrl,
49 @Nullable Class<? extends DeconzBaseMessage> expectedMessageType) {
50 this.identifier = identifier;
51 this.commandUrl = commandUrl;
52 this.expectedMessageType = expectedMessageType;
56 * get the identifier string of this resource type
60 public String getIdentifier() {
65 * get the commandUrl part for this resource type
69 public String getCommandUrl() {
74 * get the expected message type for this resource type
78 public @Nullable Class<? extends DeconzBaseMessage> getExpectedMessageType() {
79 return expectedMessageType;
83 * get the resource type from a string
86 * @return the corresponding resource type (or UNKNOWN)
88 public static ResourceType fromString(String s) {
89 ResourceType lightType = MAPPING.getOrDefault(s, UNKNOWN);
90 if (lightType == UNKNOWN) {
91 LOGGER.debug("Unknown resource type '{}' found. This should be reported.", s);