Hi,
I like automation and have a couple of relay cards that I have written a C application to control. My amplifiers do not have 12V trigger or remote controls (mono blocks), so I plan on controlling them by switching on/off power with the relays.
What I then plan on doing is making a plugin for Plex so I can use both the media center and the iOS client to turn on/off the amps. 
I have made a working plugin:
<br />
import os<br />
<br />
PLUGIN_PREFIX = '/photos/practical'<br />
NAME = 'Practical'<br />
ART = 'art-default.jpg'<br />
ICON = 'icon-default.png'<br />
<br />
cmd = [["Power on amplifiers", "/bin/amps_on"],["Power off amplifiers", "/bin/amps_off"]]<br />
<br />
def Start():<br />
Plugin.AddPrefixHandler(PLUGIN_PREFIX, MainMenu, NAME, ICON, ART)<br />
Plugin.AddViewGroup("List", viewMode="List", mediaType="items")<br />
# Set defaults<br />
MediaContainer.content = 'Items'<br />
MediaContainer.art = R(ART)<br />
MediaContainer.title1 = NAME<br />
MediaContainer.viewGroup = 'List'<br />
DirectoryItem.thumb = R(ICON)<br />
<br />
def MainMenu():<br />
dir = MediaContainer(viewMode="List")<br />
for i in range(len(cmd)):<br />
dir.Append(Function(DirectoryItem(RunCommand, L(cmd*[0]), subtitle=None, summary=None), cmdnum = i))<br />
return dir<br />
<br />
def RunCommand(sender, cmdnum = 0):<br />
Log('RunCommand: %d' % cmdnum)<br />
os.system(cmd[cmdnum][1])<br />
return MessageContainer("Success!", L(""))<br />
So, basicly, it is a MainMenu with DirectoryItems and my *plan* is that when I hit enter on one of these items, the command will be run and the message "Success" will be displayed.
This is indeed working, however:
On iOS the behavior is the following:
1. Navigate to plugin
2. Click on "Power on amplifiers"
3. The message "No items to display - This directory appears to be empty." is shown.. The command is run though, so this is OK!
In the Plex Media Center, the following happens:
1. Navigate to the plugin
2. The menu is shown, and the selected DirectoryItem's method is called (because it is selected), causing the "Power on amplifiers" command to be run since this is the top most item.
3. Each time I navigate the menu (up/down), the RunCommand method is called without me hitting enter. It will also run when hitting enter, but then the success message is shown as intended.
So, basically what I want is either
a ) Make the method not being called when navigating the menu (just when hitting enter)
b ) Determine in the RunCommand method that the menu item has been entered, and not just selected. (The "sender" object is the same in both circumstances, so it is not possible to use that one I think).
Any ideas?
(PS: Yes, I know that this is perhaps not what a "Channel" is intended to do. But there's not any other way, or is there?)