]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tivo] fix bugs with standby mode and channel parsing (#9964)
authormlobstein <michael.lobstein@gmail.com>
Tue, 26 Jan 2021 15:45:59 +0000 (09:45 -0600)
committerGitHub <noreply@github.com>
Tue, 26 Jan 2021 15:45:59 +0000 (16:45 +0100)
* fix some tivo binding bugs

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
* update search example rule

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
bundles/org.openhab.binding.tivo/README.md
bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java
bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java

index d5084b30d444a64def256d69812179562657ea1c..9361143295331e4626c662a7553e82a0fd0f4841 100644 (file)
@@ -52,7 +52,7 @@ All devices support the following channels:
 |-----------------|-----------------|---------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
 | channelSet      | Number (1-9999) | Current Channel - Request (SETCH)     | Displays the current channel number. When changed, tunes the DVR to the specified channel (unless a recording is in progress on all available tuners). The TiVo must be in Live TV mode for this command to work.                                                 |
 | channelForce    | Number (1-9999) | Current Channel - Forced (FORCECH)    | Displays the current channel number. When changed, tunes the DVR to the specified channel, **cancelling any recordings in progress if necessary** i.e. when all tuners are already in use / recording. The TiVo must be in Live TV mode for this command to work. |
-| menuTeleport    | String          | Change Special/Menu Screen (TELEPORT) | Change to one of the following TiVo menu screens: TIVO (Home), LIVE TV, GUIDE, NOW PLAYING (My Shows), NETFLIX.                                                                                                                                                   |
+| menuTeleport    | String          | Change Special/Menu Screen (TELEPORT) | Change to one of the following TiVo menu screens: TIVO (Home), LIVETV, GUIDE, NOWPLAYING (My Shows), SEARCH, NETFLIX.                                                                                                                                                   |
 | irCommand       | String          | Remote Control Button (IRCOMMAND)     | Send a simulated button push from the remote control to the TiVo. See Appendix A in document TCP Remote Protocol 1.1 for supported codes.                                                                                                                         |
 | kbdCommand      | String          | Keyboard Command (KEYBOARD)           | Sends a code corresponding to a keyboard key press to the TiVo e.g. A-Z. See Appendix A in document TCP Remote Protocol 1.1 for supported characters and special character codes.                                                                                 |
 | dvrStatus       | String          | TiVo Status                           | Action return code / channel information returned by the TiVo.                                                                                                                                                                                                    |
@@ -98,7 +98,7 @@ sitemap tivo label="Tivo Central" {
         Text        item=TiVo_Recording       label="Recording"    icon="screen"
         Switch      item=TiVo_IRCmd           label="Channel"      icon="screen"   mappings=["CHANNELDOWN"="CH -","CHANNELUP"="CH +"]
         Switch      item=TiVo_IRCmd           label="Media"        icon="screen"   mappings=["REVERSE"="⏪", "PAUSE"="⏸", "PLAY"="▶", /*(DVD TiVo only!) "STOP"="⏹",*/ "FORWARD"="⏩", "RECORD"="⏺" ]
-        Switch      item=TiVo_MenuScreen      label="Menus"        icon="screen"   mappings=["TIVO"="Home", "LIVETV"="Live Tv", "GUIDE"="Guide", "NOWPLAYING"="My Shows", "NETFLIX"="Netflix" ]
+        Switch      item=TiVo_MenuScreen      label="Menus"        icon="screen"   mappings=["TIVO"="Home", "LIVETV"="Live Tv", "GUIDE"="Guide", "NOWPLAYING"="My Shows", "NETFLIX"="Netflix", SEARCH="Search" ]
         Switch      item=TiVo_SetChannel      label="Fav TV"       icon="screen"   mappings=[2.1="CBS", 4.1="NBC", 7.1="ABC", 11.1="FOX", 5.2="AntennaTV"]            
         Switch      item=TiVo_IRCmd           label="Navigation"   icon="screen"   mappings=["UP"="˄", "DOWN"="˅", "LEFT"="<", "RIGHT"=">", "SELECT"="Select", "EXIT"="Exit" ]                
         Switch      item=TiVo_IRCmd           label="Actions"      icon="screen"   mappings=["ACTION_A"="Red","ACTION_B"="Green","ACTION_C"="Yellow","ACTION_D"="Blue"]
@@ -118,6 +118,8 @@ sitemap tivo label="Tivo Central" {
 ```
 NULL=Unknown
 -=Unknown
+rec-NULL=Unknown
+rec-=Unknown
 rec-0=Not Recording
 rec-1=Recording
 100=HBO
@@ -156,11 +158,9 @@ when
 then
     if (TiVo_KeyboardStr.state != NULL && TiVo_KeyboardStr.state.toString.length > 0) {
         
-        // Commands to get us to the TiVo/Home menu and select the search menu using the 'remote' number keys
-        sendCommand(TiVo_MenuScreen, "TIVO")
-        Thread::sleep(1500)
-        sendCommand(TiVo_KbdCmd, "NUM4")
-        Thread::sleep(1500)
+        // Command to get us to the TiVo search menu
+        sendCommand(TiVo_MenuScreen, "SEARCH")
+        Thread::sleep(1000)
         
         var i = 0
         var char txt = ""
@@ -189,6 +189,3 @@ then
 end
 
 ```
-
-* You may need to adjust the two `Thread::sleep(1500)` lines, depending on the performance of your TiVo
-* In testing, response times have varied considerably at different times of the day, etc. You may need to increase the delay until there is sufficient time added for the system to respond consistently to the 'remote control' menu commands.
index 8479e1b8653b6b873af7d1133f995dd71841c404..ea207afc7a9e4c2d2b6fc1016cf8368b5f3d400c 100644 (file)
@@ -129,15 +129,14 @@ public class TiVoHandler extends BaseThingHandler {
         TivoStatusData commandResult = null;
         logger.debug("handleCommand '{}' - {} found!", getThing().getUID(), commandKeyword);
         // Re-write command keyword if we are in STANDBY, as only IRCODE TIVO will wake the unit from
-        // standby mode
+        // standby mode, otherwise just execute the commands
         if (deviceStatus.getConnectionStatus() == ConnectionStatus.STANDBY && commandKeyword.contentEquals("TELEPORT")
                 && commandParameter.contentEquals("TIVO")) {
             String command = "IRCODE " + commandParameter;
             logger.debug("TiVo '{}' TELEPORT re-mapped to IRCODE as we are in standby: '{}'", getThing().getUID(),
                     command);
-        }
-        // Execute command
-        if (commandKeyword.contentEquals("FORCECH") || commandKeyword.contentEquals("SETCH")) {
+            commandResult = tivoConnection.get().cmdTivoSend(command);
+        } else if (commandKeyword.contentEquals("FORCECH") || commandKeyword.contentEquals("SETCH")) {
             commandResult = chChannelChange(commandKeyword, commandParameter);
         } else {
             commandResult = tivoConnection.get().cmdTivoSend(commandKeyword + " " + commandParameter);
index d53717bd6f50f9818624cfdf23f24b3b3fcf3458..7057e5f46358e9484921ef3684ae1719d1d58f29 100644 (file)
@@ -141,8 +141,12 @@ public class TivoStatusProvider {
         logger.debug(" statusParse '{}' - running on string '{}'", tivoConfigData.getCfgIdentifier(), rawStatus);
 
         if (rawStatus.contentEquals("COMMAND_TIMEOUT")) {
-            // Ignore COMMAND_TIMEOUT, they occur a few seconds after each successful command, just return existing
-            // status again
+            // If connection status was UNKNOWN, COMMAND_TIMEOUT indicates the Tivo is alive, so update the status
+            if (this.tivoStatusData.getConnectionStatus() == ConnectionStatus.UNKNOWN) {
+                return new TivoStatusData(false, -1, -1, false, "COMMAND_TIMEOUT", false, ConnectionStatus.ONLINE);
+            }
+            // Otherwise ignore COMMAND_TIMEOUT, they occur a few seconds after each successful command, just return
+            // existing status again
             return this.tivoStatusData;
         } else {
             switch (rawStatus) {
@@ -181,7 +185,7 @@ public class TivoStatusProvider {
                 chNum = Integer.parseInt(matcher.group(1).trim());
                 logger.debug(" statusParse '{}' - parsed channel '{}'", tivoConfigData.getCfgIdentifier(), chNum);
             }
-            if (matcher.groupCount() == 2) {
+            if (matcher.groupCount() == 2 && matcher.group(2) != null) {
                 subChNum = Integer.parseInt(matcher.group(2).trim());
                 logger.debug(" statusParse '{}' - parsed sub-channel '{}'", tivoConfigData.getCfgIdentifier(),
                         subChNum);
@@ -252,6 +256,8 @@ public class TivoStatusProvider {
                         tivoConfigData.getCfgIdentifier());
                 StreamReader streamReader = this.streamReader;
                 if (streamReader != null && streamReader.isAlive()) {
+                    // Send a newline to poke the Tivo to verify it responds with INVALID_COMMAND/COMMAND_TIMEOUT
+                    streamWriter.println("\r");
                     return true;
                 }
             } else {