Setting SupportedInputSources outside of onConnect()

I’m working on a plugin that provides the MediaInputSource Capability and trying to dynamically set the SupportedInputSources Attribute. That is, rather than specifying the value for the Attribute in onConnect() like most other plugins seem to do, I’m setting it in onPoll() after querying information from the device. However, the assignment doesn’t seem to “take”/have any effect and the attribute is always empty, regardless of how I try to do the assignment (creating a new array, invoking push() on the existing Attribute, etc).

I’ve done a fair amount of searching and while I found a suggestion from @bill a rather long while ago in a somewhat different context to update the SupportInputSources Attribute dynamically, I haven’t found any evidence of anyone actually doing it.

Also, I don’t know if this is related, but when trying to bind SupportedInputSources in the Designer, it doesn’t show up as an option in the drop-down list, which I also thought was odd. I suspect there may be an inter-relationship in these problems, but I even tried deleting and re-creating the plugin and it didn’t have any different behavior.

You should be able to set that in onPoll. I think something in your plugin isn’t actually setting it or it’s getting set incorrectly. That’s handled no different than any other attribute. There’s nothing restricting you from setting it in onPoll. If you want me to help you troubleshoot, send me something simple & straightforward & I can try to figure out why it isn’t working for you.

That’s what I thought, @bill, and I was really surprised it wasn’t working. I’ve put together an HRP:

test1.hrp (131.8 KB)

that demonstrates the problem. I basically stripped down the plugin I was working on and put some simple logic into onPoll() to add to SupportedInputSources over time. This example shows the same behavior I was seeing in my main project, so hopefully it is helpful in troubleshooting.

There were a few related strange-behaviors I encountered in creating it. First, in the from-scratch HRP, when I added a new plugin from code, THR did not appear to create the Attributes associated with the specified Capabilities right away. I had to save, close, and re-load the HRP for them to show up. Second, I note that even after doing that, SupportedInputSources still does not show up in the list for device bindings. This latter point I suspect is the core of the problem I’m seeing, but I can’t figure why it is happening. I’m going to feel really dumb if it is a typo, but while I think that could be the case, I can’t find it anywhere.

In addition, while it is commented out, there is a portion in onConnect() that demonstrates the problem I ran into with the AudioSoundMode Capability / SupportedSoundModes Attribute. Any thoughts on that issue would also be appreciated (just uncomment those lines and the plugin will crash with the error on startup).

Thanks!

HFN

I just tested & looked at your code. This has nothing to do with onConnect or onPoll. It’s that instead of assigning a new value to the attribute you are trying to push a new value onto the existing attribute.

        // This line of code will not update the device attribute
        device.SupportedInputSources.push(profileNum);

You need to actually reassign the value to the attribute. Array Push does work if that’s what you want to do but you’ll need to do something like this:

var inputSourcesVariable = [];
              
function onPoll() {
    inputSourcesVariable.push(profileNum);        
    device.SupportedInputSources = inputSourcesVariable;
}

See the attached example

test2.hrp (132.4 KB)

1 Like

Awesome, Bill, thanks for digging into this! I will try to test it out in my plugin this weekend, but I’m sure this will do the trick!

@bill just to close the loop on this–everything is now working as expected in terms of populating SupportedInputSources. However, SupportedInputSources is still not appearing in the drop-down list in the Designer as an Attribute you can bind to. If you type it in manually, it works, but why isn’t it in drop-down list? I’m seeing similar behavior for the Roku plugin as well, which makes me think this is more Designer-wide than plugin specific.

I think I kept it hidden due to the fact that not all integrations which support the MediaInputSource capability support SupportedInputSources. I’ll go ahead & enable it though so it shows in the next release. For future reference:

These integrations support it:
Harmony
HomeAssistant
Plugin
SmartThings
LG(WebOSTV)

These integrations do not support it:
Denon/Marantz
Onkyo
Yamaha

1 Like