Dynamic List Filters

Posted on
Thu Dec 17, 2020 11:49 am
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Dynamic List Filters

At the risk of coming across like a baby that just discovered his own foot, I wanted to highlight an approach to using dynamic list filters that I only just discovered. I was under the (mistaken) impression that filters were limited to Indigo objects and object attributes (i.e., "supports.onState" and the like). It turns out that you can send "anything" in the filter field to the callback method.

In this example, Source1 and Source2 list all Indigo devices. Value1 and Value2 show the device states for the selected Indigo devices and both Value1 and Value2 refer to the same callback, with only the filter being different. By using the filter value, you can return different things to different controls using one callback. So why not use that to tell the callback which value to return to each control? Turns out this works really well. Who knew?

Devices.xml
Code: Select all
<Field id="Source1" type="menu">
   <Label>Source 1:</Label>
   <List class="self" filter="" method="some_method" dynamicReload="true"/>
   <CallbackMethod>callback_method</CallbackMethod>
</Field>

<Field id="Value1" type="menu">
   <Label>Value:</Label>
   <List class="self" filter="Source1" method="another_method" dynamicReload="true"/>
</Field>

<Field id="Source2" type="menu">
   <Label>Source 1:</Label>
   <List class="self" filter="" method="some_method" dynamicReload="true"/>
   <CallbackMethod>callback_method</CallbackMethod>
</Field>

<Field id="Value2" type="menu">
   <Label>Value:</Label>
   <List class="self" filter="Source2" method="another_method" dynamicReload="true"/>
</Field>
plugin.py
Code: Select all
def some_method(self, filter="", values_dict=None, type_id="", target_id=0):
   return [(dev.id, dev.name) for dev in indigo.devices.iter()]

def another_method(self, filter="", values_dict=None, type_id="", target_id=0):
   return [(state, state) for state in indigo.devices[values_dict[filter]].states]
(The example code is modified from working code, but may contain errors.)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Dec 17, 2020 1:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 16820
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Dynamic List Filters

Yeah, the filter param is super useful. I use it in the Action Collection to implement (somewhat) pluggable brand-specific actions for Z-Wave devices (Homeseer was first, Inovelli and Zooz next). I can then use a single callback function in the plugin that examines the filter and uses that to dispatch to the correct module.function. Pretty slick actually, I can encapsulate everything in one file for each vendor.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Dec 17, 2020 4:32 pm
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Dynamic List Filters

In one of my plugins, I have what amounts to eight copies of the same callback--one each for eight controls. It'll be nice to pare that back to just one.

It was the filter="stuff" example in the docs that got me to think about it differently.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests