Skip to content

Commit

Permalink
[tivo] fix bugs with standby mode and channel parsing (#9964)
Browse files Browse the repository at this point in the history
* fix some tivo binding bugs

Signed-off-by: Michael Lobstein <[email protected]>

* update search example rule

Signed-off-by: Michael Lobstein <[email protected]>
  • Loading branch information
mlobstein authored Jan 26, 2021
1 parent 89f5538 commit a49b348
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
17 changes: 7 additions & 10 deletions bundles/org.openhab.binding.tivo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down Expand Up @@ -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"]
Expand All @@ -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
Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ private void sendCommand(String commandKeyword, String commandParameter, TivoSta
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ private TivoStatusData statusParse(String rawStatus) {
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) {
Expand Down Expand Up @@ -181,7 +185,7 @@ private TivoStatusData statusParse(String rawStatus) {
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);
Expand Down Expand Up @@ -252,6 +256,8 @@ public boolean connTivoConnect() throws InterruptedException {
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 {
Expand Down

0 comments on commit a49b348

Please sign in to comment.