Пример #1
0
 def controller_init(self, enablecontroller=None):
     if enablecontroller != None:
         self.enabled = enablecontroller
     self.connectinprogress = 0
     self.inch, state = commands.parseruleline(
         self.inchannel)  # replace global variables
     self.outch, state = commands.parseruleline(self.outchannel)
     state = self.outch.find('#')
     if state > -1:
         self.outch = self.outch[:(state + 1)]
     try:
         ls = self.laststatus
     except:
         self.laststatus = -1
     self.mqttclient = GMQTTClient()
     self.mqttclient.subscribechannel = self.outch
     self.mqttclient.controllercb = self.on_message
     self.mqttclient.connectcb = self.on_connect
     self.mqttclient.disconnectcb = self.on_disconnect
     if self.controllerpassword == "*****":
         self.controllerpassword = ""
     self.initialized = True
     if self.enabled:
         if self.isconnected() == False:
             misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,
                         "MQTT: Try to connect")
             self.connect()
     else:
         self.laststatus = -1
         self.disconnect()
     return True
Пример #2
0
 def controller_init(self,enablecontroller=None):
  if enablecontroller != None:
   self.enabled = enablecontroller
  self.connectinprogress = 0
  self.inch, state = commands.parseruleline(self.inchannel)    # replace global variables
  self.outch, state = commands.parseruleline(self.outchannel)
  state = self.outch.find('#')
  if state >-1:
   self.outch = self.outch[:(state+1)]
  else:
   state = self.outch.find('%tskname%')
   if state < 0:
    state = self.outch.find('%tskid%')
   if state >-1:
    self.outch = self.outch[:(state)]+"/#"
   else:
    state = self.outch.find('%valname%')
    if state >-1:
     self.outch = self.outch[:(state)]+"/#"
  self.outch = self.outch.replace('//','/').strip()
  if self.outch=="" or self.outch=="/" or self.outch=="/#" or self.outch=="%/#":
   self.outch = "#"
  try:
   ls = self.laststatus
  except:
   self.laststatus = -1

  try:
   self.lwt_t, state = commands.parseruleline(self.lwt_topic)
  except:
   self.lwt_topic = ""
  try:
   if self.useJSON: #check if var exists
    pass
  except:
   self.useJSON = False
  self.mqttclient = GMQTTClient()
  self.mqttclient.subscribechannel = self.outch
  self.mqttclient.controllercb = self.on_message
  self.mqttclient.connectcb = self.on_connect
  self.mqttclient.disconnectcb = self.on_disconnect
  if self.controllerpassword=="*****":
   self.controllerpassword=""
  self.initialized = True
  if self.enabled:
   if self.isconnected()==False:
    misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"MQTT: Try to connect")
    self.connect()
  else:
   self.laststatus = -1
   self.disconnect()
  return True
Пример #3
0
 def oledparse(self, ostr):
     cl, st = commands.parseruleline(ostr)
     if st == "CMD":
         resstr = str(cl)
     else:
         resstr = str(ostr)
     if "{" in resstr or "&" in resstr:
         resstr = resstr.replace("{D}", "˚").replace("&deg;", "˚")
         resstr = resstr.replace("{<<}", "«").replace("&laquo;", "«")
         resstr = resstr.replace("{>>} ", "»").replace("&raquo;", "»")
         resstr = resstr.replace("{u} ", "µ").replace("&micro; ", "µ")
         resstr = resstr.replace("{E}", "€").replace("&euro;", "€")
         resstr = resstr.replace("{Y}", "¥").replace("&yen;", "¥")
         resstr = resstr.replace("{P}", "£").replace("&pound;", "£")
         resstr = resstr.replace("{c}", "¢").replace("&cent;", "¢")
         resstr = resstr.replace("{^1}", "¹").replace("&sup1;", "¹")
         resstr = resstr.replace("{^2}", "²").replace("&sup2;", "²")
         resstr = resstr.replace("{^3}", "³").replace("&sup3;", "³")
         resstr = resstr.replace("{1_4}", "¼").replace("&frac14;", "¼")
         resstr = resstr.replace("{1_2}", "½").replace("&frac24;", "½")
         resstr = resstr.replace("{3_4}", "¾").replace("&frac34;", "¾")
         resstr = resstr.replace("{+-}", "±").replace("&plusmn;", "±")
         resstr = resstr.replace("{x}", "×").replace("&times;", "×")
         resstr = resstr.replace("{..}", "÷").replace("&divide;", "÷")
     return resstr
