sliders and dimmable lamps

Posted on
Sun Dec 16, 2007 6:50 am
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

sliders and dimmable lamps

When you change in indigodb.py in line 318:

Code: Select all
   if self.imageFilePath:
      if self.controlValueRaw in [u"off", u"0", u"paused"]:
       pass   # NOP; use base file name already assigned
      elif self.controlValueRaw in [u"on", u"100"]:
        self.imageFilePath = self.imageFilePath[:-4] + u"+on.png"
      else:
        self.imageFilePath = self.imageFilePath[:-4] + u"+" + self.controlValueRaw + u".png"



you can make moving sliders and dimmable lamps like:
iphone_fader_small.png
iphone_fader_small+1.png
iphone_fader_small+2.png
iphone_fader_small+3.png

Posted on
Sun Dec 16, 2007 9:56 am
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

some screenshots (fader works with 100 steps)

Image Image Image


all the files and icons as zip

Posted on
Sat Dec 29, 2007 2:51 pm
dacostad offline
Posts: 78
Joined: May 26, 2006

Changes

I am trying to implement a slider on my iphone to control the light level, however with my limited techinical expertise it appears that the indigodb.py file in the latest version (beta 10) has changed from the example of the changes given above.

Can some one give me an "idiot level" guide as to what I need to do to implement a light slider on my iPhone.

Thanks


David

Posted on
Sat Jan 12, 2008 8:59 am
richardall offline
Posts: 46
Joined: Aug 04, 2005

I know a little bit and I couldn't figure it out

I unzipped the file and found the images, a text file and some web pages.

Reading the text file, I made copies of my indigodb.py files. I then modified the indigodb.py.txt with the suggestion to the best I could understand them.

I then copied the images into their respective files under the indigowebserver folders.

The last file in the zip was named main and contained web pages. I placed these files in my documents folder for my web server.

When I launched the web pages, the show nicely but are incomplete. When I relaunch indigo, the new variables ar not listed for any pages to be build.

I'm not sure what else should or could have been done, but instructions would be nice and copies of the pages would also be nice





Readme for edit indigodb.py.txt
Hold form Indigowebserver/indigopy

Posted on
Sat Jan 12, 2008 9:12 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: I know a little bit and I couldn't figure it out

I haven't looked into Martijn's .zip and instructions in detail yet, but I am planning on rolling into Indigo soon some changes that should make creating iPhone and iPod Touch easier. Just an FYI...

Regards,
Matt

Posted on
Sat Jan 12, 2008 11:37 am
richardall offline
Posts: 46
Joined: Aug 04, 2005

Not to be pushy

But when is soon?

Posted on
Sat Jan 12, 2008 11:42 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Not to be pushy

Not sure. After the new thermostat adapter support is complete.

Matt

Posted on
Sat Jan 12, 2008 2:06 pm
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

but instructions would be nice and copies of the pages would also be nice


I 'll try to explane what I've done:

- First I Changed the indigodb.py file, so that for every(100) device value's a unique pict is chosen.
- Then I made 100 picts for every pict I want to use in the control page.
like this:
iphone_fader_small.png
iphone_fader_small+1.png
...
iphone_fader_small+98.png
iphone_fader_small+99.png
iphone_fader_small+100.png


- Make a new control page
- Chose iphone_fader_small.png for example.

now the slider position will corrosopond with the device value.
on top I placed iphone_icon_2929_transp.png transp. buttons
for the Control light click action.

the control page:
Image

Posted on
Sat Jan 12, 2008 2:11 pm
dacostad offline
Posts: 78
Joined: May 26, 2006

(No subject)

Thanks Martijn.

I have had no luck modifying the indigodb.py file as per your instructions as each time I do it something ends up broke. Could you possibly post a copy of your actual indigodb.py file.

Thanks


David

Posted on
Sat Jan 12, 2008 2:17 pm
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

copy of my indigodb.py:
Code: Select all
####################
# Copyright (c) 2007, Perceptive Automation, LLC. All rights reserved.
# http://www.perceptiveautomation.com
#
# Redistribution of this source file, its binary forms, and images are not allowed.
# We are working on our open source license terms, but at this point the source files,
# its binary forms, and all images cannot be redistributed without written permission
# from both Perceptive Automation, LLC. and Andy Turner, HighEarthOrbit software.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#
# IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
####################

####################
## IMPORTS
import cherrypy
from cherrypy import _cputil

import indigoconn as ic

import calendar, time

