Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| indigo_5_documentation:plugin_extending_tutorial [2011/09/19 23:19] – [Indigo Server Plugin Tutorial] jay | indigo_5_documentation:plugin_extending_tutorial [2025/02/18 20:36] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Indigo Server Plugin Tutorial ====== | ||
| + | |||
| + | Note most of the code examples below are calling methods on the object //'' | ||
| + | |||
| + | // | ||
| + | |||
| + | ===== Indigo Plugin SDK Source Code Examples ===== | ||
| + | |||
| + | The Indigo Plugin SDK ([[http:// | ||
| + | |||
| + | Included in the SDK are examples that create plugin based relay, dimmer, thermostat, and custom devices. Also included is an example showing basic Indigo database traversal, how to catch low-level X10/INSTEON messages, and how to create an Indigo telnet server using the python twisted framework. | ||
| + | |||
| + | We'll be adding additional example plugins in the future. | ||
| + | |||
| + | ===== Other Useful Plugin Source Code Examples ===== | ||
| + | |||
| + | Additionally, | ||
| + | |||
| + | ^ Plugin task ^ Plugin that illustrates an approach | ||
| + | | Parsing XML from an IP source | ||
| + | | Integrating with native Mac Apps | Airfoil | ||
| + | | Sending RS232 (serial port & network serial port) Commands | ||
| + | | Reading RS232 (serial & network serial port) Input | EasyDAQ | ||
| + | | Interacting with an IMAP mail server | ||
| + | | Creating custom devices with states | ||
| + | | Creating custom actions | ||
| + | | Creating custom events | ||
| + | |||
| + | Each of these plugins is installed by default with Indigo 5 - in the ''/ | ||
| + | |||
| + | Both the SDK example plugins and the plugins included with Indigo above are great places to see working examples of plugins and their source code. | ||
| + | |||
| + | ===== How to Read and Write Plugin Preferences ===== | ||
| + | |||
| + | FIXME (useful, but very rough notes below) | ||
| + | |||
| + | * Per plugin prefs file is automatically managed (created, loaded, updated). | ||
| + | * Pref values can be numbers, boolean, strings, indigo.Dict() or indigo.List(). | ||
| + | * Key values defined in PluginConfig.xml are automatically mapped into the plugin' | ||
| + | self.pluginPrefs[" | ||
| + | </ | ||
| + | * Plugin can also insert other values into its pluginPrefs space (not just values shown in the plugin' | ||
| + | * To read a preference value access its key:< | ||
| + | someVal = self.pluginPrefs[" | ||
| + | indigo.server.log(" | ||
| + | </ | ||
| + | * To update a preference value assign it a new value:< | ||
| + | self.pluginPrefs[" | ||
| + | </ | ||
| + | |||
| + | ===== How to Add Plugin Metadata to Devices, Trigger & Scheduled Events, Variables, etc. ===== | ||
| + | |||
| + | FIXME (useful, but very rough notes below) | ||
| + | |||
| + | * Most Indigo database objects support the addition of plugin specific metadata. | ||
| + | * Every plugin has its own name space accessed via the object instance //'' | ||
| + | * The pluginProps dictionary supports numbers, boolean, strings, indigo.Dict() or indigo.List(). | ||
| + | * Example adding new plugin metadata to the Device "den fixture":< | ||
| + | dev = indigo.devices[" | ||
| + | newProps = dev.pluginProps | ||
| + | newProps[" | ||
| + | newProps[" | ||
| + | newProps[" | ||
| + | newProps[" | ||
| + | dev.replacePluginPropsOnServer(newProps) | ||
| + | </ | ||
| + | * Example reading the plugin specific property onCycles from the Device "den fixture":< | ||
| + | dev = indigo.devices[" | ||
| + | onCycles = dev.pluginProps[" | ||
| + | indigo.server.log(" | ||
| + | </ | ||
| + | * Example incrementing by 1 the plugin specific property onCycles for the Device "den fixture":< | ||
| + | dev = indigo.devices[" | ||
| + | newProps = dev.pluginProps | ||
| + | newProps[" | ||
| + | dev.replacePluginPropsOnServer(newProps) | ||
| + | |||
| + | dev = indigo.devices[" | ||
| + | onCycles = dev.pluginProps[" | ||
| + | indigo.server.log(" | ||
| + | </ | ||
| + | * Plugins have read-only access to other plugin metadata via //'' | ||
| + | * Plugins have read/write access to their own metadata space. | ||
| + | |||
| + | ===== Creating a Custom Plugin Device ===== | ||
| + | |||
| + | FIXME (useful, but very rough notes below) | ||
| + | |||
| + | * Plugin Device state and properties are defined in Devices.xml. | ||
| + | * Properties define the user configurable options for a device instance, and are specified in the //''< | ||
| + | * States are specified in the Devices.xml //''< | ||
| + | * States defined in Devices.xml are automatically shows in the Trigger Event ''// | ||
| + | * States are read-only for everyone except the plugin that defines the device' | ||
| + | * Plugins should update a device state after it has sent commands to hardware, or somehow received new state information from hardware. Example that increments the plugin defined state ''// | ||
| + | dev = indigo.devices[" | ||
| + | dev.updateStateOnServer(" | ||
| + | </ | ||
| + | * Plugins should subclass ''// | ||
| + | def deviceStartComm(self, | ||
| + | self.easydaq.startCommThread(dev) | ||
| + | |||
| + | def deviceStopComm(self, | ||
| + | self.easydaq.stopCommThread(dev) | ||
| + | </ | ||
| + | * Calls to ''// | ||
| + | |||
| + | ===== Creating a Custom Plugin Trigger Event ===== | ||
| + | |||
| + | FIXME Explain Events.xml. Show example plugin subclasses of functions: triggerStartProcessing, | ||
| + | |||
| + | ===== Monitoring Device State Changes from a Plugin ===== | ||
| + | |||
| + | FIXME (useful, but very rough notes below) | ||
| + | |||
| + | FIXME Give examples of using indigo.devices.subscribeToChanges() and plugin subclasses of functions: deviceCreated, | ||
| + | |||
| + | ===== Monitoring Changes to Variables, Triggered & Scheduled Events, Action Groups, and Control Pages ===== | ||
| + | |||
| + | FIXME (useful, but very rough notes below) | ||
| + | |||
| + | FIXME Give examples of using indigo.*.subscribeToChanges() and plugin subclasses of functions: variableCreated, | ||