[tivo] fix bugs with standby mode and channel parsing (#9964)

* 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>
This commit is contained in:
mlobstein 2021-01-26 09:45:59 -06:00 committed by GitHub
parent 89f5538f25
commit a49b3487fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 17 deletions

View 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. | | 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. | | 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. | | 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. | | 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. | | 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" 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="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_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_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="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"] 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 NULL=Unknown
-=Unknown -=Unknown
rec-NULL=Unknown
rec-=Unknown
rec-0=Not Recording rec-0=Not Recording
rec-1=Recording rec-1=Recording
100=HBO 100=HBO
@ -156,11 +158,9 @@ when
then then
if (TiVo_KeyboardStr.state != NULL && TiVo_KeyboardStr.state.toString.length > 0) { 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 // Command to get us to the TiVo search menu
sendCommand(TiVo_MenuScreen, "TIVO") sendCommand(TiVo_MenuScreen, "SEARCH")
Thread::sleep(1500) Thread::sleep(1000)
sendCommand(TiVo_KbdCmd, "NUM4")
Thread::sleep(1500)
var i = 0 var i = 0
var char txt = "" var char txt = ""
@ -189,6 +189,3 @@ then
end 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.

View File

@ -129,15 +129,14 @@ public class TiVoHandler extends BaseThingHandler {
TivoStatusData commandResult = null; TivoStatusData commandResult = null;
logger.debug("handleCommand '{}' - {} found!", getThing().getUID(), commandKeyword); 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 // 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") if (deviceStatus.getConnectionStatus() == ConnectionStatus.STANDBY && commandKeyword.contentEquals("TELEPORT")
&& commandParameter.contentEquals("TIVO")) { && commandParameter.contentEquals("TIVO")) {
String command = "IRCODE " + commandParameter; String command = "IRCODE " + commandParameter;
logger.debug("TiVo '{}' TELEPORT re-mapped to IRCODE as we are in standby: '{}'", getThing().getUID(), logger.debug("TiVo '{}' TELEPORT re-mapped to IRCODE as we are in standby: '{}'", getThing().getUID(),
command); command);
} commandResult = tivoConnection.get().cmdTivoSend(command);
// Execute command } else if (commandKeyword.contentEquals("FORCECH") || commandKeyword.contentEquals("SETCH")) {
if (commandKeyword.contentEquals("FORCECH") || commandKeyword.contentEquals("SETCH")) {
commandResult = chChannelChange(commandKeyword, commandParameter); commandResult = chChannelChange(commandKeyword, commandParameter);
} else { } else {
commandResult = tivoConnection.get().cmdTivoSend(commandKeyword + " " + commandParameter); commandResult = tivoConnection.get().cmdTivoSend(commandKeyword + " " + commandParameter);

View File

@ -141,8 +141,12 @@ public class TivoStatusProvider {
logger.debug(" statusParse '{}' - running on string '{}'", tivoConfigData.getCfgIdentifier(), rawStatus); logger.debug(" statusParse '{}' - running on string '{}'", tivoConfigData.getCfgIdentifier(), rawStatus);
if (rawStatus.contentEquals("COMMAND_TIMEOUT")) { if (rawStatus.contentEquals("COMMAND_TIMEOUT")) {
// Ignore COMMAND_TIMEOUT, they occur a few seconds after each successful command, just return existing // If connection status was UNKNOWN, COMMAND_TIMEOUT indicates the Tivo is alive, so update the status
// status again 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; return this.tivoStatusData;
} else { } else {
switch (rawStatus) { switch (rawStatus) {
@ -181,7 +185,7 @@ public class TivoStatusProvider {
chNum = Integer.parseInt(matcher.group(1).trim()); chNum = Integer.parseInt(matcher.group(1).trim());
logger.debug(" statusParse '{}' - parsed channel '{}'", tivoConfigData.getCfgIdentifier(), chNum); 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()); subChNum = Integer.parseInt(matcher.group(2).trim());
logger.debug(" statusParse '{}' - parsed sub-channel '{}'", tivoConfigData.getCfgIdentifier(), logger.debug(" statusParse '{}' - parsed sub-channel '{}'", tivoConfigData.getCfgIdentifier(),
subChNum); subChNum);
@ -252,6 +256,8 @@ public class TivoStatusProvider {
tivoConfigData.getCfgIdentifier()); tivoConfigData.getCfgIdentifier());
StreamReader streamReader = this.streamReader; StreamReader streamReader = this.streamReader;
if (streamReader != null && streamReader.isAlive()) { 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; return true;
} }
} else { } else {