Keeping track of discovered devices

Posted on
Thu Feb 14, 2019 2:55 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Keeping track of discovered devices

I expect only the hard core plugin developers will be interested in this one...

I've got a number of plugins that deal with what I call "discovered" devices. These are ones where the plugin has to build a list of logical devices and maintain it separately from the list of Indigo devices that get created. For instance, the Ecobee plugin gets a list of devices associated with the user's account when it authenticates with the Ecobee servers. Or, to be more accurate, every time it gets a status update from the servers, since the response always includes all associated devices.

But the user might not have created Indigo devices for all possible Ecobee devices. So the plugin maintains a list of "discovered" (or "known) Ecobee devices, which it uses to populate the appropriate popup in the device creation dialog. This same scenario plays out in a bunch of plugins.

So here's the issue I'm running into. I was maintaining the list based on calls to startComm and stopComm for each device. startComm put that device in an active list, and stopComm deleted it from the list. And when I needed a list of available devices for a device creation dialog, I would just remove active from known and what was left was available.

Now take the situation where an Indigo device has been disabled, but not deleted. It's not in active, so should the user be able to create a new Indigo device based on it? If not, how do I know if that device still exists, but isn't running. I guess I would need to search indigo.devices looking for everything of that device type?

How do you other developers handle this?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Feb 14, 2019 4:31 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Keeping track of discovered devices

I do it a couple of different ways: for the relatively simple case I do as you described - just keep up with it in start/stopComm. There are scenarios where this is the easiest way to handle it. It does mean that if you pop up a list of devices not yet created in Indigo you have to filter indigo.devices (using the iter() method and the appropriate filter) to find all of yours and perform the matching logic then (at list creation time). But for plugins where that just doesn't happen much it isn't a big deal.

For more complex scenarios, like when there are potentially a lot of devices associated with a plugin, then in the init method I cycle through my devices using the indigo.device iterator and add those to a dictionary that I maintain with a flag to indicate that the device is inactive. Then start/stop will just flip the flag as appropriate. That way when the user needs a list of available devices that don't have an Indigo device associated with it, you can easily compare the dict to the list you get from wherever and just present the ones not already associated with an Indigo device.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests

cron