Awesome, thanks! I am swamped this week, but will try to get these changes in later in the week or over the weekend.
Ahh don’t you hate it when real life gets in the way!
One addition that I just stumbled across tonight. When you are saving the appId and appName, they can come in with non-breaking spaces, which causes issues if you are later trying to compare with values typed in Home Remote that have a regular space. So, I modified the block of code to look like this:
//Need to replace nbsp with a regular space
var re = new RegExp(String.fromCharCode(160), "g");
apps = {};
appsElement.elements.forEach(function (node) {
var appId = node.attributes.id.replace(re, " ");
var appName = node.text.replace(re, " ");
apps[appName] = appId;
});
Hopefully that makes sense. It was a weird issue, where I was trying to use HomeRemote to call a specific input, and it was not working. I ended up using charCodeAt to look at each character to see what was going on. Mystery solved.
Thanks, Bill! I saw you added TvChannel.ProgramTitle
as well–very cool! I’m still doing some fine-tuning and testing before making another release of the plugin, but I had a quick question for you, @bill: in onConnect()
, we store off the apps list into a plugin global variable (that was how it was done in your original plugin). I was thinking about it some more and, in theory, someone could add apps and then that list would be out of date until the remote was restarted. Is there any particular reason not to retrieve and regenerate the apps list every time onConnect()
is called? Or is my understanding of how state is maintained incorrect?
That’s correct. You can update in onConnect if you want. I’m sure any performance improvement by skipping the call is negligible.
I’ve integrated the various changes discussed above, sometimes taking my best guess on how to handle a few situations. Please let me know if you have any problems with the latest version. One thing, @amingle, I wanted to call out is that I put in the valid signal check, but rather than clearing the ProgramTitle
, I set it to “NO SIGNAL”. I’m open to change how that works, but I though it was a little more explicit/informative than simply clearing ProgramTitle
.
In addition, one thing that is kind of bugging me is the WOL/PowerToggle
portion of the code. Since the plugin does not currently “know” power state of the device, it in theory could send WOL for a PowerToggle
even if you are trying to turn it off. That isn’t super-likely to happen because the WOL only gets sent if the Roku doesn’t respond within a second to the power command, but it’s just kind of ugly and I would recommend staying away from PowerToggle
if possible.
It does raise a broader question, however, of how Switch
should be handled in plugins. I’ve never incorporated it into any of mine because I use the explicit PowerOn
/PowerOff
Media Commands, but I thought I’d see, @bill, if you had any thoughts on the preferred convention for the Switch
capability? I’m guessing in order to implement it correctly, you would have to continuously poll for power state information? If we did have reliable power state info, the WOL/PowerToggle
thing could probably be cleaned up some more.
I probably wouldn’t worry about incorporating the Switch
capability because, yeah, there really isn’t a reliable way to determine the current power state. None that I’m aware of anyway.
This all looks good to me. I don’t see any issues with how you implemented anything here. Thanks for your work on this.
Came across an interesting part of this plugin this week. I changed the above line to be:
device.SupportedInputSources = Object.keys(apps).sort();
This way, the list of Supported Input Sources is alphabetized (handy for a dropdown menu).
However, the default JS sort() is case sensitive. I ran into this with discovery+, which has a lower case app name. So, I changed it to:
device.SupportedInputSources = Object.keys(apps).sort(
function(a, b) {
if (a.toLowerCase() < b.toLowerCase()) return -1;
if (a.toLowerCase() > b.toLowerCase()) return 1;
return 0;
}
);
Now, the list is alphabetized regardless of case.
That’s an interesting point about sorting the sources, I assume you put them in a ComboBox
to get the drop-down list? I haven’t actually used that control before. @bill, I’m curious, from a design/HR usability standpoint, does it make more sense to add a sort capability to the control itself (with an option to do a case-insensitive sort)? That way you could do it for any set of inputs (or other values you were putting in the ComboBox
, regardless of whether they were from a plugin device or a built-in device. Obviously the plugin device code can always be modified, but with a built-in device, there’s no way to get a sorted list if you wanted to, correct? Is that a reasonable thing to put in a feature request?
That’s correct. I can switch inputs using the combo box options. Interesting thought about putting that at the designer level instead of within the plugin.
I don’t know if this is something I want to add to the ComboBox control. At least not now anyway. If the user really wants to customize the order they could just manually assign the Items instead of Binding to the ItemsSource. That or they can customize the plugin.
But manually assigning would only work if the item contents were known ahead of time, right? Otherwise, if the data from the binding varied over time and was not necessarily predictable, that wouldn’t be an option, would it? I’ve never really done anything with the ComboBox, so I may be off base here/not understanding exactly what you’re proposing.
Correct. I don’t know that there’s anything wrong with that. My preference would be to have the plugin do the sorting. Default to whichever sort method the majority of users want. You could also add a sort option Setting to your plugin. Have them choose their sort method when they create the plugin. It’s really no different than prompting them for the IP address of the Roku device.
Good evening. New to setting up my remote and I’m kind of confused as to how I use this plugin. I added the plugin and when I open the new Roku page it works - but wondering how I add the keyboard.
There is a sample keyboard control in the project at the bottom of the first post of the MCE Controller Plugin (I updated the main post here to make that a little more clear). If you open that project in the HR Designer, you can copy and paste it into your own project. As noted, it is set up to be used in a PageBrowser control, so you would add a PageBrowser to the page you want to have the keyboard, point it at the KeyboardControl page, and then set the Device property to be your Roku device name (most likely “Roku”). There is also a portrait mode one in this thread as well.
@hotelfoxtrotnovember, great Roku plugin. I’m wanting to create a “Netflix” button for quick access. I’ve set the binding to MY_ROKU.InputSource with a value of 12 (Netflix AppID), but am getting a 404 error. Am I using this incorrectly? Many thanks.
Hi @Styxman and thanks! I’ll be honest, I’m not actually in a position to test the behavior of the plugin at the moment (just moved to a new house), but I think you would actually assign the app’s name to MY_ROKU.InputSource
rather than the AppID. From a quick look, I believe that’s what the code is expecting, as it makes it a little more user friendly and hides having to track down AppIDs. This isn’t a feature I ever used myself–it existed in the original plugin and I just cleaned up that code with some additional help from @amingle, who could probably confirm the proper way to use the InputSource
for launching apps.
One thing you could try doing is binding MY_ROKU.SupportedInputSources
to a combo box control and that should actually display all of the apps (by name) available. You would then want to use the name of the app exactly as it appears in that list to pass to InputSource
. I believe that would answer your question, but as I said, I unfortunately am not in a position to test it myself at the moment.
If you’re still having trouble, please let me know and we’ll try to figure something else out!
Thanks for the response. You are absolutely correct…InputSource is expecting the name (not appID). I put Netflix as the value and all is well. Thanks again.
Brand new to Home Remote programming, but roku plugin seems to work great. Thank you.
At a loss to find command to send the “Option” command, designated “*” on Roku remote.
Suggestions?
Thanks
I’m not able to test it right now (my new theater is still in, but almost done with, the planning stage, so hopefully soon ), but I had *
bound to Roku.MediaCommand = Info
on my remote, so I’m 99% sure that’s what you’re looking for. Hope that helps and glad the plugin is working for you!