From 7684dff0d3c4f1438a787e4f27143b29f342144c Mon Sep 17 00:00:00 2001 From: jgyates Date: Mon, 25 Sep 2023 13:18:47 -0400 Subject: [PATCH] V1.18.18 --- addon/gentemp.py | 20 +++++++++---- changelog.md | 2 ++ genmonlib/controller.py | 66 ++++++++++++++++++++++------------------- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/addon/gentemp.py b/addon/gentemp.py index fb54b483..3510570f 100644 --- a/addon/gentemp.py +++ b/addon/gentemp.py @@ -116,12 +116,20 @@ def __init__( self.Generator = ClientInterface(host=self.MonitorAddress, port=port, log=self.log) self.BoundsData = [] - if self.DeviceNominalValues != None and self.DeviceMaxValues != None: - for (NominalValue,MaxValue) in itertools.zip_longest(self.DeviceNominalValues, self.DeviceMaxValues): - self.BoundsData.append({"max": MaxValue, "nominal": NominalValue}) - return_string = json.dumps(self.BoundsData) - self.LogDebug("Bounds Data: " + str(self.BoundsData)) - self.SendCommand("generator: set_temp_bounds=" + return_string) + + if self.UseMetric: + self.Units = "C" + else: + self.Units = "F" + if self.DeviceNominalValues != None and self.DeviceMaxValues != None and self.DeviceLabels != None: + if len(self.DeviceNominalValues) == len(self.DeviceMaxValues) == len(self.DeviceLabels): + for (NominalValue,MaxValue, DeviceName) in itertools.zip_longest(self.DeviceNominalValues, self.DeviceMaxValues, self.DeviceLabels): + self.BoundsData.append({"max": MaxValue, "nominal": NominalValue, "name": DeviceName, "units": self.Units}) + return_string = json.dumps(self.BoundsData) + self.LogDebug("Bounds Data: " + str(self.BoundsData)) + self.SendCommand("generator: set_temp_bounds=" + return_string) + else: + self.LogError("Error in configuration: sensor name, nominal and max values do not have he same number of entries") self.DeviceList = self.EnumDevices() diff --git a/changelog.md b/changelog.md index becf8dbf..540af303 100644 --- a/changelog.md +++ b/changelog.md @@ -23,6 +23,8 @@ All notable changes to this project will be documented in this file. - Update to gensnmp.py to allow user defined SNMP entries - Fixed issue with page reload after saving service journal - Change for external CT gauge display when using gencthat.py add on +- Fixed bug that may prohibit some add on programs from working at the same time +- Added more bounds checking to gentemp.py ## V1.18.17 -2023-04-06 - Added feature request to allow external temperature sensors to be displayed as gauges diff --git a/genmonlib/controller.py b/genmonlib/controller.py index b338072f..3ed3116f 100644 --- a/genmonlib/controller.py +++ b/genmonlib/controller.py @@ -121,15 +121,13 @@ def __init__( self.UseExternalCTData = False self.ExternalCTData = None self.UseExternalTempData = False - self.ExternalDataLock = threading.RLock() self.ExternalTempData = None self.ExternalTempDataTime = None self.ExternalTempBounds = None + self.ExternalDataLock = threading.RLock() - self.ProgramStartTime = datetime.datetime.now() # used for com metrics - self.OutageStartTime = ( - self.ProgramStartTime - ) # if these two are the same, no outage has occured + self.ProgramStartTime = datetime.datetime.now() # used for com metrics + self.OutageStartTime = (self.ProgramStartTime) # if these two are the same, no outage has occured self.OutageNoticeDelayTime = None self.LastOutageDuration = self.OutageStartTime - self.OutageStartTime self.OutageNoticeDelay = 0 @@ -2022,19 +2020,17 @@ def SetupCommonTiles(self): try: self.LogDebug("Setting up gauges for external temp sensors") index = 0 - TempList = self.ExternalTempData["External Temperature Sensors"] - for (TempDict,TempBounds) in itertools.zip_longest(TempList, self.ExternalTempBounds): - temp_name = list(TempDict.keys())[0] - temp_max = TempBounds['max'] - temp_nominal = TempBounds['nominal'] - temp_value = TempDict[temp_name] - temp_list = temp_value.strip().split(" ") - temp_units = temp_list[1] - if temp_name != None and temp_max != None and temp_nominal != None: - Tile = MyTile(self.log,title=temp_name, units=temp_units,type="temperature", subtype = "external", - nominal=temp_nominal, maximum=temp_max, callback=self.GetExternalTemp, callbackparameters=(index,),) - self.TileList.append(Tile) - index += 1 + if "External Temperature Sensors" in self.ExternalTempData.keys(): + for TempBounds in self.ExternalTempBounds: + temp_max = TempBounds['max'] + temp_nominal = TempBounds['nominal'] + temp_name = TempBounds['name'].strip() + temp_units = TempBounds['units'] + if temp_name != None and temp_max != None and temp_nominal != None: + Tile = MyTile(self.log,title=temp_name, units=temp_units,type="temperature", subtype = "external", + nominal=temp_nominal, maximum=temp_max, callback=self.GetExternalTemp, callbackparameters=(index,),) + self.TileList.append(Tile) + index += 1 except Exception as e1: self.LogErrorLine("Error in SetupCommonTiles: TempData: " + str(e1)) @@ -2288,6 +2284,7 @@ def DisplayMaintenanceCommon(self, Maintenance, JSONNum=False): def DisplayStatusCommon(self, Status, JSONNum=False): try: + with self.ExternalDataLock: try: if self.ExternalTempData != None: @@ -2299,8 +2296,9 @@ def DisplayStatusCommon(self, Status, JSONNum=False): ExternalTempList = self.ExternalTempData["External Temperature Sensors"] if len(ExternalTempList): Status["Status"].append({"External Temperature Sensors" : TempList}) - for TempDict in ExternalTempList: + for ExTempDict in ExternalTempList: try: + TempDict = ExTempDict.copy() # make a copy since we use popitmes below if len(TempDict): TempKey, TempData = TempDict.popitem() TempDataList = TempData.strip().split( " ") @@ -2309,7 +2307,7 @@ def DisplayStatusCommon(self, Status, JSONNum=False): self.LogErrorLine("Error in DisplayStatus (3): " + str(e1)) except Exception as e1: self.LogErrorLine("Error in DisplayStatusCommon(2): " + str(e1)) - + ReturnCurrent = self.CheckExternalCTData(request="current", ReturnFloat=True, gauge=True) ReturnCurrent1 = self.CheckExternalCTData(request="ct1", ReturnFloat=True, gauge=True) ReturnCurrent2 = self.CheckExternalCTData(request="ct2", ReturnFloat=True, gauge=True) @@ -2815,18 +2813,24 @@ def GetExternalTemp(self, sensor_index): if not self.UseExternalTempData or self.ExternalTempData == None or self.ExternalTempBounds == None: return 0.0 index = 0 - TempList = self.ExternalTempData["External Temperature Sensors"] - for TempDict in TempList: - if index == sensor_index: - temp_name = list(TempDict.keys())[0] - temp_value = TempDict[temp_name] - temp_list = temp_value.strip().split(" ") - temp_value = temp_list[0] - return float(temp_value) - - index += 1 + with self.ExternalDataLock: + TempList = self.ExternalTempData["External Temperature Sensors"] + if len(TempList) > 0: + for TempDict in TempList: + if index == sensor_index: + temp_name = list(TempDict.keys())[0] + temp_value = TempDict[temp_name] + temp_list = temp_value.strip().split(" ") + temp_value = temp_list[0] + return float(temp_value) + index += 1 + else: + self.LogDebug("Error in GetExternalTemp: " + str(self.ExternalTempData)) + + self.LogDebug("Temp data not found in GetExternalTemp: " + str(sensor_index)) + return 0.0 except Exception as e1: - self.LogErrorLine("Error in GetExternalTemp: " + str(e1)) + self.LogErrorLine("Error in GetExternalTemp: " + str(e1) + ": " + str(sensor_index) + ": " + str(self.ExternalTempData)) return 0.0 # ---------- GeneratorController::SetExternalTemperatureBounds-------------