####################
## CONSTANTS
_kTrueStr = u"true"
_kFalseStr = u"false"
_kEmptyStr = u""

# Indigo Epoch is 01/01/2000 UTC. Const below is handy for converting to/from UNIX Epoch.
_kEpochOffset = calendar.timegm((2000, 1, 1, 0, 0, 0))

# Space between caption and its state image; must match internal value used by Indigo page editor
_kCaptionBufferSpace = 3

####################
## EXCEPTIONS
class ControlDisabled(Exception):
   def __init__(self, value=None):
      self.value = value   # unicode string

####################
def SortByAttr(listElem, attr):
   tempList = [ (getattr(elem, attr).lower(), index, elem) for index, elem in enumerate(listElem) ]
   tempList.sort()
   return [ elem[-1] for elem in tempList ]

####################
class ActionGroup:
   """ Document me. """

   def __init__(self, name, displayInUI):
      self.name = name

      if displayInUI and displayInUI == _kTrueStr:
         self.displayInUI = True
      else:
         self.displayInUI = False

def ActionGroupFromXml(xmlGroup):
   name = xmlGroup.GetChildElemVal(u"Name")
   displayInUI = xmlGroup.GetChildElemVal(u"DisplayInRemoteUI")   # may be None

   return ActionGroup(name, displayInUI)

####################
class Device:
   """ Document me. """

   def __init__(self, name, type, typeFlags, lastChanged, brightness, isOn, displayInUI, hasStateToDisplay):
      self.name = name
      self.type = type
      self.typeFlags = int(typeFlags)
      if self.typeFlags & (1 << 0):
         self.typeSupportsOnOff = True
      else:
         self.typeSupportsOnOff = False
      if self.typeFlags & (1 <<1> 0:
            self.lastChangedStr = unicode(time.strftime("%Y-%m-%d&nbsp;&nbsp;&nbsp;%I:%M:%S %p", time.gmtime(self.lastChanged + _kEpochOffset)), "utf-8")
            self.lastChangedRFC822 = unicode(time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(self.lastChanged + _kEpochOffset)), "utf-8")
            self.lastChangedRFC3339 = unicode(time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(self.lastChanged + _kEpochOffset)), "utf-8")
         else:
            self.lastChangedStr = _kEmptyStr
            self.lastChangedRFC822 = _kEmptyStr
            self.lastChangedRFC3339 = _kEmptyStr
      else:
         self.lastChanged = 0
         self.lastChangedStr = _kEmptyStr
         self.lastChangedRFC822 = _kEmptyStr
         self.lastChangedRFC3339 = _kEmptyStr

      if self.typeSupportsDim and brightness:
         self.brightness = int(brightness) / 10
      else:
         self.brightness = 0

      if self.typeSupportsOnOff and isOn == _kTrueStr:
         self.isOn = True
      else:
         self.isOn = False

      if self.typeSupportsDim:
         self.deviceState = str(self.brightness).decode("utf-8") + u"%"
      else:
         if self.isOn:
            self.deviceState = u"On"
         else:
            self.deviceState = u"Off"

      if displayInUI and displayInUI == _kTrueStr:
         self.displayInUI = True
      else:
         self.displayInUI = False

      if hasStateToDisplay and hasStateToDisplay == _kTrueStr:
         self.hasStateToDisplay = True
      else:
         self.hasStateToDisplay = False

def DeviceFromXml(xmlDev):
   name = xmlDev.GetChildElemVal(u"Name")
   type = xmlDev.GetChildElemVal(u"Type")
   typeFlags = xmlDev.GetChildElemVal(u"TypeFlags2")
   lastChanged = xmlDev.GetChildElemVal(u"LastChanged")
   brightness = xmlDev.GetChildElemVal(u"BrightValue")               # may be None
   isOn = xmlDev.GetChildElemVal(u"IsOn")                        # may be None
   displayInUI = xmlDev.GetChildElemVal(u"DisplayInRemoteUI")         # may be None
   hasStateToDisplay = xmlDev.GetChildElemVal(u"HasStateToDisplay")   # may be None

   return Device(name, type, typeFlags, lastChanged, brightness, isOn, displayInUI, hasStateToDisplay)

####################
class ControlPage:
   """ Document me. """
   
   def __init__(self, name, widthHeight, color, imageFileName):
      self.name = name

      (self.width, self.height) = str(widthHeight).split(" ")
      self.width = int(self.width)
      self.height = int(self.height)
      self.halfWidth = self.width / 2
      self.halfHeight = self.height / 2

      self.imageFileName = imageFileName      # might be None
      self.imageFilePath = None
      if self.imageFileName:
         self.imageFilePath = u"images/backgrounds/" + self.imageFileName

      self.color = u"#FFFFFF"         # default background color (white)
      if color:
         self.color = u"#" + color.replace(u" ", u"")

