Find device by address

Posted on
Tue Mar 21, 2017 11:05 pm
drbrain offline
Posts: 9
Joined: Dec 31, 2009

Find device by address

I'm working on a plugin to support Hunter Douglas PowerView shades.

I would like to automatically create the shade devices after you add a hub device.

The PowerView hub keeps consistent IDs for the shades which I can store in the address field.

Do I have to iterate through
Code: Select all
indigo.devices
by hand to find a device that was already created to avoid
Code: Select all
exception in deviceStartComm(Hub): NameNotUniqueError
?

If I have to iterate is there a way to restrict my search to only devices for my plugin type?

Posted on
Wed Mar 22, 2017 1:47 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Find device by address

I'm not at my desk right now and can't find exact syntax, but you can say the following, once you get right syntax:

Code: Select all
if not in indigo.devices(self)


This will iterate all devices by your plugin, or self.shadeDevType will iterate all shadeDevType devices (whatever typeID you've given them).


Sent from my iPhone using Tapatalk

Posted on
Wed Mar 22, 2017 9:00 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Find device by address

First, I encourage you to not take the automatic creation approach. The standard device creation flow in Indigo is for the user to create each device themselves. There are a few cases where we automatically create devices, but that's generally sub-devices (devices that have a very tight binding between them, like multifunction sensors). There are a few plugins that auto-create devices when enabled (or when a hub-like instance is added) and it always seems to cause users some confusion. Another problem is that it often becomes necessary for your user to recreate or resync one of your devices and if there is no option for editing/creating a single device that becomes more tricky. Remember that links between triggers, conditions, actions, and control pages are via the device ID so just creating a new version of a device will break all of those ties.

Second, any device that your plugin creates will have deviceStartComm() called for it. A good design pattern is to keep a list of those "active" devices in your plugin so that you don't have to ask the server every time you want one. The will, of course, get stale over time, so if you use state information you'll want to refresh the instance.

Finally, if you need to iterate over your own devices check out the Iterating Object Lists section of the docs.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 22, 2017 12:38 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Find device by address

Hehe, if I'd had time this morning I was going to say that about auto-creation!

Somebody, probably you, said the same to me about my Evohome plugin. :-)


Sent from my iPhone using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 12 guests