From 0ffa0932e10699167628e274276f625e5e090821 Mon Sep 17 00:00:00 2001 From: enesbcs Date: Thu, 19 Mar 2020 21:26:06 +0100 Subject: [PATCH] Fixing FPM dependency list, Dummy device value counter, DomoMQTT reconnection --- _C002_DomoMQTT.py | 120 +++++++++++++++++++++++----------------------- _P033_Dummy.py | 14 ++++++ _P205_EPD.py | 6 +-- plugindeps.py | 2 +- rpieGlobals.py | 2 +- 5 files changed, 79 insertions(+), 65 deletions(-) diff --git a/_C002_DomoMQTT.py b/_C002_DomoMQTT.py index 1b351e3..5cef46c 100644 --- a/_C002_DomoMQTT.py +++ b/_C002_DomoMQTT.py @@ -219,72 +219,73 @@ def webform_save(self,params): # process settings post reply return True def on_message(self, msg): - msg2 = msg.payload.decode('utf-8') - list = [] - if ('{' in msg2): - try: - list = json.loads(msg2) - except Exception as e: - misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"JSON decode error:"+str(e)+str(msg2)) - list = [] - if (list) and (len(list)>0): - try: - if list['Type'] == "Scene": # not interested in scenes.. - return False - except: - pass - devidx = -1 - nvalue = "0" - svalue = "" - decodeerr = False - tval = [-1,-1,-1,-1] - try: - devidx = str(list['idx']).strip() - except: + if self.enabled: + msg2 = msg.payload.decode('utf-8') + list = [] + if ('{' in msg2): + try: + list = json.loads(msg2) + except Exception as e: + misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"JSON decode error:"+str(e)+str(msg2)) + list = [] + if (list) and (len(list)>0): + try: + if list['Type'] == "Scene": # not interested in scenes.. + return False + except: + pass devidx = -1 - decodeerr = True - try: - nvalue = str(list['nvalue']).strip() - except: nvalue = "0" - decodeerr = True - try: - svalue = str(list['svalue']).strip() - except: svalue = "" - if (';' in svalue): - tval = svalue.split(';') - tval2 = [] - for x in range(1,4): - sval = "" + decodeerr = False + tval = [-1,-1,-1,-1] + try: + devidx = str(list['idx']).strip() + except: + devidx = -1 + decodeerr = True + try: + nvalue = str(list['nvalue']).strip() + except: + nvalue = "0" + decodeerr = True try: - sval = str(list['svalue'+str(x)]).strip() + svalue = str(list['svalue']).strip() except: + svalue = "" + if (';' in svalue): + tval = svalue.split(';') + tval2 = [] + for x in range(1,4): sval = "" - if sval!="": - tval2.append(sval) - if len(tval2)==1 and svalue=="": - svalue=tval2[0] - else: - for y in range(len(tval2)): - matches = re.findall('[0-9]', tval2[y]) - if len(matches) > 0: - tval[y] = tval2[y] - forcesval1 = False - try: - if ("Selector" in list['switchType']) or ("Dimmer" in list['switchType']): - forcesval1 = True - except: + try: + sval = str(list['svalue'+str(x)]).strip() + except: + sval = "" + if sval!="": + tval2.append(sval) + if len(tval2)==1 and svalue=="": + svalue=tval2[0] + else: + for y in range(len(tval2)): + matches = re.findall('[0-9]', tval2[y]) + if len(matches) > 0: + tval[y] = tval2[y] forcesval1 = False - if (tval[0] == -1) or (tval[0] == ""): - if (float(nvalue)==0 and svalue.lower()!="off" and svalue!="") or (forcesval1): - tval[0] = str(svalue) + try: + if ("Selector" in list['switchType']) or ("Dimmer" in list['switchType']): + forcesval1 = True + except: + forcesval1 = False + if (tval[0] == -1) or (tval[0] == ""): + if (float(nvalue)==0 and svalue.lower()!="off" and svalue!="") or (forcesval1): + tval[0] = str(svalue) + else: + tval[0] = str(nvalue) + if decodeerr: + misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"JSON decode error: "+msg2) else: - tval[0] = str(nvalue) - if decodeerr: - misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"JSON decode error: "+msg2) - else: - self.onmsgcallbackfunc(self.controllerindex,devidx,tval) + self.onmsgcallbackfunc(self.controllerindex,devidx,tval) def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1): if self.enabled: @@ -330,7 +331,8 @@ def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,chang misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"MQTT idx error, sending failed.") else: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"MQTT not connected, sending failed.") - if ((time.time()-self.lastreconnect)>30) and (self.connectinprogress==0): + if ((time.time()-self.lastreconnect)>30): +# if ((time.time()-self.lastreconnect)>30) and (self.connectinprogress==0): self.connect() def on_connect(self): diff --git a/_P033_Dummy.py b/_P033_Dummy.py index 0df7c7d..d818e7c 100644 --- a/_P033_Dummy.py +++ b/_P033_Dummy.py @@ -40,10 +40,23 @@ def plugin_receivedata(self,data): self.set_value(x+1,data[x],False) # print("Data received:",data) + def getvaluecount(self): + if self.vtype in [rpieGlobals.SENSOR_TYPE_SINGLE,rpieGlobals.SENSOR_TYPE_SWITCH,rpieGlobals.SENSOR_TYPE_DIMMER,rpieGlobals.SENSOR_TYPE_LONG,rpieGlobals.SENSOR_TYPE_WIND]: + return 1 + elif self.vtype in [rpieGlobals.SENSOR_TYPE_TEMP_HUM,rpieGlobals.SENSOR_TYPE_TEMP_BARO,rpieGlobals.SENSOR_TYPE_DUAL]: + return 2 + elif self.vtype in [rpieGlobals.SENSOR_TYPE_TEMP_HUM_BARO,rpieGlobals.SENSOR_TYPE_TRIPLE]: + return 3 + elif self.vtype == rpieGlobals.SENSOR_TYPE_QUAD: + return 4 + else: + return 0 + def plugin_init(self,enableplugin=None): plugin.PluginProto.plugin_init(self,enableplugin) if self.taskdevicepluginconfig[0]>0: self.vtype = self.taskdevicepluginconfig[0] + self.valuecount = self.getvaluecount() def webform_load(self): # create html page for settings choice = self.taskdevicepluginconfig[0] @@ -57,6 +70,7 @@ def webform_save(self,params): # process settings post reply if par1: self.taskdevicepluginconfig[0] = int(par1) self.vtype = self.taskdevicepluginconfig[0] + self.valuecount = self.getvaluecount() return True def plugin_read(self): # deal with data processing at specified time interval diff --git a/_P205_EPD.py b/_P205_EPD.py index 0ad783a..5c918e1 100644 --- a/_P205_EPD.py +++ b/_P205_EPD.py @@ -199,9 +199,9 @@ def webform_load(self): # create html page for settings options = ['1.54" (200x200)','1.54"B (200x200)','1.54"C (150x150)','2.13" (250x122)','2.13"B (212x104)','2.7" (264x176)','2.7"B (264x176)','2.9" (296x128)','2.9"B (296x128)','4.2" (400x300)','4.2"B (400x300)','7.5" (800x480)','7.5"B (800x480)'] optionvalues = ["154","154b","154c","213","213b","270","270b","290","290b","420","420b","750","750b"] webserver.addHtml("Display type:") - webserver.addSelector_Head("p205_type",True) + webserver.addSelector_Head("p205_type",False) for d in range(len(options)): - webserver.addSelector_Item(options[d],optionvalues[d],(choice1==optionvalues[d]),False) + webserver.addSelector_Item(options[d],optionvalues[d],(str(choice1)==str(optionvalues[d])),False) webserver.addSelector_Foot() webserver.addFormNote("Enable SPI-0 first!") webserver.addFormNote("Hardware connection (OLED => Raspberry Pi)
VCC->3.3V, GND->GND, SDI->MOSI, SCLK->SCLK, CS-> GPIO8/CE0, D/C->GPIO25, RES->GPIO17, BUSY->GPIO2") @@ -245,8 +245,6 @@ def plugin_exit(self): def webform_save(self,params): # process settings post reply par = webserver.arg("p205_type",params) - if par == "": - par = 0 self.taskdevicepluginconfig[0] = str(par) par = webserver.arg("p205_rotate",params) diff --git a/plugindeps.py b/plugindeps.py index 87ee748..e806349 100644 --- a/plugindeps.py +++ b/plugindeps.py @@ -417,7 +417,7 @@ "modules":["i2c","rtimu"]}, {"pluginid": "208", #PFM "supported_os_level": [1,2,10], - "modules":["pyserial","pfm"]}, + "modules":["pyserial","pfm","pil"]}, {"pluginid": "209", # AMG "supported_os_level": [10], "modules":["i2c","amg","pil"]}, diff --git a/rpieGlobals.py b/rpieGlobals.py index 19c414d..85655cd 100644 --- a/rpieGlobals.py +++ b/rpieGlobals.py @@ -6,7 +6,7 @@ # Copyright (C) 2018-2020 by Alexander Nagy - https://bitekmindenhol.blog.hu/ # PROGNAME = "RPIEasy" -BUILD = 20076 +BUILD = 20079 PROGVER = str(BUILD)[:1]+"."+str(BUILD)[1:2]+"."+str(BUILD)[2:] gpMenu = []