Another example, from the Lutron plugin:
- Code: Select all
###### STATUS REQUEST ######
elif action.deviceAction == indigo.kDeviceAction.RequestStatus:
if dev.deviceTypeId == RA_PHANTOM_BUTTON:
phantom_button = dev.pluginProps[PROP_BUTTON]
integration_id = dev.pluginProps[PROP_REPEATER]
sendCmd = ("?DEVICE," + str(int(integration_id)) + ","+ str(int(phantom_button)) + ",9,")
elif dev.deviceTypeId == RA_KEYPAD:
keypad = dev.pluginProps[PROP_KEYPAD]
keypadButton = dev.pluginProps[PROP_KEYPADBUT]
if (int(keypadButton) > 80):
sendCmd = ("?DEVICE," + keypad + "," + str(int(keypadButton)) + ",9")
else:
sendCmd = ("?DEVICE," + keypad + "," + str(int(keypadButton)+80) + ",9")
elif dev.deviceTypeId == RA_DIMMER:
integration_id = dev.pluginProps[PROP_ZONE]
sendCmd = ("?OUTPUT," + integration_id + ",1,")
elif dev.deviceTypeId == RA_SHADE:
integration_id = dev.pluginProps[PROP_SHADE]
sendCmd = ("?OUTPUT," + integration_id + ",1,")
elif dev.deviceTypeId == RA_SWITCH:
integration_id = dev.pluginProps[PROP_SWITCH]
sendCmd = ("?OUTPUT," + integration_id + ",1,")
elif dev.deviceTypeId == RA_CCI:
self.logger.info(u"This device does not respond to Status Requests")
elif dev.deviceTypeId == RA_CCO:
cco = dev.pluginProps[PROP_CCO_INTEGRATION_ID]
ccoType = dev.pluginProps[PROP_CCO_TYPE]
if ccoType == "momentary":
self.logger.info(u"Momentary CCOs do not respond to Status Requests")
else:
sendCmd = ("?OUTPUT," + cco + ",1,")
if len(sendCmd):
self._sendCommand(sendCmd)
self.logger.debug(u"actionControlDimmerRelay sent: \"%s\" %s %s" % (dev.name, dev.onState, sendCmd))
As it turns out, these are unnecessarily complex due to a decision by the original author to segregate the different device types with different keys in pluginProps. But changing them would require updating all existing devices on the fly, which I haven't tackled yet.