Skip to content

Commit b5d753b

Browse files
authored
[oppo] Set playback status channels to UNDEF when Thing is off or offline (#20488)
* Update play_mode when Thing is off or offline Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
1 parent 28c136d commit b5d753b

3 files changed

Lines changed: 37 additions & 13 deletions

File tree

bundles/org.openhab.binding.oppo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The following channels are available:
9999
| time_display | Number:Time | The playback time elapsed/remaining in seconds (ReadOnly) |
100100
| current_title | Number | The current title or track number playing (ReadOnly) |
101101
| total_title | Number | The total number of titles or tracks on the disc (ReadOnly) |
102-
| current_chapter | Number | The current chapter number (ReadOnly) |
102+
| current_chapter | Number | The current chapter number (ReadOnly) |
103103
| total_chapter | Number | The total number of chapters in the current title (ReadOnly) |
104104
| repeat_mode | String | Sets the current repeat mode (00-06) |
105105
| zoom_mode | String | Sets the current zoom mode (00-12) |

bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/OppoBindingConstants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public class OppoBindingConstants {
7676
public static final String OFF = "OFF";
7777
public static final String ONE = "1";
7878
public static final String ZERO = "0";
79-
public static final String UNDEF = "UNDEF";
8079
public static final String VERBOSE_2 = "2";
8180
public static final String VERBOSE_3 = "3";
8281
public static final String MUTE = "MUTE";

bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ public void handleCommand(ChannelUID channelUID, Command command) {
262262
if (command == OnOffType.OFF) {
263263
isPowerOn = false;
264264
isInitialQuery = false;
265+
if (!BLANK.equals(currentPlayMode)) {
266+
currentPlayMode = BLANK;
267+
clearStatusChannels(true);
268+
}
265269
}
266270
}
267271
break;
@@ -368,6 +372,11 @@ private synchronized boolean openConnection() {
368372
* Close the connection with the Oppo player
369373
*/
370374
private synchronized void closeConnection() {
375+
if (!BLANK.equals(currentPlayMode)) {
376+
currentPlayMode = BLANK;
377+
clearStatusChannels(true);
378+
}
379+
371380
if (connector.isConnected()) {
372381
connector.close();
373382
connector.removeEventListener(this);
@@ -434,7 +443,10 @@ public void onNewMessageEvent(OppoMessageEvent evt) {
434443
case QPW:
435444
updateChannelState(CHANNEL_POWER, updateData);
436445
if (OFF.equals(updateData)) {
437-
currentPlayMode = BLANK;
446+
if (!BLANK.equals(currentPlayMode)) {
447+
currentPlayMode = BLANK;
448+
clearStatusChannels(true);
449+
}
438450
isPowerOn = false;
439451
} else {
440452
isPowerOn = true;
@@ -443,7 +455,10 @@ public void onNewMessageEvent(OppoMessageEvent evt) {
443455
case UPW:
444456
updateChannelState(CHANNEL_POWER, ONE.equals(updateData) ? ON : OFF);
445457
if (ZERO.equals(updateData)) {
446-
currentPlayMode = BLANK;
458+
if (!BLANK.equals(currentPlayMode)) {
459+
currentPlayMode = BLANK;
460+
clearStatusChannels(true);
461+
}
447462
isPowerOn = false;
448463
isInitialQuery = false;
449464
} else {
@@ -493,13 +508,7 @@ public void onNewMessageEvent(OppoMessageEvent evt) {
493508
if (NO_DISC.equals(currentPlayMode) || LOADING.equals(currentPlayMode)
494509
|| OPEN.equals(currentPlayMode) || CLOSE.equals(currentPlayMode)
495510
|| STOP.equals(currentPlayMode)) {
496-
updateChannelState(CHANNEL_CURRENT_TITLE, ZERO);
497-
updateChannelState(CHANNEL_TOTAL_TITLE, ZERO);
498-
updateChannelState(CHANNEL_CURRENT_CHAPTER, ZERO);
499-
updateChannelState(CHANNEL_TOTAL_CHAPTER, ZERO);
500-
updateChannelState(CHANNEL_TIME_DISPLAY, UNDEF);
501-
updateChannelState(CHANNEL_AUDIO_TYPE, UNDEF);
502-
updateChannelState(CHANNEL_SUBTITLE_TYPE, UNDEF);
511+
clearStatusChannels(false);
503512
}
504513
updateChannelState(CHANNEL_PLAY_MODE, currentPlayMode);
505514
updateState(CHANNEL_CONTROL,
@@ -590,6 +599,22 @@ public void onNewMessageEvent(OppoMessageEvent evt) {
590599
}
591600
}
592601

602+
/**
603+
* Clears the status channels
604+
*/
605+
private void clearStatusChannels(boolean clearPlayMode) {
606+
if (clearPlayMode) {
607+
updateChannelState(CHANNEL_PLAY_MODE, null);
608+
}
609+
updateChannelState(CHANNEL_CURRENT_TITLE, null);
610+
updateChannelState(CHANNEL_TOTAL_TITLE, null);
611+
updateChannelState(CHANNEL_CURRENT_CHAPTER, null);
612+
updateChannelState(CHANNEL_TOTAL_CHAPTER, null);
613+
updateChannelState(CHANNEL_TIME_DISPLAY, null);
614+
updateChannelState(CHANNEL_AUDIO_TYPE, null);
615+
updateChannelState(CHANNEL_SUBTITLE_TYPE, null);
616+
}
617+
593618
/**
594619
* Schedule the reconnection job
595620
*/
@@ -760,12 +785,12 @@ private void cancelPollingJob() {
760785
* @param channel the channel
761786
* @param value the value to be updated
762787
*/
763-
private void updateChannelState(String channel, String value) {
788+
private void updateChannelState(String channel, @Nullable String value) {
764789
if (!isLinked(channel)) {
765790
return;
766791
}
767792

768-
if (UNDEF.equals(value)) {
793+
if (value == null) {
769794
updateState(channel, UnDefType.UNDEF);
770795
return;
771796
}

0 commit comments

Comments
 (0)