Skip to content

Commit 214323b

Browse files
committed
Implement search channel
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
1 parent 8672051 commit 214323b

6 files changed

Lines changed: 71 additions & 21 deletions

File tree

bundles/org.openhab.binding.tivo/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ All devices support the following channels:
6060
| irCommand | String | Remote Control Button (IRCOMMAND) | Send a simulated button push from the remote control to the TiVo. See below for available IR COMMANDS. |
6161
| 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. |
6262
| dvrStatus | String | TiVo Status | Action return code / channel information returned by the TiVo. |
63+
| search | String | Search | Write-only channel that executes a search in the Tivo menu for the given string. |
6364

6465
- To change channels simply post/send the number of the channel to channelSet or channelForce. For OTA channels, a decimal for the sub-channel must be specified (ie: 2.1), for all others just send the channel as a whole number (ie: 100).
6566
- Keyboard commands must currently be issued one character at a time to the item (this is how the TiVo natively supports this command).
@@ -144,7 +145,7 @@ Number TiVo_ForceChannel "Force Channel" {channel="tivo:sckt:Living_Roo
144145
Number TiVo_Recording "Recording [MAP(tivo.map):rec-%s]" {channel="tivo:sckt:Living_Room:isRecording"}
145146
String TiVo_IRCmd "Ir Cmd" {channel="tivo:sckt:Living_Room:irCommand"}
146147
String TiVo_KbdCmd "Keyboard Cmd" {channel="tivo:sckt:Living_Room:kbdCommand"}
147-
String TiVo_KeyboardStr "Search String"
148+
String TiVo_SearchStr "Search String" {channel="tivo:sckt:Living_Room:search"}
148149
```
149150

150151
- The item `TiVo_SetChannelName` depends upon a valid `tivo.map` file to translate channel numbers to channel names. The openHAB **MAP** transformation service must also be installed.
@@ -169,7 +170,7 @@ sitemap tivo label="Tivo Central" {
169170
Switch item=TiVo_IRCmd label="Likes" icon="screen" mappings=["THUMBSUP"="Thumbs Up", "THUMBSDOWN"="Thumbs Down"]
170171
Switch item=TiVo_IRCmd label="Remote" icon="screen" mappings=["FIND_REMOTE"="Find Remote"]
171172
Switch item=TiVo_IRCmd label="Standby" icon="screen" mappings=["STANDBY"="Standby","TIVO"="Wake Up"]
172-
Input item=TiVo_KeyboardStr label="Search" staticIcon=zoom inputHint="text"
173+
Input item=TiVo_SearchStr label="Search" staticIcon=zoom inputHint="text"
173174
Buttongrid item=TiVo_IRCmd label="Remote Control" staticIcon=material:tv_remote buttons=[1:1:GUIDE="Guide", 1:2:TIVO="Home", 1:3:LIVETV="LiveTV", 2:2:UP="Up"=f7:arrowtriangle_up, 3:1:LEFT="Left"=f7:arrowtriangle_left, 3:2:SELECT="OK", 3:3:RIGHT="Right"=f7:arrowtriangle_right, 4:2:DOWN="Down"=f7:arrowtriangle_down, 5:1:BACK="Back", 5:2:INFO="Info", 5:3:EXIT="Exit", 6:1:THUMBSUP="Thumbs Up"=f7:hand_thumbsup, 6:3:CHANNELUP="Channel +", 7:1:THUMBSDOWN="Thumbs Down"=f7:hand_thumbsdown, 7:3:CHANNELDOWN="Channel -", 8:2:PLAY="Play"=f7:play, 9:1:REVERSE="Reverse"=f7:backward, 9:2:PAUSE="Pause"=f7:pause, 9:3:FORWARD="Forward"=f7:forward, 10:2:SLOW="Slow"=f7:play_circle, 11:1:REPLAY="Replay", 11:2:RECORD="Record"=f7:circle, 11:3:ADVANCE="Advance", 12:1:ACTION_A="A (Yellow)", 12:2:ACTION_B="B (Blue)", 12:3:ACTION_C="C (Red)", 13:1:ACTION_D="D (Green)", 13:2:CC_ON="CC On", 13:3:CC_OFF="CC Off", 14:1:NUM1="1", 14:2:NUM2="2", 14:3:NUM3="3", 15:1:NUM4="4", 15:2:NUM5="5", 15:3:NUM6="6", 16:1:NUM7="7", 16:2:NUM8="8", 16:3:NUM9="9", 17:1:CLEAR="Clear", 17:2:NUM0="0", 17:3:ENTER="Enter", 18:1:STANDBY="Stand By", 18:3:FIND_REMOTE="Find Remote"]
174175
}
175176
}
@@ -201,7 +202,7 @@ etc...
201202

202203
### `tivo.rules` Example
203204

204-
- The following rule shows how a string change to the item `TiVo_KeyboardStr` is split into individual characters and sent to the Tivo.
205+
- The following rule is no longer needed as the `search` channel implements this functionality internally. It remains here as a reference for sending KEYBOARD commands to the Tivo.
205206

206207
```java
207208
rule "TiVo Search"

bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoBindingConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ public class TiVoBindingConstants {
4242
public static final String CHANNEL_TIVO_IRCMD = "irCommand";
4343
public static final String CHANNEL_TIVO_KBDCMD = "kbdCommand";
4444
public static final String CHANNEL_TIVO_STATUS = "dvrStatus";
45+
public static final String CHANNEL_TIVO_SEARCH = "search";
4546

4647
// List of all configuration Properties
4748
public static final String CONFIG_HOST = "host";
4849
public static final String CONFIG_PORT = "tcpPort";
50+
51+
public static final String KEYBOARD = "KEYBOARD";
4952
}

bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import static org.openhab.binding.tivo.internal.TiVoBindingConstants.*;
1616

17+
import java.util.Locale;
1718
import java.util.Optional;
1819
import java.util.concurrent.ScheduledFuture;
1920
import java.util.concurrent.TimeUnit;
@@ -82,30 +83,60 @@ public void handleCommand(ChannelUID channelUID, Command command) {
8283
TivoStatusData currentStatus = tivoConnection.get().getServiceStatus();
8384
String commandKeyword = "";
8485

85-
String commandParameter = command.toString().toUpperCase();
86+
String commandParameter = command.toString().toUpperCase(Locale.ENGLISH);
8687
if (command instanceof RefreshType) {
8788
// Future enhancement, if we can come up with a sensible set of actions when a REFRESH is issued
8889
logger.debug("TiVo '{}' skipping REFRESH command for channel: '{}'.", getThing().getUID(),
8990
channelUID.getId());
9091
return;
9192
}
9293

93-
switch (channelUID.getId()) {
94-
case CHANNEL_TIVO_CHANNEL_FORCE:
95-
commandKeyword = "FORCECH";
96-
break;
97-
case CHANNEL_TIVO_CHANNEL_SET:
98-
commandKeyword = "SETCH";
99-
break;
100-
case CHANNEL_TIVO_TELEPORT:
101-
commandKeyword = "TELEPORT";
102-
break;
103-
case CHANNEL_TIVO_IRCMD:
104-
commandKeyword = "IRCODE";
105-
break;
106-
case CHANNEL_TIVO_KBDCMD:
107-
commandKeyword = "KEYBOARD";
108-
break;
94+
// Handle search command
95+
if (CHANNEL_TIVO_SEARCH.equals(channelUID.getId())) {
96+
if (commandParameter.isBlank()) {
97+
logger.debug("Search string was blank");
98+
return;
99+
}
100+
101+
try {
102+
sendCommand("TELEPORT", "SEARCH", currentStatus);
103+
Thread.sleep(1000);
104+
105+
for (int i = 0; i < commandParameter.length(); i++) {
106+
final String srchChar = commandParameter.substring(i, i + 1);
107+
108+
if (srchChar.matches("[A-Z]")) {
109+
sendCommand(KEYBOARD, srchChar, currentStatus);
110+
} else if (srchChar.matches("[0-9]")) {
111+
sendCommand(KEYBOARD, "NUM" + srchChar, currentStatus);
112+
} else if (" ".equals(srchChar)) {
113+
sendCommand(KEYBOARD, "SPACE", currentStatus);
114+
} else {
115+
logger.debug("Search character not supported: {}", srchChar);
116+
}
117+
}
118+
} catch (InterruptedException e) {
119+
// TiVo handler disposed or openHAB exiting, do nothing
120+
}
121+
return;
122+
} else {
123+
switch (channelUID.getId()) {
124+
case CHANNEL_TIVO_CHANNEL_FORCE:
125+
commandKeyword = "FORCECH";
126+
break;
127+
case CHANNEL_TIVO_CHANNEL_SET:
128+
commandKeyword = "SETCH";
129+
break;
130+
case CHANNEL_TIVO_TELEPORT:
131+
commandKeyword = "TELEPORT";
132+
break;
133+
case CHANNEL_TIVO_IRCMD:
134+
commandKeyword = "IRCODE";
135+
break;
136+
case CHANNEL_TIVO_KBDCMD:
137+
commandKeyword = KEYBOARD;
138+
break;
139+
}
109140
}
110141
try {
111142
sendCommand(commandKeyword, commandParameter, currentStatus);

bundles/org.openhab.binding.tivo/src/main/resources/OH-INF/i18n/tivo.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,5 @@ channel-type.tivo.menuTeleport.state.option.GUIDE = GUIDE
102102
channel-type.tivo.menuTeleport.state.option.NOWPLAYING = NOWPLAYING
103103
channel-type.tivo.menuTeleport.state.option.SEARCH = SEARCH
104104
channel-type.tivo.menuTeleport.state.option.NETFLIX = NETFLIX
105+
channel-type.tivo.search.label = Search
106+
channel-type.tivo.search.description = Executes a search in the Tivo menu for the given string (write-only)

bundles/org.openhab.binding.tivo/src/main/resources/OH-INF/thing/thing-types.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
<channel id="irCommand" typeId="irCommand"/>
2121
<channel id="kbdCommand" typeId="kbdCommand"/>
2222
<channel id="dvrStatus" typeId="dvrStatus"/>
23+
<channel id="search" typeId="search"/>
2324
</channels>
2425

2526
<properties>
26-
<property name="thingTypeVersion">1</property>
27+
<property name="thingTypeVersion">2</property>
2728
</properties>
2829

2930
<representation-property>host</representation-property>
@@ -211,4 +212,10 @@
211212
<description>Action return code / channel information returned by the TiVo. Type: String (read-only)</description>
212213
<state readOnly="true" pattern="%s"/>
213214
</channel-type>
215+
<channel-type id="search">
216+
<item-type>String</item-type>
217+
<label>Search</label>
218+
<description>Executes a search in the Tivo menu for the given string (write-only)</description>
219+
<autoUpdatePolicy>veto</autoUpdatePolicy>
220+
</channel-type>
214221
</thing:thing-descriptions>

bundles/org.openhab.binding.tivo/src/main/resources/OH-INF/update/update.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
<type>tivo:channelForce</type>
1313
</update-channel>
1414
</instruction-set>
15+
16+
<instruction-set targetVersion="2">
17+
<add-channel id="search">
18+
<type>tivo:search</type>
19+
</add-channel>
20+
</instruction-set>
1521
</thing-type>
1622

1723
</update:update-descriptions>

0 commit comments

Comments
 (0)