Page 1 of 1

Implementing Status Request

PostPosted: Mon Apr 02, 2018 1:49 pm
by Colorado4Wheeler
What's the method to implement Status Request on non custom devices? I've looked a few times through the documentation and either I don't see it or I'm not getting it, I can turn off the button and that's what I have done until I can figure out how this gets implemented in the plugin.py. I even tore into a couple other plugins seeing if it was obvious and it wasn't.

Re: Implementing Status Request

PostPosted: Mon Apr 02, 2018 2:05 pm
by FlyingDiver
If you keep the status of the Indigo device up to date with the actual hardware, then this button doesn't do anything.

But if changes are pushed to Indigo from the hardware (and might not get received), and you can somehow interrogate the hardware to get the current status, that's what you do here.

Re: Implementing Status Request

PostPosted: Mon Apr 02, 2018 2:08 pm
by FlyingDiver
For instance, this is from the MyQ plugin:
Code: Select all
    def actionControlDevice(self, action, dev):

        if action.deviceAction == indigo.kDeviceAction.Unlock:
            self.logger.debug(u"actionControlDevice: \"%s\" Unlock" % dev.name)
            self.changeDevice(dev, kDoorOpen)

        elif action.deviceAction == indigo.kDeviceAction.Lock:
            self.logger.debug(u"actionControlDevice: \"%s\" Lock" % dev.name)
            self.changeDevice(dev, kDoorClose)

        elif action.deviceAction == indigo.kDeviceAction.RequestStatus:
            self.logger.debug(u"actionControlDevice: \"%s\" Request Status" % dev.name)
            self.getDevices()

        else:
            self.logger.error(u"actionControlDevice: \"%s\" Unsupported action requested: %s" % (dev.name, str(action)))



So for a status request, I just call the same routine I do other times that polls the MyQ servers for the current status.

Re: Implementing Status Request

PostPosted: Mon Apr 02, 2018 2:42 pm
by Colorado4Wheeler
FlyingDiver wrote:
        elif action.deviceAction == indigo.kDeviceAction.RequestStatus:
            self.logger.debug(u"actionControlDevice: \"%s\" Request Status" % dev.name)
            self.getDevices()


That's what I was looking for, thank you!

Re: Implementing Status Request

PostPosted: Mon Apr 02, 2018 2:57 pm
by FlyingDiver
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.

Re: Implementing Status Request

PostPosted: Mon Apr 02, 2018 3:08 pm
by Colorado4Wheeler
I've never implemented the device actions in a plugin before, it wasn't clear to me what the method name was supposed to be.

Code: Select all
def actionControlDevice(self, action, dev):