API Addition: dev.stateListOrDisplayStateIdChanged() method
Posted: Sat Nov 12, 2011 5:48 pm
The release version of v5.0.0 has a new device instance method: stateListOrDisplayStateIdChanged().
Background: 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.
Problem: The Indigo Server only calls getDeviceStateList() and getDeviceDisplayStateId() at very specific times, like when a plugin device dialog is dismissed. Plugins that need to refresh a device state list definition or display state ID at other times couldn't.
Solution: Call stateListOrDisplayStateIdChanged() on the device instance you need refreshed. 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.
Example usage:
Background: 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.
Problem: The Indigo Server only calls getDeviceStateList() and getDeviceDisplayStateId() at very specific times, like when a plugin device dialog is dismissed. Plugins that need to refresh a device state list definition or display state ID at other times couldn't.
Solution: Call stateListOrDisplayStateIdChanged() on the device instance you need refreshed. 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.
Example usage:
- Code: Select all
dev = indigo.devices["den fixture"]
dev.stateListOrDisplayStateIdChanged() # will call getDeviceStateList() and getDeviceDisplayStateId()