View unanswered posts | View active topics It is currently Fri Sep 10, 2010 7:26 am



Reply to topic  [ 5 posts ] 
 RESTful url device toggle 
Author Message

Joined: Sep 16, 2009
Posts: 50
Post RESTful url device toggle
It has bugged me for a while that the restful interface does not have a toggle, only on/off. I figured out how to add toggle.

In the directory /Library/Application Support/Perceptive Automation/Indigo 4/IndigoWebServer/indigopy

In the file devicesreqhandler.py:

Under the stanza:
Code: Select all
                   #######
                        if device.typeSupportsOnOff:
                                isOn = kw.get('isOn', None)
                                if isOn is not None:
                                        isOn = isOn.lower() in [kTrueStr, u"yes", u"1"]
                                        if not onlyChanges or isOn != device.isOn:
                                                if isOn:
                                                        cherrypy.server.indigoDb.DeviceTurnOn(cherrypy.server.indigoConn, elem_name, cherrypy.request.remote.better_ip)
                                                else:
                                                        cherrypy.server.indigoDb.DeviceTurnOff(cherrypy.server.indigoConn, elem_name, cherrypy.request.remote.better_ip)

                        ######



Add the modifed block:

Code: Select all

## chris
                        if device.typeSupportsOnOff:
                                Toggle = kw.get('Toggle', None)
                                if Toggle is not None:
                                        Toggle = Toggle.lower() in [kTrueStr, u"yes", u"1"]
                                        if not onlyChanges or Toggle != device.Toggle:
                                                if Toggle:
                                                        cherrypy.server.indigoDb.DeviceToggleOnOff(cherrypy.server.indigoConn, elem_name, cherrypy.request.remote.better_ip)
                                                else:
                                                        cherrypy.server.indigoDb.DeviceToggleOnOff(cherrypy.server.indigoConn, elem_name, cherrypy.request.remote.better_ip)

                        ######
## chris



and in indigodb.py:

After the stanza:

Code: Select all

        def DeviceTurnOff(self, indigoConn, device, requestOrigin = None):
                if not self._allowControlPages:
                        raise ControlDisabled
                indigoConn.CheckConnection()

                logStr = "request to turn off device \"" + device + "\""
                if requestOrigin:
                        logStr += " from " + requestOrigin
                self._Log(logStr)

                indigoConn.SendCommandPacket(u"TurnOff", dataVal=device)


Add the modified block:

Code: Select all
#### chris
        def DeviceToggleOnOff(self, indigoConn, device, requestOrigin = None):
                if not self._allowControlPages:
                        raise ControlDisabled
                indigoConn.CheckConnection()

                logStr = "request to toggle device \"" + device + "\""
                if requestOrigin:
                        logStr += " from " + requestOrigin
                self._Log(logStr)

                indigoConn.SendCommandPacket(u"ToggleOnOff", dataVal=device)
### chris


Then call it like:

Code: Select all
# curl 'http://10.0.0.32:8176/devices/bedroom%20sparkly%20lights?Toggle=1&_method=put'


It would be really great to see this added to indigo. Most of the heavy lifting (SendCommandPacket(u"ToggleOnOff")) was already baked in, just not exposed to the restful API.

-Chris


Sat Jul 17, 2010 11:07 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 2557
Location: Austin, Texas
Post Re: RESTful url device toggle
With the RESTful API, we've taken a wait and see approach to implementing some functionality. In this particular case, it's usually easily enough implemented in the client so the priority was low. However, this does show the power of the python (IWS) client!

_________________
Jay (Indigo Support)
Image


Sun Jul 18, 2010 6:32 am
Profile WWW
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 8077
Location: Texas
Post Re: RESTful url device toggle
I'll get this added to the next 4.0 dot release. I made the arg name all lowercase (toggle) for consistency with the others, and simplified it a bit to:

Code: Select all
            toggle = kw.get('toggle', None)
            if toggle is not None:
               toggle = toggle.lower() in [kTrueStr, u"yes", u"1"]
               if toggle:
                  cherrypy.server.indigoDb.DeviceToggleOnOff(cherrypy.server.indigoConn, elem_name, cherrypy.request.remote.better_ip)

Thanks for the contribution.

_________________
Image


Sun Jul 18, 2010 10:19 am
Profile WWW

Joined: Sep 16, 2009
Posts: 50
Post Re: RESTful url device toggle
@Jay yeah I was doing it on the client side. For us though this ends up being one of the top ways we interact with Indigo/Insteon so the extra half-second or so it was taking to establish state and use the turnOn=0/1 was noticeable. The python was indeed very clearly written and easy to hook into.

Thanks for including it, will be easier than having to re-modify every time I upgrade.


-Chris


Sun Jul 18, 2010 11:01 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 8077
Location: Texas
Post Re: RESTful url device toggle
Indigo 4.1.11, which includes the RESTful toggle functionality, is now available.

_________________
Image


Tue Jul 20, 2010 9:38 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.