]> git.basschouten.com Git - openhab-addons.git/blob
f08566c77f9f21959c2d12c07b84396ecb6457c9
[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.hue.internal.dto.clip2.enums;
14
15 import java.util.EnumSet;
16 import java.util.Set;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Enum for resource types.
23  *
24  * @author Andrew Fiddian-Green - Initial contribution
25  */
26 @NonNullByDefault
27 public enum ResourceType {
28     AUTH_V1,
29     BEHAVIOR_INSTANCE,
30     BEHAVIOR_SCRIPT,
31     BRIDGE,
32     BRIDGE_HOME,
33     BUTTON,
34     DEVICE,
35     DEVICE_POWER,
36     ENTERTAINMENT,
37     ENTERTAINMENT_CONFIGURATION,
38     GEOFENCE,
39     GEOFENCE_CLIENT,
40     GEOLOCATION,
41     GROUPED_LIGHT,
42     HOMEKIT,
43     LIGHT,
44     LIGHT_LEVEL,
45     MOTION,
46     PUBLIC_IMAGE,
47     ROOM,
48     RELATIVE_ROTARY,
49     SCENE,
50     SMART_SCENE,
51     TEMPERATURE,
52     ZGP_CONNECTIVITY,
53     ZIGBEE_CONNECTIVITY,
54     ZONE,
55     UPDATE,
56     ADD,
57     DELETE,
58     ERROR;
59
60     public static final Set<ResourceType> SSE_TYPES = EnumSet.of(UPDATE, ADD, DELETE, ERROR);
61
62     public static ResourceType of(@Nullable String value) {
63         if (value != null) {
64             try {
65                 return valueOf(value.toUpperCase());
66             } catch (IllegalArgumentException e) {
67                 // fall through
68             }
69         }
70         return ERROR.setUnknownTypeId(value);
71     }
72
73     private @Nullable String unknownTypeId;
74
75     private ResourceType setUnknownTypeId(@Nullable String value) {
76         unknownTypeId = value;
77         return this;
78     }
79
80     @Override
81     public String toString() {
82         String s = this.name().replace("_", " ");
83         s = s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
84         return unknownTypeId == null ? s : s + String.format(" (%s)", unknownTypeId);
85     }
86 }