*/
package org.openhab.binding.oppo.internal.communication;
+import static java.util.Map.entry;
+import static org.openhab.binding.oppo.internal.OppoBindingConstants.*;
+
import java.util.HashMap;
import java.util.Map;
ZOOM_MODE.put("11", "1/3");
ZOOM_MODE.put("12", "1/4");
}
+
+ // map to lookup disc type
+ public static final Map<String, String> DISC_TYPE = Map.ofEntries(entry("BDMV", "BD-MV"),
+ entry("DVDV", "DVD-VIDEO"), entry("DVDA", "DVD-AUDIO"), entry("SACD", "SACD"), entry("CDDA", "CDDA"),
+ entry("HDCD", "HDCD"), entry("DATA", "DATA-DISC"), entry("VCD2", "VCD2"), entry("SVCD", "SVCD"),
+ entry("UHBD", "UHBD"), entry("UNKN", UNKNOW_DISC));
+
+ // map to lookup playback status
+ public static final Map<String, String> PLAYBACK_STATUS = Map.ofEntries(entry("DISC", "NO DISC"),
+ entry("LOAD", "LOADING"), entry("OPEN", "OPEN"), entry("CLOS", "CLOSE"), entry("PLAY", "PLAY"),
+ entry("PAUS", "PAUSE"), entry("STOP", "STOP"), entry("HOME", "HOME MENU"), entry("MCTR", "MEDIA CENTER"),
+ entry("SCSV", "SCREEN SAVER"), entry("MENU", "DISC MENU"));
}
// example: 0 BD-PLAYER, split off just the number
updateChannelState(CHANNEL_SOURCE, updateData.split(SPACE)[0]);
break;
- case UPL:
- // we got the playback status update, throw it away and call the query because the text output
- // is better
- connector.sendCommand(OppoCommand.QUERY_PLAYBACK_STATUS);
- break;
case QTK:
// example: 02/10, split off both numbers
String[] track = updateData.split(SLASH);
updateChannelState(CHANNEL_TOTAL_CHAPTER, chapter[1]);
}
break;
+ case UPL:
case QPL:
+ // try to normalize the slightly different responses between UPL and QPL
+ String playStatus = OppoStatusCodes.PLAYBACK_STATUS.get(updateData);
+ if (playStatus == null) {
+ playStatus = updateData;
+ }
+
// if playback has stopped, we have to zero out Time, Title and Track info and so on manually
- if (NO_DISC.equals(updateData) || LOADING.equals(updateData) || OPEN.equals(updateData)
- || CLOSE.equals(updateData) || STOP.equals(updateData)) {
+ if (NO_DISC.equals(playStatus) || LOADING.equals(playStatus) || OPEN.equals(playStatus)
+ || CLOSE.equals(playStatus) || STOP.equals(playStatus)) {
updateChannelState(CHANNEL_CURRENT_TITLE, ZERO);
updateChannelState(CHANNEL_TOTAL_TITLE, ZERO);
updateChannelState(CHANNEL_CURRENT_CHAPTER, ZERO);
updateChannelState(CHANNEL_AUDIO_TYPE, UNDEF);
updateChannelState(CHANNEL_SUBTITLE_TYPE, UNDEF);
}
- updateChannelState(CHANNEL_PLAY_MODE, updateData);
+ updateChannelState(CHANNEL_PLAY_MODE, playStatus);
+
+ // ejecting the disc does not produce a UDT message, so clear disc type manually
+ if (OPEN.equals(playStatus) || NO_DISC.equals(playStatus)) {
+ updateChannelState(CHANNEL_DISC_TYPE, UNKNOW_DISC);
+ currentDiscType = BLANK;
+ }
// if switching to play mode and not a CD then query the subtitle type...
// because if subtitles were on when playback stopped, they got nulled out above
// and the subtitle update message ("UST") is not sent when play starts like it is for audio
- if (PLAY.equals(updateData) && !CDDA.equals(currentDiscType)) {
+ if (PLAY.equals(playStatus) && !CDDA.equals(currentDiscType)) {
connector.sendCommand(OppoCommand.QUERY_SUBTITLE_TYPE);
}
- currentPlayMode = updateData;
+ currentPlayMode = playStatus;
break;
case QRP:
updateChannelState(CHANNEL_REPEAT_MODE, updateData);
updateChannelState(CHANNEL_ZOOM_MODE, updateData);
break;
case UDT:
- // we got the disc type status update, throw it away
- // and call the query because the text output is better
- connector.sendCommand(OppoCommand.QUERY_DISC_TYPE);
case QDT:
- currentDiscType = updateData;
- updateChannelState(CHANNEL_DISC_TYPE, updateData);
+ // try to normalize the slightly different responses between UDT and QDT
+ final String discType = OppoStatusCodes.DISC_TYPE.get(updateData);
+ currentDiscType = (discType != null ? discType : updateData);
+ updateChannelState(CHANNEL_DISC_TYPE, currentDiscType);
break;
case UAT:
// we got the audio type status update, throw it away
// and call the query because the text output is better
+ // wait before sending the command to give the player time to catch up
+ Thread.sleep(SLEEP_BETWEEN_CMD_MS);
connector.sendCommand(OppoCommand.QUERY_AUDIO_TYPE);
break;
case QAT:
case UST:
// we got the subtitle type status update, throw it away
// and call the query because the text output is better
+ // wait before sending the command to give the player time to catch up
+ Thread.sleep(SLEEP_BETWEEN_CMD_MS);
connector.sendCommand(OppoCommand.QUERY_SUBTITLE_TYPE);
break;
case QST:
logger.debug("onNewMessageEvent: unhandled key {}, value: {}", key, updateData);
break;
}
- } catch (OppoException e) {
+ } catch (OppoException | InterruptedException e) {
logger.debug("Exception processing event from player: {}", e.getMessage());
}
}