Determining the class of a device

Posted on
Sat Jan 07, 2017 9:58 am
kmarkley offline
Posts: 185
Joined: Nov 15, 2016

Determining the class of a device

I'm sure this is easy, but I can't seem to find it in the wiki.

I know I can get devices of a particular class:
Code: Select all
indigo.devices.iter(filter="indigo.relay")


But if I already have a device instance, how do I determine if it's the kind I'm interested in?:
Code: Select all
def deviceUpdated(self, oldDev, newDev):
    if ???newDev is indigo.relay???:
        do stuff

Posted on
Sat Jan 07, 2017 10:06 am
kmarkley offline
Posts: 185
Joined: Nov 15, 2016

Re: Determining the class of a device

D'oh:
Code: Select all
type(newDev)

I need more coffee.

Posted on
Sat Jan 07, 2017 11:59 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Determining the class of a device

It depends on what you are doing, but I most often end up using isinstance:

Code: Select all
            if isinstance(dev, indigo.DimmerDevice):     # or indigo.RelayDevice, indigo.ThermostatDevice, etc.

Note that dimmer is a subclass of relay, so if you check for indigo.DimmerDevice then it will return true for all dimmers and relays.

Image

Posted on
Sat Jan 07, 2017 2:09 pm
kmarkley offline
Posts: 185
Joined: Nov 15, 2016

Re: Determining the class of a device

Even better. Thank you.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 10 guests