2 * Copyright (c) 2010-2024 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.emotiva.internal.protocol;
15 import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.*;
16 import static org.openhab.binding.emotiva.internal.protocol.EmotivaDataType.*;
18 import java.util.ArrayList;
19 import java.util.List;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Emotiva subscription tags with corresponding UoM data type and channel.
28 * @author Espen Fossen - Initial contribution
31 public enum EmotivaSubscriptionTags {
33 /* Protocol V1 notify tags */
34 power("power", ON_OFF, CHANNEL_MAIN_ZONE_POWER),
35 source("source", STRING, CHANNEL_SOURCE),
36 dim("dim", DIMENSIONLESS_PERCENT, CHANNEL_DIM),
37 mode("mode", STRING, CHANNEL_MODE),
38 speaker_preset("speaker-preset", STRING, CHANNEL_SPEAKER_PRESET),
39 center("center", DIMENSIONLESS_DECIBEL, CHANNEL_CENTER),
40 subwoofer("subwoofer", DIMENSIONLESS_DECIBEL, CHANNEL_SUBWOOFER),
41 surround("surround", DIMENSIONLESS_DECIBEL, CHANNEL_SURROUND),
42 back("back", DIMENSIONLESS_DECIBEL, CHANNEL_BACK),
43 volume("volume", DIMENSIONLESS_DECIBEL, CHANNEL_MAIN_VOLUME),
44 loudness("loudness", ON_OFF, CHANNEL_LOUDNESS),
45 treble("treble", DIMENSIONLESS_DECIBEL, CHANNEL_TREBLE),
46 bass("bass", DIMENSIONLESS_DECIBEL, CHANNEL_BASS),
47 zone2_power("zone2-power", ON_OFF, CHANNEL_ZONE2_POWER),
48 zone2_volume("zone2-volume", DIMENSIONLESS_DECIBEL, CHANNEL_ZONE2_VOLUME),
49 zone2_input("zone2-input", STRING, CHANNEL_ZONE2_SOURCE),
50 tuner_band("tuner-band", STRING, CHANNEL_TUNER_BAND),
51 tuner_channel("tuner-channel", FREQUENCY_HERTZ, CHANNEL_TUNER_CHANNEL),
52 tuner_signal("tuner-signal", STRING, CHANNEL_TUNER_SIGNAL),
53 tuner_program("tuner-program", STRING, CHANNEL_TUNER_PROGRAM),
54 tuner_RDS("tuner-RDS", STRING, CHANNEL_TUNER_RDS),
55 audio_input("audio-input", STRING, CHANNEL_AUDIO_INPUT),
56 audio_bitstream("audio-bitstream", STRING, CHANNEL_AUDIO_BITSTREAM),
57 audio_bits("audio-bits", STRING, CHANNEL_AUDIO_BITS),
58 video_input("video-input", STRING, CHANNEL_VIDEO_INPUT),
59 video_format("video-format", STRING, CHANNEL_VIDEO_FORMAT),
60 video_space("video-space", STRING, CHANNEL_VIDEO_SPACE),
61 input_1("input-1", STRING, CHANNEL_INPUT1),
62 input_2("input-2", STRING, CHANNEL_INPUT2),
63 input_3("input-3", STRING, CHANNEL_INPUT3),
64 input_4("input-4", STRING, CHANNEL_INPUT4),
65 input_5("input-5", STRING, CHANNEL_INPUT5),
66 input_6("input-6", STRING, CHANNEL_INPUT6),
67 input_7("input-7", STRING, CHANNEL_INPUT7),
68 input_8("input-8", STRING, CHANNEL_INPUT8),
70 /* Protocol V2 notify tags */
71 selected_mode("selected-mode", STRING, CHANNEL_SELECTED_MODE),
72 selected_movie_music("selected-movie-music", STRING, CHANNEL_SELECTED_MOVIE_MUSIC),
73 mode_ref_stereo("mode-ref-stereo", STRING, CHANNEL_MODE_REF_STEREO),
74 mode_stereo("mode-stereo", STRING, CHANNEL_MODE_STEREO),
75 mode_music("mode-music", STRING, CHANNEL_MODE_MUSIC),
76 mode_movie("mode-movie", STRING, CHANNEL_MODE_MOVIE),
77 mode_direct("mode-direct", STRING, CHANNEL_MODE_DIRECT),
78 mode_dolby("mode-dolby", STRING, CHANNEL_MODE_DOLBY),
79 mode_dts("mode-dts", STRING, CHANNEL_MODE_DTS),
80 mode_all_stereo("mode-all-stereo", STRING, CHANNEL_MODE_ALL_STEREO),
81 mode_auto("mode-auto", STRING, CHANNEL_MODE_AUTO),
82 mode_surround("mode-surround", STRING, CHANNEL_MODE_SURROUND),
83 menu("menu", ON_OFF, CHANNEL_MENU),
84 menu_update("menu-update", STRING, CHANNEL_MENU_DISPLAY_PREFIX),
86 /* Protocol V3 notify tags */
87 keepAlive("keepAlive", NUMBER_TIME, LAST_SEEN_STATE_NAME),
88 goodBye("goodBye", GOODBYE, ""),
89 bar_update("bar-update", STRING, CHANNEL_BAR),
90 width("width", DIMENSIONLESS_DECIBEL, CHANNEL_WIDTH),
91 height("height", DIMENSIONLESS_DECIBEL, CHANNEL_HEIGHT),
93 /* Notify tag not in the documentation */
94 source_tuner("source-tuner", ON_OFF, ""),
97 unknown("unknown", UNKNOWN, "");
99 private final Logger logger = LoggerFactory.getLogger(EmotivaSubscriptionTags.class);
101 /* For error handling */
102 public static final String UNKNOWN_TAG = "unknown";
104 private final String name;
105 private final EmotivaDataType dataType;
106 private final String channel;
108 EmotivaSubscriptionTags(String name, EmotivaDataType dataType, String channel) {
110 this.dataType = dataType;
111 this.channel = channel;
114 public static boolean hasChannel(String name) {
116 EmotivaSubscriptionTags type = EmotivaSubscriptionTags.valueOf(name);
117 if (!type.channel.isEmpty()) {
120 } catch (IllegalArgumentException e) {
126 public static EmotivaSubscriptionTags fromChannelUID(String id) {
127 for (EmotivaSubscriptionTags value : values()) {
128 if (id.equals(value.getChannel())) {
132 return EmotivaSubscriptionTags.unknown;
135 public static EmotivaSubscriptionTags[] generalChannels() {
136 List<EmotivaSubscriptionTags> tags = new ArrayList<>();
137 for (EmotivaSubscriptionTags value : values()) {
138 if (value.channel.startsWith("general")) {
142 return tags.toArray(new EmotivaSubscriptionTags[0]);
145 public static EmotivaSubscriptionTags[] nonGeneralChannels() {
146 List<EmotivaSubscriptionTags> tags = new ArrayList<>();
147 for (EmotivaSubscriptionTags value : values()) {
148 if (!value.channel.startsWith("general")) {
152 return tags.toArray(new EmotivaSubscriptionTags[0]);
155 public static EmotivaSubscriptionTags[] speakerChannels() {
156 List<EmotivaSubscriptionTags> tags = new ArrayList<>();
157 for (EmotivaSubscriptionTags value : values()) {
158 if (value.getDataType().equals(DIMENSIONLESS_DECIBEL)) {
162 return tags.toArray(new EmotivaSubscriptionTags[0]);
165 public static List<EmotivaSubscriptionTags> noSubscriptionToChannel() {
166 return List.of(goodBye);
169 public String getName() {
173 public String getEmotivaName() {
174 String retVal = name.replaceAll("-", "_");
175 logger.debug("Converting OH channel '{}' to Emotiva command '{}'", name, retVal);
179 public EmotivaDataType getDataType() {
183 public String getChannel() {