def print_event(*arg): ddat = arg[0] try: if ddat["control"] in ["ST", "RR", "OL"] : ectrl = EVENT_CTRL.get(ddat["control"], ddat["control"]) node = ddat["node"] evi = ddat["eventInfo"] ti = time.strftime('%X') # print ddat["Event-sid"] print("%-7s %-4s\t%-22s\t%-12s\t%s\t%s" % \ (ti, ddat["Event-seqnum"], \ ectrl, node, ddat["action"], evi)) #elif ddat["control"] == "_1" and ddat["action"] in ["6", "7", "3"] : # print ddat["control"], " : ", ddat # print arg #print ddat # print data except Exception: print("Unexpected error:", sys.exc_info()[0]) print(ddat) # print data finally: pass
def parse_event(*arg): global isy, verbose ddat = arg[0] # mydat = arg[1] exml = arg[2] # Message types to skip logging skipEvents = { 0: ['Heartbeat', 'System Status', 'System Config Updated', 'Electricity'], 1: ['Heartbeat', 'System Status', 'System Config Updated'], 2: [] } statusEvents = ['Status', 'On Level', 'Ramp Rate', 'Humidity', 'UOM', 'Thermostat Mode', 'Heat/Cool State'] try: # Log message, format based on message type control = ddat['control'] # Extract message elements node = ddat['node'] evi = ddat['eventInfo'] action = ddat['action'] if debug: print "\n%s" % ddat print "control: %s" % control print "node: %s" % node print "evi: %s" % evi print "action: %s" % action # Get human-readable event control ectrl = EVENT_CTRL.get(control, control) if debug: print "ectrl: %s" % ectrl if ectrl in skipEvents[verbose]: return() if evi is None: # Clear empty event info for logging evi = '' if node: # Track status, ramp level, on level and other data for a node # The first one we see is the current level, don't log unless # in at least double-verbose mode if ectrl in statusEvents and (node not in nodeStatus or control not in nodeStatus[node]): if node not in nodeStatus: nodeStatus[node] = {} nodeStatus[node][control] = action if verbose < 2: return() log_event(build_message(node, control, action, evi)) else: log_event(build_message(None, control, action, evi)) except Exception: #print("Unexpected error:", sys.exc_info()[0]) print("Unexpected error:", str(sys.exc_info())) print(ddat) finally: pass
def print_event(*arg): ddat = arg[0] mydat = arg[1] exml = arg[2] try: if ddat["control"] in ["_11"] : pass elif ddat["control"] in ["ST", "RR", "OL"] : ectrl = EVENT_CTRL.get(ddat["control"], ddat["control"]) node = ddat["node"] evi = ddat["eventInfo"] ti = time.strftime('%X') # print ddat["Event-sid"] print("%-7s %-4s\t%-22s\t%-12s\t%s\t%s" % \ (ti, ddat["Event-seqnum"], \ ectrl, node, ddat["action"], evi)) elif ddat["control"] == "_3" : if ddat['action'] == 'FD' : print 'new Folder node: ', ddat['node'], ' = ', ddat['eventInfo']['folder'] elif ddat['action'] == 'FR' : print 'del Folder node: ', ddat['node'] elif ddat['action'] == 'FN' : print 'rename Folder node: ', ddat['node'], ' = ', ddat else : print '_3 : ', ddat else : print "Event Dat : \n\t", ddat, "\n\t", exml #elif ddat["control"] == "_1" and ddat["action"] in ["6", "7", "3"] : # print ddat["control"], " : ", ddat # print arg #print ddat # print data except Exception: print("Unexpected error:", sys.exc_info()[0]) print(ddat) # print data finally: pass
def status_dump(signum, frame): global isy for node in nodeStatus: nodeName = isy._node_get_name(node) nodeName = nodeName[1] for control in nodeStatus[node]: ectrl = EVENT_CTRL.get(control, control) value = nodeStatus[node][control] if int(value) == 255: value = 'on' elif int(value) == 0: value = 'off' else: value = str(int(float(value) / 255.0 * 100.0)) + '%' if nodeName: log_event("\"%s\" (%s) %s is %s" % (nodeName, node, ectrl, value)) else: log_event("%s %s is %s" % (nodeName, node, ectrl, value)) # Reset signal handler signal.signal(signal.SIGUSR1,status_dump)
def print_event(*arg): ddat = arg[0] # mydat = arg[1] exml = arg[2] # Event Dat : # {'control': 'DOF', 'node': '16 6C D2 7', 'eventInfo': None, 'Event-seqnum': '141', 'action': '0', 'Event-sid': 'uuid:40'} # <?xml version="1.0"?><Event seqnum="141" sid="uuid:40"><control>DOF</control><action>0</action><node>16 6C D2 7</node><eventInfo></eventInfo></Event> # ti = time.strftime('%X') try: if ddat["control"] in ["_0", "_11", "_12", "_19" ] : pass elif ddat["control"] == "ERR" : print "{!s:<7} {!s:<4}\t{!s:<22}\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], "ERR", ddat['node'], ddat['action']) return elif ddat["control"] in ["DOF", "DON", "BMAN", "SMAN" ] : action=ddat["control"] status=ddat["node"] print "{!s:<7} {!s:<4}\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], action, status) elif ddat["control"] in ["ST", "RR", "OL"] : ectrl = EVENT_CTRL.get(ddat["control"], ddat["control"]) node = ddat["node"] evi = ddat["eventInfo"] # print ddat["Event-sid"] print("%-7s %-4s\t%-22s\t%-12s\t%s\t%s" % \ (ti, ddat["Event-seqnum"], \ ectrl, node, ddat["action"], evi)) # print '_3 ', ddat["control"], ' : ', ddat elif ddat["control"] == "_1" : # 'on': None, 'f': '140630 20:55:55', 's': '31', 'r': '140630 20:55:55', 'nr': None, 'id': '1E'} if ddat['action'] == '0' : print "exml = ", exml if "nsr" in ddat["eventInfo"] : action = "Event Status" status = "id={!s} {!s}".format(ddat["eventInfo"]['id'], ddat["eventInfo"]['nsr']) else : if 'on' in ddat["eventInfo"] : ena = "enabled" else : ena = "disabled" if 'rr' in ddat["eventInfo"] : rr = "rr" else : rr = "nr" action = "Event Status" status = "id={!s} {!s} {!s} run={!s} fin={!s} status={!s}".format( ddat["eventInfo"]['id'], ena, rr, ddat["eventInfo"]['r'], ddat["eventInfo"]['f'], ddat["eventInfo"]['s']) if ddat['action'] == '1' : action = "Get Status" status = "" elif ddat['action'] == '2' : action = "Key Change" status = ddat['node'] elif ddat['action'] == '3' : action = "Info String" status = "{!s}\t{!s} ".format(ddat['node'], ddat["eventInfo"]) elif ddat['action'] == '4' : action = "IR Learn Mode" status = "" elif ddat['action'] == '5' : action = "Schedule" status = ddat['node'] elif ddat['action'] == '6' : action = "Var Stat" status = "{!s} {!s}:{!s} {!s} {!s}".format( ddat['node'], ddat['eventInfo']['var']['var-type'], ddat['eventInfo']['var']['var-id'], ddat['eventInfo']['var']['val'], ddat['eventInfo']['var']['ts']) elif ddat['action'] == '7' : action = "Var Init" status = "{!s} {!s}:{!s} {!s}".format( ddat['node'], ddat['eventInfo']['var']['var-type'], ddat['eventInfo']['var']['var-id'], ddat['eventInfo']['var']['init']) elif ddat['action'] == '8' : action = "Key" status = ddat['eventInfo'] else : action = ddat['action'], status = ddat['eventInfo'] print "{!s:<7} {!s:<4}\t{!s:<22}\t{!s}\t{!s} ".format( ti, ddat['Event-seqnum'], "Trigger Event", action, status) elif ddat["control"] == "_3" : if ddat['action'] == 'FD' : action = 'new Folder node: ' status = str("{!s} = {!s}").format(ddat['node'], ddat['eventInfo']['folder']) elif ddat['action'] == 'FR' : action = 'del Folder node' status = ddat['node'] elif ddat['action'] == 'FN' : action = 'rename Folder node' status = ddat['node'] elif ddat['action'] == 'CE' : action = 'Clear Node Error' status = ddat['node'] elif ddat['action'] == 'NE' : action = 'Node Error' status = ddat['node'] elif ddat['action'] == 'WH' : action = "Pending Device Operation" status = ddat['node'] elif ddat['action'] == 'WD' : action = "Programming Device" status = ddat['node'] elif ddat['action'] == 'SN' : action = "Discovering Nodes" status = "" elif ddat['action'] == 'SC' : action = "Discovering Nodes Complete" status = "" else : action = ddat['action'] status = "{!s}\t{!s}".format(ddat['node'], ddat['eventInfo']) # "Node Change", print "{!s:<7} {!s:<4}\t{!s:<22}\t{!s}".format( ti, ddat['Event-seqnum'], action, status) elif ddat["control"] == "_4" : status="" action=ddat['action'] if ddat['action'] == '0' : action = "Time Change" elif ddat['action'] == '1' : action = "Time Conf Changed" elif ddat['action'] == '2' : action = "NTP Setting Change" elif ddat['action'] == '3' : action = "Notifications Settings Updated" elif ddat['action'] == '4' : action = "NTP Communications Error" elif ddat['action'] == '5' : action = "Batch Mode Updated" status = ddat['eventInfo']['status'] elif ddat['action'] == '6' : action = "Battery Mode Programming Updated" status = ddat['eventInfo']['status'] else : action = ddat['action'] status = ddat['eventInfo'] print "{!s:<7} {!s:<4}\tSys Conf Updated\t{!s} : {!s}".format( ti, ddat['Event-seqnum'], action, status) elif ddat["control"] == "_5" : action=ddat['action'] if ddat['action'] == '0' : action = "Not Busy" elif ddat['action'] == '1' : action = "Busy" elif ddat['action'] == '2' : action = "Idle" elif ddat['action'] == '3' : action = "Safe Mode" print "{!s:<7} {!s:<4}\tSys Status Updated\t{!s}".format( ti, ddat['Event-seqnum'], action) elif ddat["control"] == "_7" : if ddat['action'] == '1' : action = "Update" elif ddat['action'] == '2.1' : action = "Device Address Info" elif ddat['action'] == '2.2' : action = "Device Address Warn" elif ddat['action'] == '2.3' : action = "Device Address Error" else : action = ddat['action'] print "{!s:<7} {!s:<4}\tProgress Report\t{!s} : {!s}".format(ti, ddat['Event-seqnum'], action, ddat["eventInfo"]) elif ddat["control"] == "_10" : action=ddat['action'] status=ddat['eventInfo'] if ddat['action'] == '1' : action="Open ADR Error" status="" if ddat['action'] == '2' : action="Open ADR Status Update" status=ddat['eventInfo'] if ddat['action'] == '5' : action="Flex Your Power Error" status="" elif ddat['action'] == '6' : action="Flex Your Power Status" status=ddat['eventInfo']['active'] print "{!s:<7} {!s:<4}\tOpenADR / Flex\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], action, status) # elif ddat["control"] == "_12" : # pass # elif ddat["control"] == "_1" and ddat["action"] in ["6", "7", "3"] : # print ddat["control"], " : ", ddat # print arg else : print "Event Dat : \n\t", ddat, "\n\t", exml pass #print ddat # print data except Exception as e: print("Unexpected error:", sys.exc_info()[0]) print(e) print(ddat) raise # print data finally: pass
def _print_event(*arg): ddat = arg[0] # mydat = arg[1] exml = arg[2] # Event Dat: # {'control': 'DOF', 'node': '16 6C D2 7', 'eventInfo': None, 'Event-seqnum': '141', 'action': '0', 'Event-sid': 'uuid:40'} # <?xml version="1.0"?><Event seqnum="141" sid="uuid:40"><control>DOF</control><action>0</action><node>16 6C D2 7</node><eventInfo></eventInfo></Event> # ti = time.strftime('%X') try: if "control" not in ddat or ddat["control"] is None: return control_val = ddat["control"] if "action" in ddat and ddat["action"] is not None: action_val = _action_val(ddat["action"]) else : action_val = None if control_val in EVENT_CTRL_ACTION and action_val: action_str = EVENT_CTRL_ACTION[control_val].get(action_val, action_val) else : action_str = "" node = ddat.get("node", "") if node is None: node = "" control_str = EVENT_CTRL.get(control_val, control_val) evi = "" if ddat["control"] in ["_0"]: pass elif ddat["control"] == "ERR": print "{!s:<7} {!s:<4}\t{!s:<12}{!s:<12}\t{!s}".format( ti, ddat['Event-seqnum'], "ERR", ddat['node'], action_str) return #elif ddat["control"] in ["DOF", "DON", "BMAN", "SMAN", "FDUP", "FDSTOP", "FDDOWN" ]: # print "{!s:<7} {!s:<4}\t{!s:<12}{!s}\t{!s}".format( # ti, ddat['Event-seqnum'], node, control_str, action_str) # return elif ddat["control"] in ["ST", "RR", "OL", "DOF", "DON", "DFOF", "DFON", "BMAN", "SMAN", "FDUP", "FDSTOP", "FDDOWN" ]: if ddat["eventInfo"] is not None: evi = ddat["eventInfo"] else : evi = "" print "{!s:<7} {!s:<4}\t{!s:<12}{!s:<12}\t{!s:<12}\t{!s}".format( ti, ddat["Event-seqnum"], node, control_str, action_val, evi) return elif ddat["control"] == "_1": # 'on': None, 'f': '140630 20:55:55', 's': '31', 'r': '140630 20:55:55', 'nr': None, 'id': '1E'} #action = EVENT_CTRL_ACTION[ddat["control"]].get(ddat['action'], ddat['action']) status = "" if action_val == '0': st=[ ] if 'id' in ddat["eventInfo"]: st.append("id={}".format(ddat["eventInfo"]['id'])) if 's' in ddat["eventInfo"]: st.append("status={}".format(ddat["eventInfo"]['s'])) if 'on' in ddat["eventInfo"]: st.append( "enabled=true") if 'off' in ddat["eventInfo"]: st.append( "enabled=false") if 'rr' in ddat["eventInfo"]: st.append( "runAtStartup=true") if 'nr' in ddat["eventInfo"]: st.append( "runAtStartup=false") if 'r' in ddat["eventInfo"]: st.append("lastRunTime={}".format(ddat["eventInfo"]['r'])) if 'f' in ddat["eventInfo"]: st.append("lastFinishTime={}".format(ddat["eventInfo"]['f'])) if 'nsr' in ddat["eventInfo"]: st.append("nextScheduledRunTime={}".format( ddat["eventInfo"]['nsr'])) status = " ".join(st) elif action_val == '6': status = "{!s:<12} {!s}:{!s} {!s} {!s}".format( ddat['node'], ddat['eventInfo']['var']['var-type'], ddat['eventInfo']['var']['var-id'], ddat['eventInfo']['var']['val'], ddat['eventInfo']['var']['ts']) elif action_val == '7': status = "{!s:<12} {!s}:{!s} {!s}".format( ddat['node'], ddat['eventInfo']['var']['var-type'], ddat['eventInfo']['var']['var-id'], ddat['eventInfo']['var']['init']) else: if isinstance( ddat['eventInfo'], dict): status = " ".join(["{}={}".format(a,b) for a, b in ddat['eventInfo'].items()] ) elif ddat['eventInfo'] is None: status="" else: status = ddat['eventInfo'] print "{!s:<7} {!s:<4}\t{!s:<12}{!s}\t{!s}\t{!s}".format( ti, ddat["Event-seqnum"], node, control_str, action_str, status) return elif ddat["control"] in [ "_3", "_4", "_5", "_6", "_7", "_8", "_9", "_10", "_11", "_12", "_13", "_14", "_15", "_16", "_19", "_20", "_21", "_22" ] : d = ddat['eventInfo'] if isinstance( d, dict): status = " ".join(["{}={}".format(a,b) for a, b in d.items()] ) elif d is None: status="" else: status = eventInfo #status = ddat['eventInfo'] print "{!s:<7} {!s:<4}\t{!s:<12}{!s:<12}\t{!s:<12}\t{!s}".format( ti, ddat["Event-seqnum"], node, control_str, action_str, status) return # elif ddat["control"] == "_11": # status = ddat['eventInfo'] # status="value={} unit={}".format( # ddat['eventInfo'].get('value', ""), # ddat['eventInfo'].get('unit', "")) # # print "{!s:<7} {!s:<4}\t{!s:<12}\t{!s}\t{!s}\t{!s}".format( # ti, ddat["Event-seqnum"], node, control_str, action_str, status) # return elif ddat["control"] == "_17": if action_val == '1': status = "total={!s:<12} lastReadTS={!s}".format( ddat['eventInfo'].get('total', ""), ddat['eventInfo'].get('lastReadTS', "") ) else: status = ddat.get('eventInfo', "") print "{!s:<7} {!s:<4}\t{!s:<12}{!s:<12}\t{!s:<12}\t{!s}".format( ti, ddat["Event-seqnum"], node, control_str, action_str, status) return elif ddat["control"] == "_18": if 'ZBNetwork' in ddat['eventInfo']: d = ddat['eventInfo']['ZBNetwork'] status = " ".join(["{}={}".format(a,b) for a, b in d.items()] ) else: status = ddat['eventInfo'] print "{!s:<7} {!s:<4}\t{!s:<12}{!s:<12}\t{!s:<12}\t{!s}".format( ti, ddat["Event-seqnum"], node, control_str, action_str, status) return elif ddat["control"] == "_23": if 'PortalStatus' in ddat['eventInfo']: d = ddat['eventInfo']['PortalStatus'] status = " ".join(["{}={}".format(a,b) for a, b in d.items()] ) else: status = ddat['eventInfo'] print "{!s:<7} {!s:<4}\t{!s:<12}{!s:<12}\t{!s:<12}\t{!s}".format( ti, ddat["Event-seqnum"], node, control_str, action_str, status) return else: status = ddat.get('eventInfo', "") print "{!s:<7} {!s:<4}\t{!s:<12}{!s:<12}\t{!s:<12}\t{!s}".format( ti, ddat["Event-seqnum"], node, control_str, action_str, status) # return # if node is None: # node = "" # if action is None: # action = ddat.get('action', "") # print "{!s:<7} {!s:<4}\t{} : {} : {}\t{!s:<12}".format( # ti, ddat['Event-seqnum'], # node, # control_str, # action, # ddat.get('eventInfo', "-") ) print "Event Dat : \n\t", ddat, "\n\t", exml sys.stdout.flush() #print ddat # print data except Exception as e: print("Unexpected error:", sys.exc_info()[0]) print(e) print(ddat) raise # print data finally: pass
def build_message(node=None, control='', action='', evi=''): global isy, programs if debug: print "build_message(node=%s, control=%s, action=%s, evi=%s)" % (node,control,action,evi) # Dict for Node update/change actions updateAction = { "NI": "Node Initialized", "NN": "Node Renamed", "NR": "Node Removed", "ND": "Node Added", "NR": "Node Revised", "MV": "Node Moved (into a scene)", "CL": "Link Changed (in a scene)", "RG": "Removed From Group (scene)", "EN": "Enabled", "PC": "Parent Changed", "PI": "Power Info Changed", "DI": "Device ID Changed", "DP": "Device Property Changed", "GN": "Group Renamed", "GR": "Group Removed", "GD": "Group Added", "FN": "Folder Renamed", "FR": "Folder Removed", "FD": "Folder Added", "NE": "Node Error (Comm. Errors)", "CE": "Clear Node Error (Comm. Errors Cleared)", "SN": "Discovering Nodes (Linking)", "SC": "Node Discovery Complete", "WR": "Network Renamed", "WH": "Pending Device Operation", "WD": "Programming Device", "RV": "Node Revised (UPB)", } # Get human-readable event control ectrl = EVENT_CTRL.get(control, control) if node: # Get name for node address nodeName = isy._node_get_name(node) nodeName = nodeName[1] # Make printable node name with address msgnode = node if nodeName is not None: msgnode = "\"%s\" (%s)" % (nodeName, node) # Set "is" for status updates with no changes, "changed to" for others if node in nodeStatus and control in nodeStatus[node] and nodeStatus[node][control] == action: actionWord = 'is' else: if ectrl in ['Status', 'Device On', 'Device Off', 'Device Fast On', 'Device Fast Off', 'On Level', 'Ramp Rate']: actionWord = 'changed to' else: actionWord = 'is' # Calculate percentage for some events, for others return raw value if ectrl in ['On Level', 'Ramp Rate']: action = str(int(float(action) / 255.0 * 100.0)) + '%' elif ectrl in ['Status', 'Device On', 'Device Off', 'Device Fast On', 'Device Fast Off', 'On Level', 'Ramp Rate']: if isinstance(action, dict): action = str(action) elif int(action) == 255: action = 'on' elif int(action) == 0: action = 'off' else: action = str(int(float(action) / 255.0 * 100.0)) + '%' elif ectrl in ['Nodes Updated']: if action in updateAction: action = updateAction[action] else: action = 'Unknown action %s' % action # No value for on/off events if ectrl in ['Device On', 'Device Off', 'Device Fast On', 'Device Fast Off']: return("%s %s" % (msgnode, ectrl)) else: return("%s %s %s %s %s" % (msgnode, ectrl, actionWord, action, evi)) else: # No node for this event if ectrl == 'Trigger': triggerActions = { '0': "Event Status", '1': "Client Should Get Status", '2': "Key Changed", '3': "Info String", '4': "IR Learn Mode", '5': "Schedule (schedule status changed)", '6': "Variable Status (status of variable changed)", '7': "Variable Initialized (initial value of a variable", '8': 'Unknown action 8!', } if action == '0' and 'nr' in evi: prog_id = '{0:0>4}'.format(evi['id']) program = isy.get_prog(prog_id) actionMsg = "- %s " % (program['name']) # print "%s -> %s" % (prog_id, str(programs[prog_id])) if 'on' in evi and programs[prog_id]['enabled'] != True: actionMsg += 'enabled, ' programs[prog_id]['status'] = True if 'off' in evi and programs[prog_id]['enabled'] != False: actionMsg += 'disabled, ' programs[prog_id]['status'] = False if 'rr' in evi: actionMsg += 'run at startup, ' if 's' in evi: actionMsg += 'status: ' status = int(evi['s'],16) if (status & 0x01) and programs[prog_id]['running'] != 'idle': actionMsg += 'idle, ' programs[prog_id]['running'] = 'idle' elif (status & 0x02) and programs[prog_id]['running'] != 'then': actionMsg += 'running then, ' programs[prog_id]['running'] = 'then' elif (status & 0x03) and programs[prog_id]['running'] != 'else': actionMsg += 'running else, ' programs[prog_id]['running'] = 'else' if (status & 0x10) and programs[prog_id]['status'] != 'unknown': actionMsg += 'status unknown, ' programs[prog_id]['status'] = 'unknown' elif (status & 0x20) and programs[prog_id]['status'] != True: actionMsg += 'status became true, ' programs[prog_id]['status'] = 'true' elif (status & 0x30) and programs[prog_id]['status'] != False: actionMsg += 'status became false, ' programs[prog_id]['status'] = 'false' elif (status & 0xF0) and programs[prog_id]['status'] != 'not loaded': actionMsg += 'not loaded, ' programs[prog_id]['status'] = 'not loaded' actionMsg += "Last Run: %s, Last Finish %s, " % (re.sub('(\d{2])(\d{2})(\d{2})',r'20\1-\2-\3',evi['r']), re.sub('(\d{2])(\d{2})(\d{2})',r'20\1-\2-\3',evi['f'])) if debug: # Include event info if debugging return("%s : %s %s %s" % (ectrl, triggerActions[action], actionMsg, evi)) else: return("%s : %s %s" % (ectrl, triggerActions[action], actionMsg)) elif action == '3': return(str(evi)) else: if action in triggerActions: return("Trigger: %s - %s" % (triggerActions[action], str(evi))) else: return("Trigger: unknown action %s - %s" % (action, str(evi))) elif ectrl == 'Elk': if action == '2': # Area return("ELK: Area %d Type: %d Value: %d" % ( int(evi['ae']['ae-area']), int(evi['ae']['ae-type']), int(evi['ae']['ae-val']))) elif action == '3': # Zone return("ELK: Zone %d Type: %d Value: %d" % ( int(evi['ze']['ze-zone']), int(evi['ze']['ze-type']), int(evi['ze']['ze-val']))) elif action == '4': # Keypad if 'ke-area' in evi['ke']: return("ELK: Keypad %d Area: %d Type: %d Value: %d" ( int(evi['ke']['ke-keypad']), int(evi['ke']['ke-area']), int(evi['ke']['ke-type']), int(evi['ke']['ke-val']))) elif 'ke-key' in evi['ke']: return("ELK: Keypad %d Key: %d Type: %d Value: %d" % ( int(evi['ke']['ke-keypad']), int(evi['ke']['ke-key']), int(evi['ke']['ke-type']), int(evi['ke']['ke-val']))) else: return("ELK: Keypad %d Type: %d Value: %d" % ( int(evi['ke']['ke-keypad']), int(evi['ke']['ke-type']), int(evi['ke']['ke-val']))) elif action == '6': # System return("ELK: System Type: %d Value: %d" % ( int(evi['se']['se-type']), int(evi['se']['se-val']))) else: return("%s(%s) %s" % (ectrl, action, evi)) else: return("%s = %s %s" % (ectrl, action, evi))
def print_event(*arg): ddat = arg[0] # mydat = arg[1] exml = arg[2] # Event Dat : # {'control': 'DOF', 'node': '16 6C D2 7', 'eventInfo': None, 'Event-seqnum': '141', 'action': '0', 'Event-sid': 'uuid:40'} # <?xml version="1.0"?><Event seqnum="141" sid="uuid:40"><control>DOF</control><action>0</action><node>16 6C D2 7</node><eventInfo></eventInfo></Event> # ti = time.strftime('%X') try: if ddat["control"] in ["_0", "_11", "_12", "_19"]: pass elif ddat["control"] == "ERR": print "{!s:<7} {!s:<4}\t{!s:<22}\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], "ERR", ddat['node'], ddat['action']) return elif ddat["control"] in ["DOF", "DON", "BMAN", "SMAN"]: action = ddat["control"] status = ddat["node"] print "{!s:<7} {!s:<4}\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], action, status) elif ddat["control"] in ["ST", "RR", "OL"]: ectrl = EVENT_CTRL.get(ddat["control"], ddat["control"]) node = ddat["node"] evi = ddat["eventInfo"] # print ddat["Event-sid"] print("%-7s %-4s\t%-22s\t%-12s\t%s\t%s" % \ (ti, ddat["Event-seqnum"], \ ectrl, node, ddat["action"], evi)) # print '_3 ', ddat["control"], ' : ', ddat elif ddat["control"] == "_1": # 'on': None, 'f': '140630 20:55:55', 's': '31', 'r': '140630 20:55:55', 'nr': None, 'id': '1E'} if ddat['action'] == '0': print "exml = ", exml if "nsr" in ddat["eventInfo"]: action = "Event Status" status = "id={!s} {!s}".format( ddat["eventInfo"]['id'], ddat["eventInfo"]['nsr']) else: if 'on' in ddat["eventInfo"]: ena = "enabled" else: ena = "disabled" if 'rr' in ddat["eventInfo"]: rr = "rr" else: rr = "nr" action = "Event Status" status = "id={!s} {!s} {!s} run={!s} fin={!s} status={!s}".format( ddat["eventInfo"]['id'], ena, rr, ddat["eventInfo"]['r'], ddat["eventInfo"]['f'], ddat["eventInfo"]['s']) if ddat['action'] == '1': action = "Get Status" status = "" elif ddat['action'] == '2': action = "Key Change" status = ddat['node'] elif ddat['action'] == '3': action = "Info String" status = "{!s}\t{!s} ".format(ddat['node'], ddat["eventInfo"]) elif ddat['action'] == '4': action = "IR Learn Mode" status = "" elif ddat['action'] == '5': action = "Schedule" status = ddat['node'] elif ddat['action'] == '6': action = "Var Stat" status = "{!s} {!s}:{!s} {!s} {!s}".format( ddat['node'], ddat['eventInfo']['var']['var-type'], ddat['eventInfo']['var']['var-id'], ddat['eventInfo']['var']['val'], ddat['eventInfo']['var']['ts']) elif ddat['action'] == '7': action = "Var Init" status = "{!s} {!s}:{!s} {!s}".format( ddat['node'], ddat['eventInfo']['var']['var-type'], ddat['eventInfo']['var']['var-id'], ddat['eventInfo']['var']['init']) elif ddat['action'] == '8': action = "Key" status = ddat['eventInfo'] else: action = ddat['action'], status = ddat['eventInfo'] print "{!s:<7} {!s:<4}\t{!s:<22}\t{!s}\t{!s} ".format( ti, ddat['Event-seqnum'], "Trigger Event", action, status) elif ddat["control"] == "_3": if ddat['action'] == 'FD': action = 'new Folder node: ' status = str("{!s} = {!s}").format( ddat['node'], ddat['eventInfo']['folder']) elif ddat['action'] == 'FR': action = 'del Folder node' status = ddat['node'] elif ddat['action'] == 'FN': action = 'rename Folder node' status = ddat['node'] elif ddat['action'] == 'CE': action = 'Clear Node Error' status = ddat['node'] elif ddat['action'] == 'NE': action = 'Node Error' status = ddat['node'] elif ddat['action'] == 'WH': action = "Pending Device Operation" status = ddat['node'] elif ddat['action'] == 'WD': action = "Programming Device" status = ddat['node'] elif ddat['action'] == 'SN': action = "Discovering Nodes" status = "" elif ddat['action'] == 'SC': action = "Discovering Nodes Complete" status = "" else: action = ddat['action'] status = "{!s}\t{!s}".format(ddat['node'], ddat['eventInfo']) # "Node Change", print "{!s:<7} {!s:<4}\t{!s:<22}\t{!s}".format( ti, ddat['Event-seqnum'], action, status) elif ddat["control"] == "_4": status = "" action = ddat['action'] if ddat['action'] == '0': action = "Time Change" elif ddat['action'] == '1': action = "Time Conf Changed" elif ddat['action'] == '2': action = "NTP Setting Change" elif ddat['action'] == '3': action = "Notifications Settings Updated" elif ddat['action'] == '4': action = "NTP Communications Error" elif ddat['action'] == '5': action = "Batch Mode Updated" status = ddat['eventInfo']['status'] elif ddat['action'] == '6': action = "Battery Mode Programming Updated" status = ddat['eventInfo']['status'] else: action = ddat['action'] status = ddat['eventInfo'] print "{!s:<7} {!s:<4}\tSys Conf Updated\t{!s} : {!s}".format( ti, ddat['Event-seqnum'], action, status) elif ddat["control"] == "_5": action = ddat['action'] if ddat['action'] == '0': action = "Not Busy" elif ddat['action'] == '1': action = "Busy" elif ddat['action'] == '2': action = "Idle" elif ddat['action'] == '3': action = "Safe Mode" print "{!s:<7} {!s:<4}\tSys Status Updated\t{!s}".format( ti, ddat['Event-seqnum'], action) elif ddat["control"] == "_7": if ddat['action'] == '1': action = "Update" elif ddat['action'] == '2.1': action = "Device Address Info" elif ddat['action'] == '2.2': action = "Device Address Warn" elif ddat['action'] == '2.3': action = "Device Address Error" else: action = ddat['action'] print "{!s:<7} {!s:<4}\tProgress Report\t{!s} : {!s}".format( ti, ddat['Event-seqnum'], action, ddat["eventInfo"]) elif ddat["control"] == "_10": action = ddat['action'] status = ddat['eventInfo'] if ddat['action'] == '1': action = "Open ADR Error" status = "" if ddat['action'] == '2': action = "Open ADR Status Update" status = ddat['eventInfo'] if ddat['action'] == '5': action = "Flex Your Power Error" status = "" elif ddat['action'] == '6': action = "Flex Your Power Status" status = ddat['eventInfo']['active'] print "{!s:<7} {!s:<4}\tOpenADR / Flex\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], action, status) # elif ddat["control"] == "_12" : # pass # elif ddat["control"] == "_1" and ddat["action"] in ["6", "7", "3"] : # print ddat["control"], " : ", ddat # print arg else: print "Event Dat : \n\t", ddat, "\n\t", exml pass #print ddat # print data except Exception as e: print("Unexpected error:", sys.exc_info()[0]) print(e) print(ddat) raise # print data finally: pass
def print_event(*arg): ddat = arg[0] # mydat = arg[1] exml = arg[2] # Event Dat: # {'control': 'DOF', 'node': '16 6C D2 7', 'eventInfo': None, 'Event-seqnum': '141', 'action': '0', 'Event-sid': 'uuid:40'} # <?xml version="1.0"?><Event seqnum="141" sid="uuid:40"><control>DOF</control><action>0</action><node>16 6C D2 7</node><eventInfo></eventInfo></Event> # print("Event Dat: \n\t", ddat, "\n\t", exml) ti = time.strftime('%X') try: control = ddat['Event']['control'] action = ddat['Event']['action'] status = ddat['Event']['eventInfo'] node = ddat['Event']['node'] if control in ["_0", "_11", "_12", "_19"]: pass elif control == "ERR": print("{!s:<7} {!s:<4}\t{!s:<22}\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], "ERR", node, action)) return elif control in ["DOF", "DON", "BMAN", "SMAN"]: action = ddat['Event']['control'] print("{!s:<7} {!s:<4}\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], control, node)) elif control in ["ST", "RR", "OL"]: ectrl = EVENT_CTRL.get(control, control) # print ddat["Event-sid"] print("%-7s %-4s\t%-22s\t%-12s\t%s\t%s" % (ti, ddat["Event-seqnum"], ectrl, node, action, status)) # print '_3 ', ddat["control"], ': ', ddat elif control == "_1": # 'on': None, 'f': '140630 20:55:55', 's': '31', 'r': '140630 20:55:55', 'nr': None, 'id': '1E'} if action == '0': print("exml = ", exml) if "nsr" in status: action = "Event Status" status = "id={!s} {!s}".format(ddat['Event']["eventInfo"]['id'], ddat['Event']["eventInfo"]['nsr']) else: if 'on' in status: ena = "enabled" else: ena = "disabled" if 'rr' in status: rr = "rr" else: rr = "nr" action = "Event Status" status = "id={!s} {!s} {!s} run={!s} fin={!s} status={!s}".format( ddat['Event']["eventInfo"]['id'], ena, rr, ddat['Event']["eventInfo"].get('r', ''), ddat['Event']["eventInfo"].get('f', ''), ddat['Event']["eventInfo"].get('s')) if action == '1': action = "Get Status" status = "" elif action == '2': action = "Key Change" status = node elif action == '3': action = "Info String" status = "{!s}\t{!s} ".format(node, ddat['Event']["eventInfo"]) elif action == '4': action = "IR Learn Mode" status = "" elif action == '5': action = "Schedule" status = node elif action == '6': action = "Var Stat" status = "{!s} {!s}:{!s} {!s} {!s}".format( node, ddat['Event']['eventInfo']['var']['var-type'], ddat['Event']['eventInfo']['var']['var-id'], ddat['Event']['eventInfo']['var']['val'], ddat['Event']['eventInfo']['var']['ts']) elif action == '7': action = "Var Init" status = "{!s} {!s}:{!s} {!s}".format( node, ddat['Event']['eventInfo']['var']['var-type'], ddat['Event']['eventInfo']['var']['var-id'], ddat['Event']['eventInfo']['var']['init']) elif action == '8': action = "Key" print("{!s:<7} {!s:<4}\t{!s:<22}\t{!s}\t{!s} ".format( ti, ddat['Event-seqnum'], "Trigger Event", action, status)) elif control == "_3": if action == 'FD': action = 'new Folder node: ' status = str("{!s} = {!s}").format(node, ddat['Event']['eventInfo']['folder']) elif action == 'FR': action = 'del Folder node' status = node elif action == 'FN': action = 'rename Folder node' status = node elif action == 'CE': action = 'Clear Node Error' status = node elif action == 'NE': action = 'Node Error' status = node elif action == 'WH': action = "Pending Device Operation" status = node elif action == 'WD': action = "Programming Device" status = node elif action == 'SN': action = "Discovering Nodes" status = "" elif action == 'SC': action = "Discovering Nodes Complete" status = "" else: status = "{!s}\t{!s}".format(node, ddat['Event']['eventInfo']) # "Node Change", print("{!s:<7} {!s:<4}\t{!s:<22}\t{!s}".format( ti, ddat['Event-seqnum'], action, status)) elif control == "_4": status = "" if action == '0': action = "Time Change" elif action == '1': action = "Time Conf Changed" elif action == '2': action = "NTP Setting Change" elif action == '3': action = "Notifications Settings Updated" elif action == '4': action = "NTP Communications Error" elif action == '5': action = "Batch Mode Updated" status = ddat['Event']['eventInfo']['status'] elif action == '6': action = "Battery Mode Programming Updated" status = ddat['Event']['eventInfo']['status'] print("{!s:<7} {!s:<4}\tSys Conf Updated\t{!s}: {!s}".format( ti, ddat['Event-seqnum'], action, status)) elif control == "_5": if action == '0': action = "Not Busy" elif action == '1': action = "Busy" elif action == '2': action = "Idle" elif action == '3': action = "Safe Mode" print("{!s:<7} {!s:<4}\tSys Status Updated\t{!s}".format( ti, ddat['Event-seqnum'], action)) elif control == "_7": if action == '1': action = "Update" elif action == '2.1': action = "Device Address Info" elif action == '2.2': action = "Device Address Warn" elif action == '2.3': action = "Device Address Error" print("{!s:<7} {!s:<4}\tProgress Report\t{!s}: {!s}".format(ti, ddat['Event-seqnum'], action, status)) elif control == "_10": if action == '1': action = "Open ADR Error" status = "" elif action == '2': action = "Open ADR Status Update" elif action == '5': action = "Flex Your Power Error" status = "" elif action == '6': action = "Flex Your Power Status" print("{!s:<7} {!s:<4}\tOpenADR / Flex\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], action, status)) elif control == "_21": if action == '1.3': action = "Configuration" print("{!s:<7} {!s:<4}\tZ-Wave\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], action, status)) elif control == "USRNUM": print("{!s:<7} {!s:<4}\tUser Number\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], action, status)) elif control == "BATLVL": print("{!s:<7} {!s:<4}\tBattery Level\t{!s}\t{!s}%".format( ti, ddat['Event-seqnum'], node, action)) elif control == "CLISPC": print("{!s:<7} {!s:<4}\tCool Setpoint\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], node, action)) elif control == "CLISPH": print("{!s:<7} {!s:<4}\tHeat Setpoint\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], node, action)) elif control == 'CLIHCS': print("{!s:<7} {!s:<4}\tHeat/Cool State\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], node, action)) elif control == 'CLIFS': if action == '0': action = 'Auto' if action == '1': action = 'On' if action == '6': action = 'Circulation' print("{!s:<7} {!s:<4}\tFan State\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], node, action)) elif control == 'CLIFSO': print("{!s:<7} {!s:<4}\tFan State ?\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], node, action)) elif control == 'CLIFRS': if action == '0': action = 'Auto' if action == '1': action = 'On' if action == '6': action = 'Circulation' print("{!s:<7} {!s:<4}\tFan Requested State\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], node, action)) elif control == 'CLIMD': if action == '0': action = 'Off' elif action == '1': action = 'Heat' elif action == '2': action = 'Cool' elif action == '3': action = 'Auto' elif action == '11': action = 'Energy Save Heat' elif action == '12': action = 'Energy Save Cool' print("{!s:<7} {!s:<4}\tThermostat Mode\t{!s}\t{!s}".format( ti, ddat['Event-seqnum'], node, action)) # elif ddat["control"] == "_12": # pass # elif ddat["control"] == "_1" and ddat["action"] in ["6", "7", "3"]: # print ddat["control"], ": ", ddat # print arg else: print("Event Dat: \n\t", ddat, "\n\t", exml) pass #print ddat # print data except Exception as e: print("Unexpected error:", sys.exc_info()[0]) print(e) print(ddat) raise # print data finally: pass