Skip to content

Commit

Permalink
V1.18.18
Browse files Browse the repository at this point in the history
  • Loading branch information
jgyates committed Sep 25, 2023
1 parent c6e94e7 commit 7684dff
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
20 changes: 14 additions & 6 deletions addon/gentemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 35 additions & 31 deletions genmonlib/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand All @@ -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( " ")
Expand All @@ -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)
Expand Down Expand Up @@ -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-------------
Expand Down

0 comments on commit 7684dff

Please sign in to comment.