def __init__(self, xml ): WbEventOther.__init__(self) # read eventype # read event source # read parameters self._type = getAttrText( xml, 'type' ) self._source = getAttrText( xml, 'source' ) self._other_data = None if xml.childNodes: self._other_data = dict() # There are parameters. for param in xml.childNodes: if param.nodeType == param.ELEMENT_NODE: # for each element in param create param entry self._other_data[param.tagName] = getElemText(param)
def configure( self, xml ): # read eventype # read event source # read parameters self._type = getAttrText( xml, 'type' ) self._source = getAttrText( xml, 'source' ) self._params = None paramElem = getNamedElem(xml, "params") if paramElem and paramElem.childNodes: self._params = dict() # There are parameters. for param in paramElem.childNodes: if param.nodeType == param.ELEMENT_NODE: isList = getAttrText(param, "type") == "list" txt = getElemText(param) # for each element in param create param entry if isList: self._params[param.tagName] = txt.split(',') else: self._params[param.tagName] = txt if len(self._params) == 0: self._params = None
def makeConfigCommands(self,dom,override): """ Convert the supplied DOM object into a list of webbrick configuration commands. The override parameter is a dictionary of values that can be used to override values in the supplied DOM when generating the configuration commands; e.g. "password" - overrides password used with "LG" command "IP" - overrides IP{ addresss et with "IA" command """ p = override.get("password") or "password" cmds = ["LG"+p,"SS1"] template = ( # elem1 elem2 cmd override transform ("NN", None, "NN", "NodeName", getNameText), # Node name ("SN", None, "SN", "NodeNum", getElemText), # Node number ("NOs", "NO", "NO", None, idNameAttr), # Name Digital Output ("CDs", "CD", "ND", None, idNameAttr), # Name Digital Input ("CDs", "CD", "CD", None, idTrigger), # Configure Digital Input #Monitors are now DIs 8-11 #("NMs", "NM", "NM", None, idNameAttr), # Name Monitor Input ("NAs", "NA", "NA", None, idNameAttr), # Name Analogue Output ("CIs", "CI", "NI", None, idNameAttr), # Name Analogue Input ("CIs", "CI", "CI", None, idAnalogLo), # Configure Analogue Input Low threshold ("CIs", "CI", "CI", None, idAnalogHi), # Configure Analogue Input High threshold ("CTs", "CT", "NT", None, idNameAttr), # Name Temperature Sensor ("CTs", "CT", "CT", None, idTempLo), # Configure Temperature Sensor Low threshold ("CTs", "CT", "CT", None, idTempHi), # Configure Temperature Sensor High threshold ("SRs", "SR", "SR", None, idValAttr), # Rotary encoder step ("IR", None, "IR", None, maskNF(0x40)), # Enable infrared receive? ("IR", None, "IT", None, maskNF(0x20)), # Enable infrared transmit? ("IR", None, "IA", None, maskInt(0x1F)), # Infrared receiving address ("SF", None, "SF", None, getElemText), # Fade rate ("MM", None, "SM", None, mimicLoHiFade), # Set mimic hi/lo/faderate ("MM", None, "CM", None, mimicAChan(0)), # Configure mimic channel for analog out 0 ("MM", None, "CM", None, mimicAChan(1)), # Configure mimic channel for analog out 1 ("MM", None, "CM", None, mimicAChan(2)), # Configure mimic channel for analog out 2 ("MM", None, "CM", None, mimicAChan(3)), # Configure mimic channel for analog out 3 ("MM", None, "CM", None, mimicDChan(0)), # Configure mimic channel for digital out 0 ("MM", None, "CM", None, mimicDChan(1)), # Configure mimic channel for digital out 1 ("MM", None, "CM", None, mimicDChan(2)), # Configure mimic channel for digital out 2 ("MM", None, "CM", None, mimicDChan(3)), # Configure mimic channel for digital out 3 ("MM", None, "CM", None, mimicDChan(4)), # Configure mimic channel for digital out 4 ("MM", None, "CM", None, mimicDChan(5)), # Configure mimic channel for digital out 5 ("MM", None, "CM", None, mimicDChan(6)), # Configure mimic channel for digital out 6 ("MM", None, "CM", None, mimicDChan(7)), # Configure mimic channel for digital out 7 ("CWs", "CW", "CW", None, idElemText), # Configure Dwell ("CSs", "CS", "CS", None, idElemText), # Configure Preset Point ("CEs", "CE", "CE", None, idSchedule), # Configure Schedule Event ("CCs", "CC", "CC", None, idScene) # Configure Scene ) # for webbrick 6.5, when triggers changed. template6_5 = ( # elem1 elem2 cmd override transform ("NN", None, "NN", "NodeName", getNameText), # Node name ("SN", None, "SN", "NodeNum", getElemText), # Node number ("NOs", "NO", "NO", None, idNameAttr), # Name Digital Output ("CDs", "CD", "ND", None, idNameAttr), # Name Digital Input ("CDs", "CD", "CD", None, idTrigger65), # Configure Digital Input #Monitors are now DIs 8-11 #("NMs", "NM", "NM", None, idNameAttr), # Name Monitor Input ("NAs", "NA", "NA", None, idNameAttr), # Name Analogue Output ("CIs", "CI", "NI", None, idNameAttr), # Name Analogue Input ("CIs", "CI", "CI", None, idAnalogLo65), # Configure Analogue Input Low threshold ("CIs", "CI", "CI", None, idAnalogHi65), # Configure Analogue Input High threshold ("CTs", "CT", "NT", None, idNameAttr), # Name Temperature Sensor ("CTs", "CT", "CT", None, idTempLo65), # Configure Temperature Sensor Low threshold ("CTs", "CT", "CT", None, idTempHi65), # Configure Temperature Sensor High threshold ("SRs", "SR", "SR", None, idValAttr), # Rotary encoder step ("SE", None, "CR", None, serialConfig), # Serial config ("IR", None, "IR", None, maskNF(0x40)), # Enable infrared receive? ("IR", None, "IT", None, maskNF(0x20)), # Enable infrared transmit? ("IR", None, "IA", None, maskInt(0x1F)), # Infrared receiving address ("SF", None, "SF", None, getElemText), # Fade rate ("MM", None, "SM", None, mimicLoHiFade), # Set mimic hi/lo/faderate ("MM", None, "CM", None, mimicAChan(0)), # Configure mimic channel for analog out 0 ("MM", None, "CM", None, mimicAChan(1)), # Configure mimic channel for analog out 1 ("MM", None, "CM", None, mimicAChan(2)), # Configure mimic channel for analog out 2 ("MM", None, "CM", None, mimicAChan(3)), # Configure mimic channel for analog out 3 ("MM", None, "CM", None, mimicDChan(0)), # Configure mimic channel for digital out 0 ("MM", None, "CM", None, mimicDChan(1)), # Configure mimic channel for digital out 1 ("MM", None, "CM", None, mimicDChan(2)), # Configure mimic channel for digital out 2 ("MM", None, "CM", None, mimicDChan(3)), # Configure mimic channel for digital out 3 ("MM", None, "CM", None, mimicDChan(4)), # Configure mimic channel for digital out 4 ("MM", None, "CM", None, mimicDChan(5)), # Configure mimic channel for digital out 5 ("MM", None, "CM", None, mimicDChan(6)), # Configure mimic channel for digital out 6 ("MM", None, "CM", None, mimicDChan(7)), # Configure mimic channel for digital out 7 ("CWs", "CW", "CW", None, idElemText), # Configure Dwell ("CSs", "CS", "CS", None, idElemText), # Configure Preset Point ("CEs", "CE", "CE", None, idSchedule65), # Configure Schedule Event ("CCs", "CC", "CC", None, idScene) # Configure Scene ) ver_template = template # is this a version 6.5 webbrick, version is on root level ver_str = getAttrText( getNamedElem(dom,"WebbrickConfig") , "Ver") if ver_str and ver_str > "6.4.1904": ver_template = template6_5 for (en1,en2,cn,ov,transform) in ver_template: # Construct command, allowing for supplied override def mkCmd(cn,ov,transform,e): Trace("Generate command %s for element %s"%(cn,getElemXml(e)), "WebBrickConfig.WebBrickConfig") try: val = (ov and override.get(ov)) or transform(e) except Exception, exc: raise WebBrickConfigException(command=cn, element=getElemXml(e), cause=str(exc)) return val and cn+val # Select top-level element Trace("Processing config element "+en1, "WebBrickConfig.WebBrickConfig") try: elms = dom.getElementsByTagName(en1) elm1 = elms and elms[0] except Exception, e: raise WebBrickConfigException(command=cn, cause=str(e))