Notification of new device creation

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Notification of new device creation

Post by berkinet »

Is there a call Indigo can make to a plugin to inform the plugin of the creation of a new device?
nsheldon
Posts: 2469
Joined: Mon Aug 09, 2010 2:12 pm
Location: CA
Contact:

Re: Notification of new device creation

Post by nsheldon »

It appears that the "deviceCreated" method is called, and can be overridden by your plugin, whenever a device that was owned by your plugin is created. The method is described here.
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Notification of new device creation

Post by jay (support) »

Note that in Indigo 6 deviceCreated() is called before your config dialog has a chance to run. We're a bit behind in the documentation, but you can use the new dev.configured property inside the deviceUpdated() method to see if your config dialog has run on the device at least one time.

The main place we recommend looking for devices is in deviceStartComm - though obviously that doesn't necessarily serve all purposes.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Re: Notification of new device creation

Post by berkinet »

Thanks... for now deviceCreated and the related calls meets my need. The issue here is that the plugin maintains a list of devices that should be polled at regular intervals. For simplicity I keep the device info in an internal dict. But, I need to update that dict if a device is added/changed or deleted. So, all I was looking for was notification that a change had been made - which, thanks to nsheldon for telling me and Jay and Matt for creating, I now have.
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Notification of new device creation

Post by jay (support) »

You should manage that in deviceStartComm() and deviceStopComm() since you don't want to poll devices that aren't enabled... ;)
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Re: Notification of new device creation

Post by berkinet »

Yup, I could do that. But, since I only poll the thermostats energy n minutes its pretty easy to just use runConcurrentThread and then loop over the devices once each time the method loops.
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Notification of new device creation

Post by jay (support) »

You're missing the point - if the user disables communication to the thermostat, they expect that it won't be communicated with.

You can do exactly what you're talking about doing - you just manage the contents of the device list from deviceStartComm() and deviceStopComm(). In deviceStartComm, you add it to the list of devices to poll, in deviceStopComm you remove it from the list. That way, the user can disable the thermostat if they need to power it down, move it, etc., and they won't get a stream of communication errors when you try to poll a device that isn't there.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Re: Notification of new device creation

Post by berkinet »

Really, I think I get it. But, since I added support for deviceUpdated. I get notified when communications are enabled and disabled as well as for device config changes.
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Notification of new device creation

Post by jay (support) »

OK - just trying to help make it less complex... ;)
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
Locked

Return to “Extending Indigo with Plugins and Python”