@@ -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