예제 #1
0
파일: __init__.py 프로젝트: auduny/chains
 def open(self):
     self.polldata = {'vol': -1, 'mute': -1}
     if self.poll():
         try: interval = float(self.config['main']['pollinterval'])
         except: interval = 1
         log.info('Starting poller with interval: %s' % interval)
         while True:
             time.sleep(interval)
             self.poll()
     else:
         log.info('Not starting poller')
예제 #2
0
 def open(self):
     self.polldata = {'vol': -1, 'mute': -1}
     if self.poll():
         try:
             interval = float(self.config['main']['pollinterval'])
         except:
             interval = 1
         log.info('Starting poller with interval: %s' % interval)
         while True:
             time.sleep(interval)
             self.poll()
     else:
         log.info('Not starting poller')
예제 #3
0
 def onSms(self, sms):
     event = {
         'key':    'smsReceived',
         #'service': self.config['id'],
         'value':  sms['message']
     }
     del sms['message']
     event['extra'] = sms
     #self.devDaemon.onEvent(event)
     self.onEvent(event)
     if self.config['main'].has_key('delsmsonrecv') and self.config['main']['delsmsonrecv'] not in ['','0']:
         log.info('Delete received sms on event sent: %s' % sms['id'])
         self.deleteSms(sms['id'])
예제 #4
0
 def onSms(self, sms):
     event = {
         'key': 'smsReceived',
         #'service': self.config['id'],
         'value': sms['message']
     }
     del sms['message']
     event['extra'] = sms
     #self.devDaemon.onEvent(event)
     self.onEvent(event)
     if self.config['main'].has_key('delsmsonrecv') and self.config['main'][
             'delsmsonrecv'] not in ['', '0']:
         log.info('Delete received sms on event sent: %s' % sms['id'])
         self.deleteSms(sms['id'])
예제 #5
0
 def getSms(self, id):
     res0 = self.cmd('at+cmgr=%s' % id, bufsize=10, raw=True)
     res = res0[0]
     txt = res0[1]
     # fixme
     res = res.replace(',,',',"",')
     tmp = res.split('","')
     tmp[0] = tmp[0].replace('+CMGR: "', '')
     tmp2 = []
     for t in tmp:
         tmp2.append(t.strip(' ').strip('"'))
     # what is tmp[2] ? always empty? ##  ['+CMGR: "REC UNREAD","+4792489963",,"09/10/07,01:15:56+08"', 'D']
     res = {'status': tmp2[0], 'callerid': tmp2[1], 'time': tmp2[3], 'message': txt, 'id': id}
     log.info("getSms: %s: %s" % (id, res))
     return res
예제 #6
0
 def cmd_sendSms(self, number, message):
     log.info('sendSms: %s : %s' % (number, message))
     id = None
     res = self.cmd('at+cmgs="%s"' % number, raw=True)
     #log.info('sendSms result: %s' % res)
     if (type(res) in (type([]),type((1,))) and res[0] == '>') or res == '>':
         res = self.cmd('%s\x1A' % message, bufsize=5, raw=True)
         log.info('sendSms result2: %s' % res)
         if res and len(res) > 1:
             # id = res[1].split(":")[1].strip()
             id = res.split(":")[1].strip()
         else:
             log.warn("Unknown result2: %s" % res)
     else:
         log.warn("Unknown result1: %s" % res)
     return id
예제 #7
0
 def cmd_sendSms(self, number, message):
     log.info('sendSms: %s : %s' % (number, message))
     id = None
     res = self.cmd('at+cmgs="%s"' % number, raw=True)
     #log.info('sendSms result: %s' % res)
     if (type(res) in (type([]), type(
         (1, ))) and res[0] == '>') or res == '>':
         res = self.cmd('%s\x1A' % message, bufsize=5, raw=True)
         log.info('sendSms result2: %s' % res)
         if res and len(res) > 1:
             # id = res[1].split(":")[1].strip()
             id = res.split(":")[1].strip()
         else:
             log.warn("Unknown result2: %s" % res)
     else:
         log.warn("Unknown result1: %s" % res)
     return id
예제 #8
0
 def trySendPin(self, force=None, pin=None):
     if not force:
         try:
             if not self.config['main']['sendpin']: return
         except KeyError:
             return
         res = self.cmd("at+cpin?")
         if res == '+CPIN: READY':
             return
     if not pin:
         try:
             pin = self.config['main']['pincode']
             if not pin: return
         except KeyError:
             return
     res = self.cmd("at+cpin=%s" % pin)
     log.info("Sent pin")
예제 #9
0
 def trySendPin(self, force=None, pin=None):
     if not force:
         try:
             if not self.config['main']['sendpin']: return
         except KeyError:
             return
         res = self.cmd("at+cpin?")
         if res == '+CPIN: READY':
             return
     if not pin:
         try:
             pin = self.config['main']['pincode']
             if not pin: return
         except KeyError:
             return
     res = self.cmd("at+cpin=%s" % pin)
     log.info("Sent pin")
예제 #10
0
 def getSms(self, id):
     res0 = self.cmd('at+cmgr=%s' % id, bufsize=10, raw=True)
     res = res0[0]
     txt = res0[1]
     # fixme
     res = res.replace(',,', ',"",')
     tmp = res.split('","')
     tmp[0] = tmp[0].replace('+CMGR: "', '')
     tmp2 = []
     for t in tmp:
         tmp2.append(t.strip(' ').strip('"'))
     # what is tmp[2] ? always empty? ##  ['+CMGR: "REC UNREAD","+4792489963",,"09/10/07,01:15:56+08"', 'D']
     res = {
         'status': tmp2[0],
         'callerid': tmp2[1],
         'time': tmp2[3],
         'message': txt,
         'id': id
     }
     log.info("getSms: %s: %s" % (id, res))
     return res