def ControlPageFromXml(xmlPage):
   name = xmlPage.GetChildElemVal(u"Name")
   widthHeight = xmlPage.GetChildElemVal(u"Size")
   color = xmlPage.GetChildElemVal(u"Color")                     # may be None
   imageFileName = xmlPage.GetChildElemVal(u"ImageFileName")         # may be None

   return ControlPage(name, widthHeight, color, imageFileName)

####################
class PageElem:
   """ Document me. """
   def _GetFontFamily(self, fontID):
      if fontID == 0:
         return u"Arial, Helvetica, sans-serif"
      elif fontID == 1:
         return u"'Arial Black', Gadget, sans-serif"
      elif fontID == 2:
         return u"Verdana, Geneva, sans-serif"
      elif fontID == 3:
         return u"Impact, Charcoal, sans-serif"
      elif fontID == 100:
         return u"Georgia, 'Times New Roman', Times, serif"
      elif fontID == 101:
         return u"'Times New Roman', Times, serif"
      elif fontID == 200:
         return u"'Courier New', Courier, monospace"
      elif fontID == 201:
         return u"Monaco, 'Lucida Console', monospace"
      elif fontID == 300:
         return u"'Comic Sans MS', cursive"
      return u"sans-serif"

   """ Document me. """
   def __init__(
      self, indigoConn, indigoDb,
      controlType, controlIndex, controlValueRaw, controlValueLong,
      leftTopPos, widthHeight, rotation, alpha,
      showStateImage, showStateText, imageFileName, stateTextAlignment, stateTextFont, stateTextPointSize, stateTextColor,
      targetElemName,
      captionName, captionPlacement, captionFont, captionPointSize, captionColor, captionCurWidth, captionCurHeight, captionWraps,
      actionType, actionLinkTarget, actionLinkOpensInNewWindow
   ):
      self.index = int(controlIndex)
      self.controlType = int(controlType)
      self.controlValueRaw = _kEmptyStr
      self.controlValueLong = _kEmptyStr
      if controlValueRaw:
         self.controlValueRaw = controlValueRaw
      if controlValueLong:
         self.controlValueLong = controlValueLong
      (self.leftPos, self.topPos) = str(leftTopPos).split(" ")
      self.leftPos = int(self.leftPos)
      self.topPos = int(self.topPos)
      (self.width, self.height) = str(widthHeight).split(" ")
      self.width = int(self.width)
      self.height = int(self.height)
   
      self.rotation = 0
      if rotation:
         self.rotation = int(rotation)
      self.alpha = 100
      if alpha:
         self.alpha = int(alpha)

      if showStateImage and showStateImage == _kTrueStr:
         self.showStateImage = True
      else:
         self.showStateImage = False

      if showStateText and showStateText == _kTrueStr:
         self.showStateText = True
      else:
         self.showStateText = False

      self.imageFileName = imageFileName      # might be None
      self.imageFilePath = None
      if self.imageFileName:
         self.imageFilePath = u"images/controls/"

      self.stateTextAlignment = 2            # defaults to align center
      self.stateTextAlignmentName = u"center"
      if stateTextAlignment:
         self.stateTextAlignment = int(stateTextAlignment)
         if self.stateTextAlignment == 0:
            self.stateTextAlignmentName = u"left"
         elif self.stateTextAlignment == 1:
            self.stateTextAlignmentName = u"right"

      self.stateTextFont = 0               # default font ID (Arial)
      if stateTextFont:
         self.stateTextFont = int(stateTextFont)
      self.stateTextFontFamily = self._GetFontFamily(self.stateTextFont)

      self.stateTextPointSize = 12         # default font point size
      if stateTextPointSize:
         self.stateTextPointSize = int(stateTextPointSize)

      self.stateTextColor = u"#008000"      # default state font color (green)
      if stateTextColor:
         self.stateTextColor = u"#" + stateTextColor.replace(u" ", u"")

      self.targetElemName = targetElemName   # might be None
      self.captionName = captionName         # might be None

      self.captionPlacement = 2
      if captionPlacement:
         self.captionPlacement = int(captionPlacement)

      self.captionFont = 0               # default font ID (Arial)
      if captionFont:
         self.captionFont = int(captionFont)
      self.captionFontFamily = self._GetFontFamily(self.captionFont)

      self.captionPointSize = 12            # default font point size
      if captionPointSize:
         self.captionPointSize = int(captionPointSize)

      self.captionColor = u"#000000"         # default caption font color (black)
      if captionColor:
         self.captionColor = u"#" + captionColor.replace(u" ", u"")

      self.captionCurWidth = 200
      if captionCurWidth:
         self.captionCurWidth = int(captionCurWidth)

      self.captionCurHeight = 12
      if captionCurHeight:
         self.captionCurHeight = int(captionCurHeight)

      if captionWraps and captionWraps == _kTrueStr:
         self.captionWraps = True
      else:
         self.captionWraps = False

      self.actionType = int(actionType)
      self.actionLinkTarget = actionLinkTarget   # might be None
      if actionLinkOpensInNewWindow and actionLinkOpensInNewWindow == _kTrueStr:
         self.actionLinkHrefTarget = "target=\"_blank\""
      else:
         self.actionLinkHrefTarget = ""

      if self.controlType == 0:
         pass   # none type
      elif self.controlType == 1:      # --- device state control type ---
         if self.imageFileName:
            self.imageFilePath += u"devices/" + self.imageFileName

         if self.targetElemName:
            if self.imageFilePath:
               if self.controlValueRaw in [u"off", u"0", u"paused"]:
                  pass   # NOP; use base file name already assigned
               elif self.controlValueRaw in [u"on", u"100"]:
                  self.imageFilePath = self.imageFilePath[:-4] + u"+on.png"
               else:
                  self.imageFilePath = self.imageFilePath[:-4] + u"+" + self.controlValueRaw + u".png"
                  
      elif self.controlType == 2:      # --- variable state control type ---
         if self.imageFileName:
            self.imageFilePath += u"variables/" + self.imageFileName

         if self.targetElemName:
            if self.imageFilePath:
               if self.controlValueRaw == u"false":
                  pass   # NOP; use base file name already assigned
               else:
                  self.imageFilePath = self.imageFilePath[:-4] + u"+" + self.controlValueRaw + u".png"
      elif self.controlType == 3:      # --- static control type ---
         if self.imageFileName:
            self.imageFilePath += u"static/" + self.imageFileName
      elif self.controlType == 4:      # --- server status text control type ---
         pass
      elif self.controlType == 5:      # --- server status icon control type ---
         pass
      else:
         pass   # invalid / unknown control type

      # It would be ideal to not have the server pass the caption height or the
      # caption width unless the wrap flag is set, in which case we would need
      # the width.
      #
      # However, we need to have that height value here so we can determine the
      # top offset for center vertical alignment. Ideally, we would use CSS to
      # center the caption within its parent DIV but it doesn't look like there
      # is a good way to do this via CSS that is supported by the major browsers.
      # There are some hacks to accomplish it, but I'd prefer to not use those
      # at this point since different browsers use different techniques.
      #
      # Likewise, not knowing the caption width presents some problems. Although
      # it is possible to use a large default width and get the correct visual
      # layout, we have problems with the transparent buffer space used in the
      # tag eating mouse clicks on other controls. For example, consider this:
      #
      #     ( button 1 )     office light ( light icon )
      #
      # The caption "office light" would have an artificially large width that
      # extends over and on top of button 1, resulting in clicks on button 1
      # not working (or triggering the office light action). By knowing the
      # approximate width of the caption, we can shrink the <div> elems to
      # snugly fit thus avoiding the problem most of the time. 2006.01.26 (mmb)
      #
      if not self.captionWraps:
         # If we are not wrapping (single line of text), then add some buffer
         # to the caption width. This is to avoid having the caption overflow
         # onto the graphic. If we add too much fudge, then the caption elem
         # will be larger than it needs to be and might obscure clicking on
         # other elements. If we add too little, then the caption might overlap
         # onto the graphic (for caption to-the-right-of-image alignment)
         # or might not appear centered. If we knew the font metrics used by
         # the browser exactly matched the Indigo control page editor, then
         # this wouldn't be necessary.
         horzFudge = int(self.captionCurWidth * 0.10)
         if horzFudge > 20:
            horzFudge = 20
         self.captionCurWidth += horzFudge

      halfCaptionCurWidth = int(self.captionCurWidth/2)
      halfCaptionHeight = int(self.captionCurHeight/2)
      
      halfSelfHeight = int(self.height/2)
      halfSelfWidth = int(self.width/2)

      self.captionPosStyle = u"position: absolute;"
      if self.captionPlacement in [0, 1, 2]:
         self.captionPosStyle += u" left: "+str(-halfCaptionCurWidth + halfSelfWidth)+u"px;"
         self.captionPosStyle += u" width: "+str(self.captionCurWidth)+u"px;"
         if self.captionPlacement == 0:
            self.captionPosStyle += u" bottom: "+str(self.height+_kCaptionBufferSpace)+u"px;"
            self.captionPosStyle += u" text-align: center;"
         elif self.captionPlacement == 1:
            self.captionPosStyle += u" top: "+str(halfSelfHeight-halfCaptionHeight)+u"px;"
            self.captionPosStyle += u" text-align: center;"
         else:   # self.captionPlacement == 2:
            self.captionPosStyle += u" top: "+str(self.height+_kCaptionBufferSpace)+u"px;"
            self.captionPosStyle += u" text-align: center;"
      elif self.captionPlacement in [4, 5]:
         self.captionPosStyle += u" top: "+str(halfSelfHeight-halfCaptionHeight)+u"px;"
         if self.captionPlacement == 4:
            self.captionPosStyle += u" right: "+str(self.width+_kCaptionBufferSpace)+u"px;"
            self.captionPosStyle += u" width: "+str(self.captionCurWidth)+u"px;"
            self.captionPosStyle += u" text-align: right;"
         else:   # self.captionPlacement == 5:
            self.captionPosStyle += u" left: "+str(self.width+_kCaptionBufferSpace)+u"px;"
            self.captionPosStyle += u" width: "+str(self.captionCurWidth)+u"px;"
            self.captionPosStyle += u" text-align: left;"
      else:
         pass   # should never happen

      if not self.captionWraps:
         # Force wrapping to off. If the browser font metrics exactly match, or if the
         # horzFudge added above is enough, then this isn't necessary. But force it off
         # as a fail safe measure -- better to have the caption off-center a bit or to
         # overlap onto its parent image a bit than to have it wrap to a second line.
         self.captionPosStyle += u" white-space: nowrap;"

