]> git.basschouten.com Git - openhab-addons.git/blob
a640783b78e58cc8c19ae69dcce648cb6f982bab
[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     TEMPERATURE,
51     ZGP_CONNECTIVITY,
52     ZIGBEE_CONNECTIVITY,
53     ZONE,
54     UPDATE,
55     ADD,
56     DELETE,
57     ERROR;
58
59     public static final Set<ResourceType> SSE_TYPES = EnumSet.of(UPDATE, ADD, DELETE, ERROR);
60
61     public static ResourceType of(@Nullable String value) {
62         if (value != null) {
63             try {
64                 return valueOf(value.toUpperCase());
65             } catch (IllegalArgumentException e) {
66                 // fall through
67             }
68         }
69         return ERROR.setUnknownTypeId(value);
70     }
71
72     private @Nullable String unknownTypeId;
73
74     private ResourceType setUnknownTypeId(@Nullable String value) {
75         unknownTypeId = value;
76         return this;
77     }
78
79     @Override
80     public String toString() {
81         String s = this.name().replace("_", " ");
82         s = s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
83         return unknownTypeId == null ? s : s + String.format(" (%s)", unknownTypeId);
84     }
85 }