Пример #4
0
 def msgparse(self, ostr):
     cl, st = commands.parseruleline(ostr)
     if st == "CMD":
         resstr = str(cl)
     else:
         resstr = str(ostr)
     return resstr
Пример #5
0
    def runcmd(self,
               number):  # run command stored at taskdevicepluginconfig[number]
        res = False
        if self.enabled:
            number = int(number)
            if self.pininversed:  # inverse handled inside parent set_value, that is called after runcmd, so take care, before run
                val2 = (1 - number)
            else:
                val2 = number
            if val2 >= 0 and val2 <= 1:
                if self.taskdevicepluginconfig[val2] != "" and str(
                        self.taskdevicepluginconfig[val2]) != "0":
                    cmdline = self.taskdevicepluginconfig[val2]
                    if self.taskdevicepluginconfig[3]:
                        cl, st = commands.parseruleline(cmdline)
                        if st == "CMD":
                            cmdline = str(cl)
                        else:
                            cmdline = str(cmdline)
#      print("XXX ",cmdline," XXX")#debug
                    output = os.popen(cmdline)
                    if self.taskdevicepluginconfig[2]:
                        return True
                    res = ""
                    for l in output:
                        res += str(l)
                else:
                    return None
        return res
Пример #6
0
def handle_sysvars(httpResponse):
    ws.navMenuIndex = 7
    ws.TXBuffer = ""
    httpResponse.WriteResponseOk(headers=({
        'Cache-Control': 'no-cache'
    }),
                                 contentType='text/html',
                                 contentCharset='UTF-8',
                                 content="")
    ws.sendHeadandTail("TmplStd", ws._HEAD)
    ws.TXBuffer += "<table class='normal'><TR><TH align='left'>System Variables<TH align='left'>Normal"
    for sv in commands.SysVars:
        ws.TXBuffer += "<TR><TD>%" + sv + "%</TD><TD>"
        ws.TXBuffer += str(commands.getglobalvar(sv)) + "</TD></TR>"
        httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
        ws.TXBuffer = ""
    conversions = [
        "%c_m2day%(%uptime%)", "%c_m2dh%(%uptime%)", "%c_m2dhm%(%uptime%)"
    ]
    for sv in conversions:
        try:
            ws.TXBuffer += "<TR><TD>" + sv + "</TD><TD>"
            ws.TXBuffer += str(commands.parseruleline(sv)[0]) + "</TD></TR>"
        except:
            pass
    ws.TXBuffer += "</table></form>"
    ws.sendHeadandTail("TmplStd", ws._TAIL)
    httpResponse._write(ws.TXBuffer, strEncoding='UTF-8')
    ws.TXBuffer = ""
Пример #7
0
 def controller_init(self, enablecontroller=None):
     if enablecontroller != None:
         self.enabled = enablecontroller
     self.templatestr, state = commands.parseruleline(
         self.inchannel)  # replace global variables
     self.templatestr = self.templatestr.replace("==", "=")
     self.initialized = True
     return True
Пример #8
0
 def controller_init(self, enablecontroller=None):
     if enablecontroller != None:
         self.enabled = enablecontroller
     self.connectinprogress = 0
     self._inch, state = commands.parseruleline(
         self.inchannel)  # replace global variables
     self._outch, state = commands.parseruleline(self.outchannel)
     state = self._outch.find('#')
     if state > -1:
         self._outch = self._outch[:(state + 1)]
     else:
         state = self._outch.find('%tskname%')
         if state < 0:
             state = self._outch.find('%tskid%')
         if state > -1:
             self._outch = self._outch[:(state)] + "/#"
         else:
             state = self._outch.find('%valname%')
             if state > -1:
                 self._outch = self._outch[:(state)] + "/#"
     self._outch = self._outch.replace('//', '/').strip()
     if self._outch == "" or self._outch == "/" or self._outch == "/#" or self._outch == "%/#":
         self._outch = "#"
     try:
         ls = self.laststatus
     except:
         self.laststatus = -1
     if self.controllerpassword == "*****":
         self.controllerpassword = ""
     self.initialized = True
     if self.enabled:
         try:
             if self._connected:
                 pass
         except:
             self._connected = False
         try:
             if self._connected == False:
                 misc.addLog(pglobals.LOG_LEVEL_DEBUG,
                             "MQTT: Try to connect")
                 self.connect()
         except:
             self._connected = False
     else:
         self.disconnect()
     return True