def PageElemFromXml(indigoConn, indigoDb, xmlPageElem):
   controlType = xmlPageElem.GetChildElemVal(u"ControlType")
   controlIndex = xmlPageElem.GetChildElemVal(u"Index")
   controlValueRaw = xmlPageElem.GetChildElemVal(u"ValueRaw")            # may be None
   controlValueLong = xmlPageElem.GetChildElemVal(u"ValueLong")         # may be None

   leftTopPos = xmlPageElem.GetChildElemVal(u"Position")
   widthHeight = xmlPageElem.GetChildElemVal(u"Size")
   rotation = xmlPageElem.GetChildElemVal(u"Rotation")                  # may be None
   alpha = xmlPageElem.GetChildElemVal(u"Alpha")                     # may be None

   showStateImage = xmlPageElem.GetChildElemVal(u"ShowStateImage")
   showStateText = xmlPageElem.GetChildElemVal(u"ShowStateText")
   imageFileName = xmlPageElem.GetChildElemVal(u"ImageFileName")         # may be None
   stateTextAlignment = xmlPageElem.GetChildElemVal(u"StateTextAlignment") # may be None
   stateTextFont = xmlPageElem.GetChildElemVal(u"StateTextFontType")      # may be None
   stateTextPointSize = xmlPageElem.GetChildElemVal(u"StateTextPointSize")   # may be None
   stateTextColor = xmlPageElem.GetChildElemVal(u"StateTextFontColor")      # may be None

   targetElemName = xmlPageElem.GetChildElemVal(u"TargetElemName")         # may be None

   captionName = xmlPageElem.GetChildElemVal(u"CaptionName")            # may be None
   captionPlacement = xmlPageElem.GetChildElemVal(u"CaptionPlacement")      # may be None
   captionFont = xmlPageElem.GetChildElemVal(u"CaptionFontType")         # may be None
   captionPointSize = xmlPageElem.GetChildElemVal(u"CaptionPointSize")      # may be None
   captionColor = xmlPageElem.GetChildElemVal(u"CaptionFontColor")         # may be None
   captionCurWidth = xmlPageElem.GetChildElemVal(u"CaptionCurWidth")      # may be None
   captionCurHeight = xmlPageElem.GetChildElemVal(u"CaptionCurHeight")      # may be None
   captionWraps = xmlPageElem.GetChildElemVal(u"CaptionWraps")            # may be None

   actionType = 0            # use none type for default
   actionLinkTarget = None
   actionLinkOpensInNewWindow = None
   actionGroup = xmlPageElem.GetChildElem(u"ActionGroup")
   actionSteps = actionGroup.GetChildElem(u"ActionSteps")
   actionList = actionSteps.GetListOfChildElems(u"Action")
   if len(actionList) == 1:
      actionType = actionList[0].GetChildElemVal(u"Type")
      actionLinkTarget = actionList[0].GetChildElemVal(u"LinkTarget")      # may be None
      actionLinkOpensInNewWindow = actionList[0].GetChildElemVal(u"LinkOpensInNewWindow")      # may be None
   elif len(actionList) > 1:
      actionType = 9999      # multiple selected -- always have controlElement() called

   return PageElem(
      indigoConn, indigoDb,
      controlType, controlIndex, controlValueRaw, controlValueLong,
      leftTopPos, widthHeight, rotation, alpha,
      showStateImage, showStateText, imageFileName, stateTextAlignment, stateTextFont, stateTextPointSize, stateTextColor,
      targetElemName,
      captionName, captionPlacement, captionFont, captionPointSize, captionColor, captionCurWidth, captionCurHeight, captionWraps,
      actionType, actionLinkTarget, actionLinkOpensInNewWindow
   )

