|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 Digital Media Server developers. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.digitalmediaserver.cast.message.enumeration; |
| 17 | + |
| 18 | +import java.util.Locale; |
| 19 | +import javax.annotation.Nullable; |
| 20 | +import org.digitalmediaserver.cast.util.Util; |
| 21 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 22 | + |
| 23 | +/** |
| 24 | + * This represents the type of cast device. |
| 25 | + * |
| 26 | + * @author Nadahar |
| 27 | + */ |
| 28 | +public enum DeviceType { |
| 29 | + |
| 30 | + /** Generic Cast device */ |
| 31 | + GENERIC, |
| 32 | + |
| 33 | + /** Cast-enabled TV */ |
| 34 | + TV, |
| 35 | + |
| 36 | + /** Cast-enabled speaker or other audio device */ |
| 37 | + SPEAKER, |
| 38 | + |
| 39 | + /** Speaker group */ |
| 40 | + SPEAKER_GROUP, |
| 41 | + |
| 42 | + /** The "Nearby Devices" pseudo-device, which represents any nearby unpaired guest-mode devices */ |
| 43 | + NEARBY_UNPAIRED; |
| 44 | + |
| 45 | + /** |
| 46 | + * Parses the specified string and returns the corresponding |
| 47 | + * {@link DeviceType}, or {@code null} if no match could be found. |
| 48 | + * |
| 49 | + * @param deviceType the string to parse. |
| 50 | + * @return The resulting {@link DeviceType} or {@code null}. |
| 51 | + */ |
| 52 | + @Nullable |
| 53 | + @JsonCreator |
| 54 | + public static DeviceType typeOf(String deviceType) { |
| 55 | + if (Util.isBlank(deviceType)) { |
| 56 | + return null; |
| 57 | + } |
| 58 | + String typeString = deviceType.toUpperCase(Locale.ROOT).replace(' ', '_'); |
| 59 | + for (DeviceType type : values()) { |
| 60 | + if (typeString.equals(type.name())) { |
| 61 | + return type; |
| 62 | + } |
| 63 | + } |
| 64 | + return null; |
| 65 | + } |
| 66 | +} |
0 commit comments