[ANSWERED]: add a state to an existing device

Posted on
Fri Aug 29, 2014 9:52 pm
kw123 offline
User avatar
Posts: 8382
Joined: May 12, 2013
Location: Dallas, TX

[ANSWERED]: add a state to an existing device

Hoe do I add a state to an existing device? It looks as if the states are copied from the device.xml file at creation.
If I later would like to add a state (adding a state in device.xml), the only way I found that works is to delete and recreate the device.
Are there indigo calls that re-read the xml file and add a state?

thx
Karl

Posted on
Sat Aug 30, 2014 1:01 am
autolog offline
Posts: 3991
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: add a state to an existing device

kw123 wrote:
How do I add a state to an existing device? ...


Coincidentally, I was only reading about this yesterday :)

Take a look at Device Base Class Instance Methods.

There is a method stateListOrDisplayStateIdChanged() which has the description
Plugins can subclass the method getDeviceStateList() to provide dynamic state list definition information. The default implementation provides a static solution by retrieving the device state list definition from the Devices.xml file. Likewise, the method getDeviceDisplayStateId() can be used to dynamically determine which device state should be displayed in the State column of the main device table UI. The problem is that the Indigo Server only calls getDeviceStateList() and getDeviceDisplayStateId() at very specific times, like when a plugin device dialog is dismissed. So, call stateListOrDisplayStateIdChanged() on the device instance you need refreshed at any time and Indigo will then automatically call your plugin's getDeviceStateList() and getDeviceDisplayStateId() methods (or use the base implementation of looking up the list from Devices.xml) and update the Indigo Server (and all clients). This is particularly useful for plugin updates that need to add new device states to existing device instances created by older versions. In this case, the plugin will need to update the device instances by calling stateListOrDisplayStateIdChanged(). A likely place to do this type of instance level upgrading is inside your plugin's deviceStartComm() method.

Hope this helps :)

Posted on
Sat Aug 30, 2014 4:56 am
kw123 offline
User avatar
Posts: 8382
Joined: May 12, 2013
Location: Dallas, TX

Re: add a state to an existing device

thx

Posted on
Wed Dec 09, 2015 3:02 am
jeremyjjr offline
Posts: 104
Joined: Sep 10, 2013
Location: St Albans, UK

Re: [ANSWERED]: add a state to an existing device

Hi,

I've been trying to figure out how to add a new device state to an existing device after updating a plugin I'm developing. I've looked at the notes in the developer documentation and also scoured existing plug-ins for examples but am not finding any simple code that shows how to accomplish this.

Does anyone have any sample code they could share that might help?

Thanks,

J.

Posted on
Thu Dec 10, 2015 7:54 am
kw123 offline
User avatar
Posts: 8382
Joined: May 12, 2013
Location: Dallas, TX

Re: [ANSWERED]: add a state to an existing device

1. add the new state to the devices.xml file
2. add
Code: Select all
def deviceStartComm(self, dev):
     dev.stateListOrDisplayStateIdChanged()
     return
to your plugin

that should do it

Karl

Posted on
Thu Dec 10, 2015 10:09 am
jeremyjjr offline
Posts: 104
Joined: Sep 10, 2013
Location: St Albans, UK

Re: [ANSWERED]: add a state to an existing device

Oh so simple! Thank you!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests