]> git.basschouten.com Git - openhab-addons.git/commitdiff
[oppo] Fix setting verbose mode at startup issue (#10306)
authormlobstein <michael.lobstein@gmail.com>
Sat, 13 Mar 2021 19:21:27 +0000 (13:21 -0600)
committerGitHub <noreply@github.com>
Sat, 13 Mar 2021 19:21:27 +0000 (20:21 +0100)
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
bundles/org.openhab.binding.oppo/README.md
bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoConnector.java
bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/discovery/OppoDiscoveryService.java
bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java

index f3a36a167892d8bd0436d7ebf7a7f2e389c517c7..a55bfff47795381f75277a3e31f620018e7a6902 100644 (file)
@@ -44,7 +44,7 @@ The thing has the following configuration parameters:
 | Address          | host         | Host name or IP address of the Oppo player or serial over IP device.                                                             | host name or ip           |
 | Port             | port         | Communication port for using serial over IP. Leave blank if using direct IP connection to the player.                            | ip port number            |
 | Serial Port      | serialPort   | Serial port to use for directly connecting to the Oppo player                                                                    | a comm port name          |
-| Verbose Mode     | verboseMode  | (Optional) If true, the player will send time updates every second. If set false, the binding polls the player every 15 seconds. | Boolean; default false    |
+| Verbose Mode     | verboseMode  | (Optional) If true, the player will send time updates every second. If set false, the binding polls the player every 10 seconds. | Boolean; default false    |
 
 Some notes:
 
@@ -54,9 +54,10 @@ Some notes:
 * The UDP-20x series should be fully functional over direct IP connection but this was not able to be tested by the developer.
 * As previously noted, when using verbose mode, the player will send time code messages once per second while playback is ongoing.
 * Be aware that this could cause performance impacts to your openHAB system.
-* In non-verbose (the default), the binding will poll the player every 15 seconds to update play time, track and chapter information instead.
+* In non-verbose (the default), the binding will poll the player every 10 seconds to update play time, track and chapter information instead.
 * In order for the direct IP connection to work while the player is turned off, the Standby Mode setting must be set to "Quick Start" in the Device Setup menu.
 * Likewise if the player is turned off, it may not be discoverable by the Binding's discovery scan.
+* If the player is switched off when the binding first starts up or if power to the player is ever interrupted, up to 30 seconds may elapse before the binding begins to update when the player is switched on.
 * If you experience any issues using the binding, first ensure that the player's firmware is up to date with the latest available version (especially on the older models).
 * For the older models, some of the features in the control API were added after the players were shipped.
 * Available HDMI modes for BDP-83 & BDP-9x: AUTO, SRC, 1080P, 1080I, 720P, SDP, SDI
index 8055763283351b0e3cf455914c56ace9f777e706..0ec5691a106d777fc0a133abe388e7f8cb44591d 100644 (file)
@@ -12,6 +12,8 @@
  */
 package org.openhab.binding.oppo.internal.communication;
 
+import static org.openhab.binding.oppo.internal.OppoBindingConstants.*;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -38,6 +40,8 @@ public abstract class OppoConnector {
     private static final Pattern QRY_PATTERN = Pattern.compile("^@(Q[A-Z0-9]{2}|VUP|VDN) OK (.*)$");
     private static final Pattern STUS_PATTERN = Pattern.compile("^@(U[A-Z0-9]{2}) (.*)$");
 
+    private static final String OK_ON = "@OK ON";
+    private static final String OK_OFF = "@OK OFF";
     private static final String NOP_OK = "@NOP OK";
     private static final String NOP = "NOP";
     private static final String OK = "OK";
@@ -249,6 +253,17 @@ public abstract class OppoConnector {
             return;
         }
 
+        // Before verbose mode 2 & 3 get set, these are the responses to QPW
+        if (OK_ON.equals(message)) {
+            dispatchKeyValue(QPW, ON);
+            return;
+        }
+
+        if (OK_OFF.equals(message)) {
+            dispatchKeyValue(QPW, OFF);
+            return;
+        }
+
         // Player sent an OK response to a query: @QDT OK DVD-VIDEO or a volume update @VUP OK 100
         Matcher matcher = QRY_PATTERN.matcher(message);
         if (matcher.find()) {
index 947c477e575b798f8dd379b061b69038ee84f54c..878aa03f9ed4ffa3d43f534c371ca43148d5554b 100644 (file)
@@ -148,7 +148,7 @@ public class OppoDiscoveryService extends AbstractDiscoveryService {
                                 multiSocket.receive(receivePacket);
 
                                 String message = new String(receivePacket.getData(), StandardCharsets.US_ASCII).trim();
-                                if (message != null && message.length() > 0) {
+                                if (message.length() > 0) {
                                     messageReceive(message);
                                 }
                             } catch (SocketTimeoutException e) {
@@ -158,7 +158,7 @@ public class OppoDiscoveryService extends AbstractDiscoveryService {
 
                         multiSocket.close();
                     } catch (IOException e) {
-                        if (!e.getMessage().contains("No IP addresses bound to interface")) {
+                        if (e.getMessage() != null && !e.getMessage().contains("No IP addresses bound to interface")) {
                             logger.debug("OppoDiscoveryService IOException: {}", e.getMessage(), e);
                         }
                     }
index 3a1c86289743685df51148c9409165cc9d347269..c85182ec610a6ac680aa635bc4f6abfd83ae4a82 100644 (file)
@@ -69,8 +69,8 @@ import org.slf4j.LoggerFactory;
 @NonNullByDefault
 public class OppoHandler extends BaseThingHandler implements OppoMessageEventListener {
     private static final long RECON_POLLING_INTERVAL_SEC = 60;
-    private static final long POLLING_INTERVAL_SEC = 15;
-    private static final long INITIAL_POLLING_DELAY_SEC = 10;
+    private static final long POLLING_INTERVAL_SEC = 10;
+    private static final long INITIAL_POLLING_DELAY_SEC = 5;
     private static final long SLEEP_BETWEEN_CMD_MS = 100;
 
     private static final Pattern TIME_CODE_PATTERN = Pattern
@@ -221,7 +221,7 @@ public class OppoHandler extends BaseThingHandler implements OppoMessageEventLis
      *
      * @param channelUID the channel sending the command
      * @param command the command received
-     * 
+     *
      */
     @Override
     public void handleCommand(ChannelUID channelUID, Command command) {
@@ -615,6 +615,8 @@ public class OppoHandler extends BaseThingHandler implements OppoMessageEventLis
                         closeConnection();
                     } else {
                         updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
+                        isInitialQuery = false;
+                        isVbModeSet = false;
                     }
                 }
             }
@@ -647,19 +649,21 @@ public class OppoHandler extends BaseThingHandler implements OppoMessageEventLis
 
                 synchronized (sequenceLock) {
                     try {
-                        // the verbose mode must be set while the player is on
-                        if (isPowerOn && !isVbModeSet && !isBdpIP) {
-                            connector.sendCommand(OppoCommand.SET_VERBOSE_MODE, this.verboseMode);
-                            isVbModeSet = true;
-                            Thread.sleep(SLEEP_BETWEEN_CMD_MS);
+                        // Verbose mode 2 & 3 only do once until power comes on OR always for BDP direct IP
+                        if ((!isPowerOn && !isInitialQuery) || isBdpIP) {
+                            connector.sendCommand(OppoCommand.QUERY_POWER_STATUS);
                         }
 
-                        // If using direct serial connection, the query is done once after the player is turned on
-                        // - OR - if using direct IP connection on the 83/9x/10x, no unsolicited updates are sent
-                        // so we must query everything to know what changed.
-                        if ((isPowerOn && !isInitialQuery) || isBdpIP) {
-                            connector.sendCommand(OppoCommand.QUERY_POWER_STATUS);
-                            if (isPowerOn) {
+                        if (isPowerOn) {
+                            // the verbose mode must be set while the player is on
+                            if (!isVbModeSet && !isBdpIP) {
+                                connector.sendCommand(OppoCommand.SET_VERBOSE_MODE, this.verboseMode);
+                                isVbModeSet = true;
+                                Thread.sleep(SLEEP_BETWEEN_CMD_MS);
+                            }
+
+                            // Verbose mode 2 & 3 only do once OR always for BDP direct IP
+                            if (!isInitialQuery || isBdpIP) {
                                 isInitialQuery = true;
                                 OppoCommand.QUERY_COMMANDS.forEach(cmd -> {
                                     try {
@@ -670,34 +674,34 @@ public class OppoHandler extends BaseThingHandler implements OppoMessageEventLis
                                     }
                                 });
                             }
-                        }
 
-                        // for Verbose mode 2 get the current play back time if we are playing, otherwise just do NO_OP
-                        if ((VERBOSE_2.equals(this.verboseMode) && PLAY.equals(currentPlayMode))
-                                || (isBdpIP && isPowerOn)) {
-                            switch (currentTimeMode) {
-                                case T:
-                                    connector.sendCommand(OppoCommand.QUERY_TITLE_ELAPSED);
-                                    break;
-                                case X:
-                                    connector.sendCommand(OppoCommand.QUERY_TITLE_REMAIN);
-                                    break;
-                                case C:
-                                    connector.sendCommand(OppoCommand.QUERY_CHAPTER_ELAPSED);
-                                    break;
-                                case K:
-                                    connector.sendCommand(OppoCommand.QUERY_CHAPTER_REMAIN);
-                                    break;
-                            }
-                            Thread.sleep(SLEEP_BETWEEN_CMD_MS);
+                            // for Verbose mode 2 get the current play back time if we are playing, otherwise just do
+                            // NO_OP
+                            if ((VERBOSE_2.equals(this.verboseMode) && PLAY.equals(currentPlayMode)) || isBdpIP) {
+                                switch (currentTimeMode) {
+                                    case T:
+                                        connector.sendCommand(OppoCommand.QUERY_TITLE_ELAPSED);
+                                        break;
+                                    case X:
+                                        connector.sendCommand(OppoCommand.QUERY_TITLE_REMAIN);
+                                        break;
+                                    case C:
+                                        connector.sendCommand(OppoCommand.QUERY_CHAPTER_ELAPSED);
+                                        break;
+                                    case K:
+                                        connector.sendCommand(OppoCommand.QUERY_CHAPTER_REMAIN);
+                                        break;
+                                }
+                                Thread.sleep(SLEEP_BETWEEN_CMD_MS);
 
-                            // make queries to refresh total number of titles/tracks & chapters
-                            connector.sendCommand(OppoCommand.QUERY_TITLE_TRACK);
-                            Thread.sleep(SLEEP_BETWEEN_CMD_MS);
-                            connector.sendCommand(OppoCommand.QUERY_CHAPTER);
-                        } else if (!isBdpIP) {
-                            // verbose mode 3
-                            connector.sendCommand(OppoCommand.NO_OP);
+                                // make queries to refresh total number of titles/tracks & chapters
+                                connector.sendCommand(OppoCommand.QUERY_TITLE_TRACK);
+                                Thread.sleep(SLEEP_BETWEEN_CMD_MS);
+                                connector.sendCommand(OppoCommand.QUERY_CHAPTER);
+                            } else if (!isBdpIP) {
+                                // verbose mode 3
+                                connector.sendCommand(OppoCommand.NO_OP);
+                            }
                         }
 
                     } catch (OppoException | InterruptedException e) {