+
+def substituteMessageVariables(msg, door_tuple):
+ loop_tokens=3
+ while loop_tokens > 0 and msg.find("${") > -1:
+ #logging.debug("subsMsgVars: loopTok=%d door_tuple=%s msg=%s" % (loop_tokens, str(door_tuple), msg))
+ if not door_tuple is None and type(door_tuple[0]) == types.StringType:
+ msg = msg.replace('${door_action_msg}', uwscfg.msg_door_action_msg)
+ msg = msg.replace('${door_status}', door_tuple[0]).replace('${by_whom}', "by "+str(door_tuple[1]))
+ else:
+ msg = msg.replace('${door_action_msg}','').replace('${door_status}','').replace('${by_whom}','')
+ loop_tokens-=1
+ return msg
+
+def formatAndDistributePresence(presence, door_tuple=(None,None)):
+ picurl=""
+ if uwscfg.cam_provide_pic == "True":
+ picurl="\n"+uwscfg.cam_picture_url
+ if presence == "yes":
+ distributeXmppMsg(substituteMessageVariables(uwscfg.msg_present, door_tuple)+picurl)
+ else:
+ distributeXmppMsg(substituteMessageVariables(uwscfg.msg_notpresent, door_tuple)+picurl)
+
+def formatAndDistributeWarning(msg, door_tuple=(None,None)):
+ distributeXmppMsg("Warning: "+msg , high_priority=True)
+
+current_status = (None, None, None, None)
+def filterAndFormatMessage(new_status):
+ global current_status
+ if new_status[0] == "error":
+ distributeXmppMsg(uwscfg.msg_status_error_msg, high_priority=True)
+ elif current_status[0] != new_status[0]:
+ distributeXmppMsg("Status: (%s,%s,%s,%s)" % new_status ,debug=True)
+ current_status=new_status
+