####################
class Variable:
   """ Document me. """

   def __init__(self, name, value, readOnly):
      self.name = name
      self.value = value
      if self.value == _kFalseStr:
         self.isFalse = True
      else:
         self.isFalse = False
      if readOnly == _kTrueStr:
         self.readOnly = True
      else:
         self.readOnly = False

def VariableFromXml(xmlVar):
   name = xmlVar.GetChildElemVal(u"Name")
   value = xmlVar.GetChildElemVal(u"Value")
   readOnly = xmlVar.GetChildElemVal(u"ReadOnly")
   
   return Variable(name, value, readOnly)

####################
class Database:
   """ Document me. """

   ####################
   def __init__(self, allowControlPages, nativeAccessEnabled, feedsEnabled, logFunc):
      self._allowControlPages = allowControlPages
      self._feedsEnabled = feedsEnabled
      self._nativeAccessEnabled = nativeAccessEnabled
      self._DebugLog = _cputil.get_special_attribute('_cp_log_message', '_cpLogMessage')
      self._Log = logFunc

   def Destroy(self):
      pass

   ####################
   def AreControlPagesAllowed(self):
      return self._allowControlPages

   def AreFeedsEnabled(self):
      return self._feedsEnabled

   def IsNativeAccessEnabled(self):
      return self._nativeAccessEnabled
   
   ####################
   def GetActionGroup(self, indigoConn, groupName):
      if not (self._allowControlPages or self._feedsEnabled):
         raise ControlDisabled
      indigoConn.CheckConnection()
      indigoConn._SendPacket(ic.Packet(ic._kRequestType, u"GetActionGroup", packetDataVal=groupName))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType, u"GetActionGroup")
      xmlGroup = responsePacket.xmlNode

      group = ActionGroupFromXml(xmlGroup)

      responsePacket.CleanUp()
      return group

   def GetActionGroups(self, indigoConn, doSort):
      if not (self._allowControlPages or self._feedsEnabled):
         raise ControlDisabled
      indigoConn.CheckConnection()
      indigoConn._SendPacket(ic.Packet(ic._kRequestType, u"GetActionGroupList"))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType, u"GetActionGroupList")
      
      groupList = []
      xmlGroupList = responsePacket.xmlNode.GetListOfChildElems(u"ActionGroup")
      for xmlGroup in xmlGroupList:
         groupList.append(ActionGroupFromXml(xmlGroup))

      if doSort:
         groupList[:] = SortByAttr(groupList, "name")

      responsePacket.CleanUp()
      return groupList

   def GetDevice(self, indigoConn, deviceName):
      if not (self._allowControlPages or self._feedsEnabled):
         raise ControlDisabled
      indigoConn.CheckConnection()
      indigoConn._SendPacket(ic.Packet(ic._kRequestType, u"GetDeviceElem", packetDataVal=deviceName))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType, u"GetDeviceElem")
      xmlDev = responsePacket.xmlNode

      device = DeviceFromXml(xmlDev)

      responsePacket.CleanUp()
      return device

   def GetDevices(self, indigoConn, doSort):
      if not (self._allowControlPages or self._feedsEnabled):
         raise ControlDisabled
      indigoConn.CheckConnection()
      indigoConn._SendPacket(ic.Packet(ic._kRequestType, u"GetDeviceList"))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType, u"GetDeviceList")

      devList = []
      xmlDevList = responsePacket.xmlNode.GetListOfChildElems(u"Device")
      for xmlDev in xmlDevList:
         devList.append(DeviceFromXml(xmlDev))

      if doSort:
         devList[:] = SortByAttr(devList, "name")
      
      responsePacket.CleanUp()
      return devList

   def GetControl(self, indigoConn, pageName, controlIndex):
      '''Return a single control element by the element's z-index '''
      if not (self._allowControlPages or self._feedsEnabled):
         raise ControlDisabled
      indigoConn.CheckConnection()
      dataNode = ic.XmlNode()
      dataNode.AddStringNode(u"PageName", pageName)
      dataNode.AddStringNode(u"ControlID", controlIndex)
      indigoConn._SendPacket(ic.Packet(ic._kRequestType, u"GetControlPageElem", packetDataNode=dataNode))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType, u"GetControlPageElem")
      xmlPageElem = responsePacket.xmlNode

      controlElem = PageElemFromXml(indigoConn, self, xmlPageElem)

      responsePacket.CleanUp()
      return controlElem

   def GetControlPage(self, indigoConn, pageName):
      if not (self._allowControlPages or self._feedsEnabled):
         raise ControlDisabled
      indigoConn.CheckConnection()
      indigoConn._SendPacket(ic.Packet(ic._kRequestType, u"GetControlPage", packetDataVal=pageName))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType, u"GetControlPage")
      xmlPage = responsePacket.xmlNode

      page = ControlPageFromXml(xmlPage)
   
      controlElemList = []
      xmlControlElemList = xmlPage.GetListOfChildElems(u"PageElem")
      for xmlPageElem in xmlControlElemList:
         controlElemList.append(PageElemFromXml(indigoConn, self, xmlPageElem))

      # change count was increased by server, return the new value
      changeCount = xmlPage.GetChildElemVal(u"ChangeCount")

      responsePacket.CleanUp()
      return [page, controlElemList, changeCount]

   def GetControlPages(self, indigoConn, doSort):
      if not (self._allowControlPages or self._feedsEnabled):
         raise ControlDisabled
      indigoConn.CheckConnection()
      indigoConn._SendPacket(ic.Packet(ic._kRequestType, u"GetControlPageList"))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType, u"GetControlPageList")

      pageList = []
      xmlPageList = responsePacket.xmlNode.GetListOfChildElems(u"ControlPage")
      for xmlPage in xmlPageList:
         pageList.append(ControlPageFromXml(xmlPage))

      if doSort:
         pageList[:] = SortByAttr(pageList, "name")

      responsePacket.CleanUp()
      return pageList

   def GetVariable(self, indigoConn, variableName):
      if not (self._allowControlPages or self._feedsEnabled):
         raise ControlDisabled
      indigoConn.CheckConnection()
      indigoConn._SendPacket(ic.Packet(ic._kRequestType, u"GetVariableElem", packetDataVal=variableName))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType, u"GetVariableElem")
      xmlVar = responsePacket.xmlNode

      varElem = VariableFromXml(xmlVar)

      responsePacket.CleanUp()
      return varElem

   def GetVariables(self, indigoConn, doSort):
      if not (self._allowControlPages or self._feedsEnabled):
         raise ControlDisabled
      indigoConn.CheckConnection()
      indigoConn._SendPacket(ic.Packet(ic._kRequestType, u"GetVariableList"))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType, u"GetVariableList")

      varList = []
      xmlVarList = responsePacket.xmlNode.GetListOfChildElems(u"Variable")
      for xmlVar in xmlVarList:
         varList.append(VariableFromXml(xmlVar))

      if doSort:
         varList[:] = SortByAttr(varList, "name")

      responsePacket.CleanUp()
      return varList

   def GetControlPageStatus(self, indigoConn, pageName, changeCount):
      '''Retrieves an update to a page given the pageName and the current changeCount number'''
      if not (self._allowControlPages or self._feedsEnabled):
             raise ControlDisabled
      indigoConn.CheckConnection()

      dataNode = ic.XmlNode()
      dataNode.AddStringNode(u"PageName", pageName)
      dataNode.AddStringNode(u"ChangeCount", str(changeCount))

      indigoConn._SendPacket(ic.Packet(ic._kRequestType,u"GetControlPageStatus", packetDataNode=dataNode))
      responsePacket = indigoConn._GetNextPacket(ic._kResponseType,u"GetControlPageStatus")
      xmlNode = responsePacket.xmlNode

      # controlIDs:
      # contains "" (_kEmptyStr) if no control IDs need to be updated
      # contains "-1" if entire page should be updated
      # else contains space delimited list of IDs, like "12 13 17 23"
      controlIDs = xmlNode.GetChildElemVal(u"ControlIDs")
      if not controlIDs:
         controlIDs = _kEmptyStr

      # change count was increased by server, return the new value
      changeCount = xmlNode.GetChildElemVal(u"ChangeCount")
      
      # server state: idle, busy
      serverState = xmlNode.GetChildElemVal(u"ServerState")

      responsePacket.CleanUp()
      return [controlIDs, changeCount, serverState]

   ####################
   def DeviceTurnOn(self, indigoConn, device):
      if not self._allowControlPages:
         raise ControlDisabled
      indigoConn.CheckConnection()
      self._Log("request to turn on device \"" + device + "\" from " + cherrypy.request.remote_addr)

      indigoConn._SendPacket(ic.Packet(ic._kCommandType, u"TurnOn", packetDataVal=device))

   def DeviceTurnOff(self, indigoConn, device):
      if not self._allowControlPages:
         raise ControlDisabled
      indigoConn.CheckConnection()
      self._Log("request to turn off device \"" + device + "\" from " + cherrypy.request.remote_addr)

      indigoConn._SendPacket(ic.Packet(ic._kCommandType, u"TurnOff", packetDataVal=device))

   def DeviceSetBrightness(self, indigoConn, device, level):
      if not self._allowControlPages:
         raise ControlDisabled
      indigoConn.CheckConnection()
      self._Log("request to set device \"" + device + "\" brightness from " + cherrypy.request.remote_addr)

      dataNode = ic.XmlNode()
      dataNode.AddStringNode(u"Name", device)
      dataNode.AddStringNode(u"Amount", level)
      indigoConn._SendPacket(ic.Packet(ic._kCommandType, u"SetBrightness", packetDataNode=dataNode))

   ####################
   def GroupExecute(self, indigoConn, group):
      if not self._allowControlPages:
         raise ControlDisabled
      indigoConn.CheckConnection()
      self._Log("request to execute action group \"" + group + "\" from " + cherrypy.request.remote_addr)

      indigoConn._SendPacket(ic.Packet(ic._kCommandType, u"TriggerActionGroup", packetDataVal=group))

   ####################
   def DoControl(self, indigoConn, pageName, controlIndex):
      if not self._allowControlPages:
         raise ControlDisabled
      indigoConn.CheckConnection()
      self._Log("request to execute control page \"" + pageName + "\" control #" + controlIndex + " from " + cherrypy.request.remote_addr)

      dataNode = ic.XmlNode()
      dataNode.AddStringNode(u"PageName", pageName)
      dataNode.AddStringNode(u"ControlID", controlIndex)
      indigoConn._SendPacket(ic.Packet(ic._kCommandType, u"TriggerControlAction", packetDataNode=dataNode))

Posted on
Sat Jan 12, 2008 2:31 pm
dacostad offline
Posts: 78
Joined: May 26, 2006

(No subject)

Thanks again Martijn, I will give that a try. Do I need to stop and start the Indigo server before using or do I need to do a complete reboot?


David

Posted on
Sat Jan 12, 2008 2:45 pm
dacostad offline
Posts: 78
Joined: May 26, 2006

(No subject)

I did a straight copy and paste over your file, but after stop and starting the server I get

"Safari can’t connect to the server.
Safari can’t open the page “http://127.0.0.1:8000/controlpage?name=Home” because it could not connect to the server “127.0.0.1”."

I tried deleting the .pyc file but there was no recompile on stopping and starting the server (no .pyc file created). What am I doing wrong?

Posted on
Sat Jan 12, 2008 3:23 pm
dacostad offline
Posts: 78
Joined: May 26, 2006

(No subject)

Got it!

I finally just added the different lines of code using BBEdit and now it is working!!

Posted on
Sat Jan 12, 2008 3:36 pm
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

Got it!


Good to hear !

do you know why the webserver didn't started ?

Posted on
Sat Jan 12, 2008 3:45 pm
dacostad offline
Posts: 78
Joined: May 26, 2006

(No subject)

No I don't.

Who is online

Users browsing this forum: No registered users and 9 guests